From 5c88ef9a66b47efc3fe5b52de9b984541c239534 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 28 Mar 2023 18:28:34 +0300 Subject: [PATCH 1/7] Issue #171: update QEverCloud to 6.2.0 and update API calls to it across the codebase --- .gitignore | 6 +- development/build-dependencies-ubuntu-2004.sh | 2 +- nixnote2.pro | 89 +- src/communication/communicationerror.cpp | 2 +- src/communication/communicationmanager.cpp | 157 +- src/communication/communicationmanager.h | 8 +- src/nixnote.cpp | 9 - src/qevercloud/CMakeLists.txt | 83 +- src/qevercloud/QEverCloud/CMakeLists.txt | 283 +- .../modules/QEverCloudCompilerSettings.cmake | 35 +- .../cmake/modules/QEverCloudConfig.cmake.in | 46 +- .../QEverCloudFindQt4Dependencies.cmake | 9 - ...erCloudFindQt4DependenciesWithWebKit.cmake | 9 - ...CloudFindQt5DependenciesTranslations.cmake | 1 + ...udFindQt5DependenciesWebEngineNoCore.cmake | 2 - .../cmake/modules/QEverCloudSetupQt.cmake | 127 +- .../QEverCloudUpdateTranslations.cmake | 53 + .../QEverCloud/headers/AsyncResult.h | 86 +- .../QEverCloud/headers/DurableService.h | 95 + .../QEverCloud/headers/EventLoopFinisher.h | 17 +- .../QEverCloud/headers/EverCloudException.h | 148 +- .../QEverCloud/headers/Exceptions.h | 276 + .../QEverCloud/headers/{export.h => Export.h} | 8 +- src/qevercloud/QEverCloud/headers/Globals.h | 86 + src/qevercloud/QEverCloud/headers/Helpers.h | 149 + .../headers/InkNoteImageDownloader.h | 79 +- src/qevercloud/QEverCloud/headers/Log.h | 115 + .../QEverCloud/headers/{oauth.h => OAuth.h} | 144 +- src/qevercloud/QEverCloud/headers/Optional.h | 120 +- src/qevercloud/QEverCloud/headers/Printable.h | 37 + .../QEverCloud/headers/QEverCloud.h | 28 +- .../QEverCloud/headers/QEverCloudOAuth.h | 8 +- .../QEverCloud/headers/RequestContext.h | 95 + .../headers/{thumbnail.h => Thumbnail.h} | 89 +- .../QEverCloud/headers/VersionInfo.h | 27 - .../QEverCloud/headers/VersionInfo.h.in | 100 +- .../QEverCloud/headers/exceptions.h | 176 - .../generated/{constants.h => Constants.h} | 231 +- .../headers/generated/EDAMErrorCode.h | 1088 +- .../QEverCloud/headers/generated/Servers.h | 1088 + .../generated/{services.h => Services.h} | 900 +- .../headers/generated/{types.h => Types.h} | 3408 +- src/qevercloud/QEverCloud/headers/globals.h | 45 - .../QEverCloud/headers/qt4helpers.h | 90 - src/qevercloud/QEverCloud/src/AsyncResult.cpp | 174 +- .../QEverCloud/src/AsyncResult_p.cpp | 151 + src/qevercloud/QEverCloud/src/AsyncResult_p.h | 64 + .../QEverCloud/src/DurableService.cpp | 345 + .../QEverCloud/src/EventLoopFinisher.cpp | 9 +- .../QEverCloud/src/EverCloudException.cpp | 16 +- src/qevercloud/QEverCloud/src/Exceptions.cpp | 588 + src/qevercloud/QEverCloud/src/Globals.cpp | 123 + src/qevercloud/QEverCloud/src/Http.cpp | 297 + src/qevercloud/QEverCloud/src/Http.h | 168 + .../QEverCloud/src/HttpRequestData.h | 36 + .../QEverCloud/src/HttpRequestParser.cpp | 154 + .../QEverCloud/src/HttpRequestParser.h | 55 + src/qevercloud/QEverCloud/src/HttpUtils.cpp | 76 + src/qevercloud/QEverCloud/src/HttpUtils.h | 31 + .../QEverCloud/src/{impl.h => Impl.h} | 23 +- .../QEverCloud/src/InkNoteImageDownloader.cpp | 98 +- src/qevercloud/QEverCloud/src/Log.cpp | 231 + .../QEverCloud/src/NetworkCookieJar.cpp | 40 + .../QEverCloud/src/NetworkCookieJar.h | 47 + src/qevercloud/QEverCloud/src/Printable.cpp | 36 + .../QEverCloud/src/RequestContext.cpp | 147 + .../QEverCloud/src/{thrift.h => Thrift.h} | 222 +- src/qevercloud/QEverCloud/src/Thumbnail.cpp | 255 + src/qevercloud/QEverCloud/src/VersionInfo.cpp | 54 + src/qevercloud/QEverCloud/src/exceptions.cpp | 378 - .../{constants.cpp => Constants.cpp} | 464 +- .../src/generated/EDAMErrorCode.cpp | 1303 + .../QEverCloud/src/generated/Servers.cpp | 18029 ++++ .../QEverCloud/src/generated/Services.cpp | 26197 +++++ .../QEverCloud/src/generated/Types.cpp | 21907 ++++ .../QEverCloud/src/generated/Types_io.h | 207 + .../QEverCloud/src/generated/services.cpp | 11055 -- .../QEverCloud/src/generated/types.cpp | 11330 --- .../QEverCloud/src/generated/types_impl.h | 215 - src/qevercloud/QEverCloud/src/globals.cpp | 44 - src/qevercloud/QEverCloud/src/http.cpp | 233 - src/qevercloud/QEverCloud/src/http.h | 96 - src/qevercloud/QEverCloud/src/oauth.cpp | 370 - .../src/oauth/AbstractOAuthEngine.cpp | 206 + .../src/oauth/AbstractOAuthEngine.h | 69 + .../QEverCloud/src/oauth/NetworkCookieJar.cpp | 36 + .../QEverCloud/src/oauth/NetworkCookieJar.h | 52 + .../QEverCloud/src/oauth/NonceGenerator.cpp | 63 + .../QEverCloud/src/oauth/NonceGenerator.h | 21 + src/qevercloud/QEverCloud/src/oauth/OAuth.cpp | 205 + .../src/oauth/OAuthSystemBrowser.cpp | 329 + .../QEverCloud/src/oauth/OAuthSystemBrowser.h | 72 + .../QEverCloud/src/oauth/OAuthWebEngine.cpp | 106 + .../QEverCloud/src/oauth/OAuthWebEngine.h | 58 + .../QEverCloud/src/oauth/OAuthWebKit.cpp | 130 + .../QEverCloud/src/oauth/OAuthWebKit.h | 55 + src/qevercloud/QEverCloud/src/oauth/Utils.cpp | 25 + src/qevercloud/QEverCloud/src/oauth/Utils.h | 19 + .../QEverCloud/src/services_nongenerated.cpp | 81 - .../QEverCloud/src/tests/MessageHandler.cpp | 60 + .../QEverCloud/src/tests/MessageHandler.h | 21 + .../src/tests/TestDurableService.cpp | 430 + .../QEverCloud/src/tests/TestDurableService.h | 35 + .../QEverCloud/src/tests/TestOptional.cpp | 139 + .../QEverCloud/src/tests/TestOptional.h | 38 + .../QEverCloud/src/tests/TestQEverCloud.cpp | 146 +- .../tests/generated/RandomDataGenerators.cpp | 1330 + .../tests/generated/RandomDataGenerators.h | 195 + .../src/tests/generated/TestNoteStore.cpp | 83285 ++++++++++++++++ .../src/tests/generated/TestNoteStore.h | 756 + .../src/tests/generated/TestUserStore.cpp | 13387 +++ .../src/tests/generated/TestUserStore.h | 148 + src/qevercloud/QEverCloud/src/thumbnail.cpp | 147 - .../translations/QEverCloud_ru_RU.ts | 37 + src/sql/notebooktable.cpp | 12 +- src/sql/searchtable.cpp | 4 +- src/sql/sharednotebooktable.cpp | 12 +- src/sql/usertable.cpp | 10 +- src/threads/syncrunner.cpp | 2 +- src/utilities/debugtool.cpp | 6 +- src/xml/exportdata.cpp | 14 +- 121 files changed, 179972 insertions(+), 26691 deletions(-) delete mode 100644 src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt4Dependencies.cmake delete mode 100644 src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt4DependenciesWithWebKit.cmake create mode 100644 src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesTranslations.cmake delete mode 100644 src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesWebEngineNoCore.cmake create mode 100644 src/qevercloud/QEverCloud/cmake/modules/QEverCloudUpdateTranslations.cmake create mode 100644 src/qevercloud/QEverCloud/headers/DurableService.h create mode 100644 src/qevercloud/QEverCloud/headers/Exceptions.h rename src/qevercloud/QEverCloud/headers/{export.h => Export.h} (71%) create mode 100644 src/qevercloud/QEverCloud/headers/Globals.h create mode 100644 src/qevercloud/QEverCloud/headers/Helpers.h create mode 100644 src/qevercloud/QEverCloud/headers/Log.h rename src/qevercloud/QEverCloud/headers/{oauth.h => OAuth.h} (57%) create mode 100644 src/qevercloud/QEverCloud/headers/Printable.h create mode 100644 src/qevercloud/QEverCloud/headers/RequestContext.h rename src/qevercloud/QEverCloud/headers/{thumbnail.h => Thumbnail.h} (65%) delete mode 100644 src/qevercloud/QEverCloud/headers/VersionInfo.h delete mode 100644 src/qevercloud/QEverCloud/headers/exceptions.h rename src/qevercloud/QEverCloud/headers/generated/{constants.h => Constants.h} (90%) create mode 100644 src/qevercloud/QEverCloud/headers/generated/Servers.h rename src/qevercloud/QEverCloud/headers/generated/{services.h => Services.h} (82%) rename src/qevercloud/QEverCloud/headers/generated/{types.h => Types.h} (67%) delete mode 100644 src/qevercloud/QEverCloud/headers/globals.h delete mode 100644 src/qevercloud/QEverCloud/headers/qt4helpers.h create mode 100644 src/qevercloud/QEverCloud/src/AsyncResult_p.cpp create mode 100644 src/qevercloud/QEverCloud/src/AsyncResult_p.h create mode 100644 src/qevercloud/QEverCloud/src/DurableService.cpp create mode 100644 src/qevercloud/QEverCloud/src/Exceptions.cpp create mode 100644 src/qevercloud/QEverCloud/src/Globals.cpp create mode 100644 src/qevercloud/QEverCloud/src/Http.cpp create mode 100644 src/qevercloud/QEverCloud/src/Http.h create mode 100644 src/qevercloud/QEverCloud/src/HttpRequestData.h create mode 100644 src/qevercloud/QEverCloud/src/HttpRequestParser.cpp create mode 100644 src/qevercloud/QEverCloud/src/HttpRequestParser.h create mode 100644 src/qevercloud/QEverCloud/src/HttpUtils.cpp create mode 100644 src/qevercloud/QEverCloud/src/HttpUtils.h rename src/qevercloud/QEverCloud/src/{impl.h => Impl.h} (65%) create mode 100644 src/qevercloud/QEverCloud/src/Log.cpp create mode 100644 src/qevercloud/QEverCloud/src/NetworkCookieJar.cpp create mode 100644 src/qevercloud/QEverCloud/src/NetworkCookieJar.h create mode 100644 src/qevercloud/QEverCloud/src/Printable.cpp create mode 100644 src/qevercloud/QEverCloud/src/RequestContext.cpp rename src/qevercloud/QEverCloud/src/{thrift.h => Thrift.h} (69%) create mode 100644 src/qevercloud/QEverCloud/src/Thumbnail.cpp create mode 100644 src/qevercloud/QEverCloud/src/VersionInfo.cpp delete mode 100644 src/qevercloud/QEverCloud/src/exceptions.cpp rename src/qevercloud/QEverCloud/src/generated/{constants.cpp => Constants.cpp} (71%) create mode 100644 src/qevercloud/QEverCloud/src/generated/EDAMErrorCode.cpp create mode 100644 src/qevercloud/QEverCloud/src/generated/Servers.cpp create mode 100644 src/qevercloud/QEverCloud/src/generated/Services.cpp create mode 100644 src/qevercloud/QEverCloud/src/generated/Types.cpp create mode 100644 src/qevercloud/QEverCloud/src/generated/Types_io.h delete mode 100644 src/qevercloud/QEverCloud/src/generated/services.cpp delete mode 100644 src/qevercloud/QEverCloud/src/generated/types.cpp delete mode 100644 src/qevercloud/QEverCloud/src/generated/types_impl.h delete mode 100644 src/qevercloud/QEverCloud/src/globals.cpp delete mode 100644 src/qevercloud/QEverCloud/src/http.cpp delete mode 100644 src/qevercloud/QEverCloud/src/http.h delete mode 100644 src/qevercloud/QEverCloud/src/oauth.cpp create mode 100644 src/qevercloud/QEverCloud/src/oauth/AbstractOAuthEngine.cpp create mode 100644 src/qevercloud/QEverCloud/src/oauth/AbstractOAuthEngine.h create mode 100644 src/qevercloud/QEverCloud/src/oauth/NetworkCookieJar.cpp create mode 100644 src/qevercloud/QEverCloud/src/oauth/NetworkCookieJar.h create mode 100644 src/qevercloud/QEverCloud/src/oauth/NonceGenerator.cpp create mode 100644 src/qevercloud/QEverCloud/src/oauth/NonceGenerator.h create mode 100644 src/qevercloud/QEverCloud/src/oauth/OAuth.cpp create mode 100644 src/qevercloud/QEverCloud/src/oauth/OAuthSystemBrowser.cpp create mode 100644 src/qevercloud/QEverCloud/src/oauth/OAuthSystemBrowser.h create mode 100644 src/qevercloud/QEverCloud/src/oauth/OAuthWebEngine.cpp create mode 100644 src/qevercloud/QEverCloud/src/oauth/OAuthWebEngine.h create mode 100644 src/qevercloud/QEverCloud/src/oauth/OAuthWebKit.cpp create mode 100644 src/qevercloud/QEverCloud/src/oauth/OAuthWebKit.h create mode 100644 src/qevercloud/QEverCloud/src/oauth/Utils.cpp create mode 100644 src/qevercloud/QEverCloud/src/oauth/Utils.h delete mode 100644 src/qevercloud/QEverCloud/src/services_nongenerated.cpp create mode 100644 src/qevercloud/QEverCloud/src/tests/MessageHandler.cpp create mode 100644 src/qevercloud/QEverCloud/src/tests/MessageHandler.h create mode 100644 src/qevercloud/QEverCloud/src/tests/TestDurableService.cpp create mode 100644 src/qevercloud/QEverCloud/src/tests/TestDurableService.h create mode 100644 src/qevercloud/QEverCloud/src/tests/TestOptional.cpp create mode 100644 src/qevercloud/QEverCloud/src/tests/TestOptional.h create mode 100644 src/qevercloud/QEverCloud/src/tests/generated/RandomDataGenerators.cpp create mode 100644 src/qevercloud/QEverCloud/src/tests/generated/RandomDataGenerators.h create mode 100644 src/qevercloud/QEverCloud/src/tests/generated/TestNoteStore.cpp create mode 100644 src/qevercloud/QEverCloud/src/tests/generated/TestNoteStore.h create mode 100644 src/qevercloud/QEverCloud/src/tests/generated/TestUserStore.cpp create mode 100644 src/qevercloud/QEverCloud/src/tests/generated/TestUserStore.h delete mode 100644 src/qevercloud/QEverCloud/src/thumbnail.cpp create mode 100644 src/qevercloud/QEverCloud/translations/QEverCloud_ru_RU.ts diff --git a/.gitignore b/.gitignore index ed28ac4d..2073515f 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,9 @@ qrc_*.* # Vim backup files *~ +# Vim temporary files +.*.swp + # Nixnote database backup files *.nnex @@ -72,4 +75,5 @@ testsrc/qmake-build-* /_build_dir_.txt - +# Autogenerated VersionInfo.h header in build dir +VersionInfo.h diff --git a/development/build-dependencies-ubuntu-2004.sh b/development/build-dependencies-ubuntu-2004.sh index 0b50c02a..44a6fcaa 100755 --- a/development/build-dependencies-ubuntu-2004.sh +++ b/development/build-dependencies-ubuntu-2004.sh @@ -23,4 +23,4 @@ sudo apt-get -y install git-core qt5-default build-essential \ # ./development/build-with-qmake.sh debug noclean /usr/lib/nixnote2/tidy # then binary is in: ./qmake-build-debug/nixnote2 # cd appdir -# ./usr/appdir/nixnote2 \ No newline at end of file +# ./usr/appdir/nixnote2 diff --git a/nixnote2.pro b/nixnote2.pro index 74099b20..0f227b56 100644 --- a/nixnote2.pro +++ b/nixnote2.pro @@ -1,4 +1,5 @@ QT += core gui widgets printsupport webkit webkitwidgets sql network xml dbus qml + DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 unix { CONFIG += link_pkgconfig @@ -16,6 +17,7 @@ win32:LIBS += -L"$$PWD/winlib" -lhunspell-$$[HUNSPELL_VERSION] win32:RC_ICONS += "$$PWD/resources/images/windowIcon.ico" INCLUDEPATH += "$$PWD/src/qevercloud/QEverCloud/headers" +INCLUDEPATH += "$$OUT_PWD" mac { TARGET = NixNote2 @@ -40,6 +42,28 @@ CONFIG(debug, debug|release) { OBJECTS_DIR = $${DESTDIR} MOC_DIR = $${DESTDIR} +oauth_webengine { + win32-g++ { + error("Cannot use QtWebEngine with MinGW build") + } else { + message("Using QtWebEngine for OAuth") + QT += webengine webenginewidgets + QEVERCLOUD_USE_QT_WEB_ENGINE = 1 + DEFINES += QEVERCLOUD_USE_QT_WEB_ENGINE=1 + } +} else { + message("Using QtWebKit for OAuth") + !win32-g++ { + warning("Consider adding CONFIG+=oauth_webengine to qmake invocation to use QtWebEngine for OAuth; QtWebKit has known problems with it, OAuth may not work!") + } + QEVERCLOUD_USE_QT_WEB_ENGINE = 0 + DEFINES += QEVERCLOUD_USE_QT_WEB_ENGINE=0 +} + +qevercloud_version_info.input = src/qevercloud/QEverCloud/headers/VersionInfo.h.in +qevercloud_version_info.output = $$OUT_PWD/VersionInfo.h +QMAKE_SUBSTITUTES += qevercloud_version_info + SOURCES += \ src/application.cpp \ src/global.cpp \ @@ -173,17 +197,28 @@ SOURCES += \ src/oauth/oauthtokenizer.cpp \ src/hunspell/spellchecker.cpp \ src/qevercloud/QEverCloud/src/AsyncResult.cpp \ + src/qevercloud/QEverCloud/src/AsyncResult_p.cpp \ + src/qevercloud/QEverCloud/src/DurableService.cpp \ src/qevercloud/QEverCloud/src/EventLoopFinisher.cpp \ src/qevercloud/QEverCloud/src/EverCloudException.cpp \ - src/qevercloud/QEverCloud/src/exceptions.cpp \ - src/qevercloud/QEverCloud/src/generated/constants.cpp \ - src/qevercloud/QEverCloud/src/generated/services.cpp \ - src/qevercloud/QEverCloud/src/generated/types.cpp \ - src/qevercloud/QEverCloud/src/globals.cpp \ - src/qevercloud/QEverCloud/src/http.cpp \ - src/qevercloud/QEverCloud/src/oauth.cpp \ - src/qevercloud/QEverCloud/src/services_nongenerated.cpp \ - src/qevercloud/QEverCloud/src/thumbnail.cpp \ + src/qevercloud/QEverCloud/src/Exceptions.cpp \ + src/qevercloud/QEverCloud/src/generated/Constants.cpp \ + src/qevercloud/QEverCloud/src/generated/EDAMErrorCode.cpp \ + src/qevercloud/QEverCloud/src/generated/Servers.cpp \ + src/qevercloud/QEverCloud/src/generated/Services.cpp \ + src/qevercloud/QEverCloud/src/generated/Types.cpp \ + src/qevercloud/QEverCloud/src/Globals.cpp \ + src/qevercloud/QEverCloud/src/Http.cpp \ + src/qevercloud/QEverCloud/src/HttpRequestParser.cpp \ + src/qevercloud/QEverCloud/src/HttpUtils.cpp \ + src/qevercloud/QEverCloud/src/InkNoteImageDownloader.cpp \ + src/qevercloud/QEverCloud/src/Log.cpp \ + src/qevercloud/QEverCloud/src/NetworkCookieJar.cpp \ + src/qevercloud/QEverCloud/src/OAuth.cpp \ + src/qevercloud/QEverCloud/src/Printable.cpp \ + src/qevercloud/QEverCloud/src/RequestContext.cpp \ + src/qevercloud/QEverCloud/src/Thumbnail.cpp \ + src/qevercloud/QEverCloud/src/VersionInfo.cpp \ src/reminders/reminderevent.cpp \ src/reminders/remindermanager.cpp \ src/settings/accountsmanager.cpp \ @@ -368,25 +403,33 @@ HEADERS += \ src/oauth/oauthtokenizer.h \ src/hunspell/spellchecker.h \ src/qevercloud/QEverCloud/headers/AsyncResult.h \ + src/qevercloud/QEverCloud/headers/DurableService.h \ src/qevercloud/QEverCloud/headers/EventLoopFinisher.h \ src/qevercloud/QEverCloud/headers/EverCloudException.h \ - src/qevercloud/QEverCloud/headers/exceptions.h \ - src/qevercloud/QEverCloud/headers/export.h \ - src/qevercloud/QEverCloud/headers/generated/constants.h \ + src/qevercloud/QEverCloud/headers/Exceptions.h \ + src/qevercloud/QEverCloud/headers/Export.h \ + src/qevercloud/QEverCloud/headers/generated/Constants.h \ src/qevercloud/QEverCloud/headers/generated/EDAMErrorCode.h \ - src/qevercloud/QEverCloud/headers/generated/services.h \ - src/qevercloud/QEverCloud/headers/generated/types.h \ - src/qevercloud/QEverCloud/headers/globals.h \ - src/qevercloud/QEverCloud/headers/oauth.h \ + src/qevercloud/QEverCloud/headers/generated/Servers.h \ + src/qevercloud/QEverCloud/headers/generated/Services.h \ + src/qevercloud/QEverCloud/headers/generated/Types.h \ + src/qevercloud/QEverCloud/headers/Globals.h \ + src/qevercloud/QEverCloud/headers/Helpers.h \ + src/qevercloud/QEverCloud/headers/InkNoteImageDownloader.h \ + src/qevercloud/QEverCloud/headers/Log.h \ + src/qevercloud/QEverCloud/headers/OAuth.h \ src/qevercloud/QEverCloud/headers/Optional.h \ + src/qevercloud/QEverCloud/headers/Printable.h \ src/qevercloud/QEverCloud/headers/QEverCloud.h \ src/qevercloud/QEverCloud/headers/QEverCloudOAuth.h \ - src/qevercloud/QEverCloud/headers/qt4helpers.h \ - src/qevercloud/QEverCloud/headers/thumbnail.h \ - src/qevercloud/QEverCloud/src/generated/types_impl.h \ - src/qevercloud/QEverCloud/src/http.h \ - src/qevercloud/QEverCloud/src/impl.h \ - src/qevercloud/QEverCloud/src/thrift.h \ + src/qevercloud/QEverCloud/headers/RequestContext.h \ + src/qevercloud/QEverCloud/headers/Thumbnail.h \ + src/qevercloud/QEverCloud/src/generated/Types_io.h \ + src/qevercloud/QEverCloud/src/AsyncResult_p.h \ + src/qevercloud/QEverCloud/src/Http.h \ + src/qevercloud/QEverCloud/src/Impl.h \ + src/qevercloud/QEverCloud/src/NetworkCookieJar.h \ + src/qevercloud/QEverCloud/src/Thrift.h \ src/reminders/reminderevent.h \ src/reminders/remindermanager.h \ src/settings/accountsmanager.h \ @@ -453,7 +496,7 @@ gcc { CONFIG += $$COMPILER_CONFIG } -QMAKE_CXXFLAGS += -std=c++11 -g -O2 -Wformat -Werror=format-security +QMAKE_CXXFLAGS += -std=c++14 -g -O2 -Wformat -Werror=format-security linux:QMAKE_LFLAGS += -Wl,-Bsymbolic-functions -Wl,-z,relro g++4 { diff --git a/src/communication/communicationerror.cpp b/src/communication/communicationerror.cpp index 91622066..4901b435 100644 --- a/src/communication/communicationerror.cpp +++ b/src/communication/communicationerror.cpp @@ -90,7 +90,7 @@ void CommunicationError::resetTo( QString CommunicationError::edamErrorCodeToString(int code) { - switch (code) { + switch (static_cast(code)) { case qevercloud::EDAMErrorCode::UNKNOWN: return "UNKNOWN"; case qevercloud::EDAMErrorCode::BAD_DATA_FORMAT: diff --git a/src/communication/communicationmanager.cpp b/src/communication/communicationmanager.cpp index 69132c5f..9e116594 100644 --- a/src/communication/communicationmanager.cpp +++ b/src/communication/communicationmanager.cpp @@ -56,6 +56,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. extern Global global; +// set Evernote http timeout to 4 minutes +// actually it is nor exactly connection timeout nor request timeout - it seems to be time between http reads +// where if nothing happens, timeout is reached +// but actually the excat definition should not matter much in real use cases +// timeout is is set to big enought value to work well even for full sync and slower connections +// but will eventually timeout, if the network is unstable +// see https://github.com/d1vanov/QEverCloud/issues/22#issuecomment-525745982 +const int requestTimeout = 4 * 60 * 10000; // Generic constructor CommunicationManager::CommunicationManager(DatabaseConnection *db) { @@ -136,7 +144,7 @@ bool CommunicationManager::initNoteStore() { noteStorePath = "/edam/note/" + shardId; QString noteStoreUrl = QString("https://") + evernoteHost + noteStorePath; - myNoteStore = new NoteStore(noteStoreUrl, authToken, this); + myNoteStore = newNoteStore(noteStoreUrl, newRequestContext(authToken, requestTimeout), this); noteStore = myNoteStore; return true; } @@ -156,7 +164,7 @@ void CommunicationManager::enDisconnect() { // Get a user's information bool CommunicationManager::getUserInfo(User &user) { - QNetworkAccessManager *p = evernoteNetworkAccessManager(); + QNetworkAccessManager *p = new QNetworkAccessManager; QNetworkAccessManager::NetworkAccessibility accessibility = p->networkAccessible(); // unfortunately it doesn't really seem to check the network availability qint64 time1 = QDateTime::currentMSecsSinceEpoch(); @@ -164,7 +172,8 @@ bool CommunicationManager::getUserInfo(User &user) { QLOG_DEBUG() << "CommunicationManager.getUserInfo(): new UserStore(); host=" << evernoteHost; QLOG_TRACE() << "token=" << authToken; - userStore = new UserStore(evernoteHost, authToken); + + userStore = newUserStore(evernoteHost, newRequestContext(authToken, requestTimeout)); bool res = true; try { @@ -172,10 +181,10 @@ bool CommunicationManager::getUserInfo(User &user) { User u = userStore->getUser(); user = u; } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); res = false; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); res = false; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -218,12 +227,12 @@ bool CommunicationManager::getSyncState(QString token, SyncState &syncState) { noteStore = myNoteStore; else noteStore = linkedNoteStore; - syncState = noteStore->getSyncState(authToken); + syncState = noteStore->getSyncState(newRequestContext(authToken, requestTimeout)); } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return false; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return false; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -285,13 +294,13 @@ CommunicationManager::getSyncChunk(SyncChunk &chunk, int start, int chunkSize, i // This is a failsafe to prevnt loops if nothing passes the filter chunk.chunkHighUSN = chunk.updateCount; try { - chunk = myNoteStore->getFilteredSyncChunk(start, chunkSize, filter, token); + chunk = myNoteStore->getFilteredSyncChunk(start, chunkSize, filter, newRequestContext(token, requestTimeout)); processSyncChunk(chunk, token); } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return false; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return false; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -308,17 +317,17 @@ CommunicationManager::getSyncChunk(SyncChunk &chunk, int start, int chunkSize, i qint32 CommunicationManager::uploadSavedSearch(SavedSearch &search) { try { if (search.updateSequenceNum > 0) - return myNoteStore->updateSearch(search, authToken); + return myNoteStore->updateSearch(search, newRequestContext(authToken, requestTimeout)); else - search = myNoteStore->createSearch(search, authToken); + search = myNoteStore->createSearch(search, newRequestContext(authToken, requestTimeout)); return search.updateSequenceNum; } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); DebugTool d; d.dumpSavedSearch(search); return 0; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); DebugTool d; d.dumpSavedSearch(search); return 0; @@ -339,12 +348,12 @@ qint32 CommunicationManager::uploadSavedSearch(SavedSearch &search) { // Permanently delete a saved search qint32 CommunicationManager::expungeSavedSearch(Guid guid) { try { - return myNoteStore->expungeSearch(guid, authToken); + return myNoteStore->expungeSearch(guid, newRequestContext(authToken, requestTimeout)); } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return 0; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return 0; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -364,23 +373,23 @@ qint32 CommunicationManager::uploadTag(Tag &tag) { try { if (tag.updateSequenceNum > 0) { QLOG_TRACE_OUT(); - return myNoteStore->updateTag(tag, authToken); + return myNoteStore->updateTag(tag, newRequestContext(authToken, requestTimeout)); } else { - tag = myNoteStore->createTag(tag, authToken); + tag = myNoteStore->createTag(tag, newRequestContext(authToken, requestTimeout)); QLOG_TRACE_OUT(); return tag.updateSequenceNum; } } catch (ThriftException &e) { QString msg(e.what()); msg.append(" # ").append(additionalInfo); - reportError(CommunicationError::ThriftException, e.type(), msg); + reportError(CommunicationError::ThriftException, static_cast(e.type()), msg); DebugTool d; d.dumpTag(tag); return 0; } catch (EDAMUserException &e) { QString msg(e.what()); msg.append(" # ").append(additionalInfo); - reportError(CommunicationError::EDAMUserException, e.errorCode, msg); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), msg); DebugTool d; d.dumpTag(tag); return 0; @@ -401,12 +410,12 @@ qint32 CommunicationManager::uploadTag(Tag &tag) { // Permanently delete a tag from Evernote qint32 CommunicationManager::expungeTag(Guid guid) { try { - return myNoteStore->expungeTag(guid, authToken); + return myNoteStore->expungeTag(guid, newRequestContext(authToken, requestTimeout)); } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return 0; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return 0; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -421,18 +430,18 @@ qint32 CommunicationManager::expungeTag(Guid guid) { qint32 CommunicationManager::uploadNotebook(Notebook ¬ebook) { try { if (notebook.updateSequenceNum > 0) - return myNoteStore->updateNotebook(notebook, authToken); + return myNoteStore->updateNotebook(notebook, newRequestContext(authToken, requestTimeout)); else { - notebook = myNoteStore->createNotebook(notebook, authToken); + notebook = myNoteStore->createNotebook(notebook, newRequestContext(authToken, requestTimeout)); return notebook.updateSequenceNum; } } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); DebugTool d; d.dumpNotebook(notebook); return 0; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); DebugTool d; d.dumpNotebook(notebook); return 0; @@ -453,14 +462,14 @@ qint32 CommunicationManager::uploadNotebook(Notebook ¬ebook) { // Permanently delete a notebook from Evernote qint32 CommunicationManager::expungeNotebook(Guid guid) { try { - return myNoteStore->expungeNotebook(guid, authToken); + return myNoteStore->expungeNotebook(guid, newRequestContext(authToken, requestTimeout)); } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return 0; } catch (EDAMNotFoundException) { return 1; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return 0; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -494,17 +503,17 @@ qint32 CommunicationManager::uploadNote(Note ¬e, QString token) { try { if (note.updateSequenceNum.isSet() && note.updateSequenceNum > 0) { QLOG_DEBUG() << "qevercloud noteStore->updateNote"; - note = noteStore->updateNote(note, token); + note = noteStore->updateNote(note, newRequestContext(token, requestTimeout)); } else { QLOG_DEBUG() << "qevercloud noteStore->createNote"; - note = noteStore->createNote(note, token); + note = noteStore->createNote(note, newRequestContext(token, requestTimeout)); } updateSequenceNum = note.updateSequenceNum; } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); //dumpNote(note); } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); //dumpNote(note); } catch (EDAMSystemException &e) { handleEDAMSystemException(e, note.title); @@ -563,12 +572,12 @@ qint32 CommunicationManager::deleteNote(Guid note, QString token) { try { - return noteStore->deleteNote(note, token); + return noteStore->deleteNote(note, newRequestContext(token, requestTimeout)); } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return 0; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return 0; } catch (EDAMNotFoundException &e) { return 1; @@ -604,12 +613,12 @@ qint32 CommunicationManager::uploadLinkedNote(Note ¬e) { // Get a shared notebook by authentication token bool CommunicationManager::getSharedNotebookByAuth(SharedNotebook &sharedNotebook) { try { - sharedNotebook = noteStore->getSharedNotebookByAuth(linkedAuthToken); + sharedNotebook = noteStore->getSharedNotebookByAuth(newRequestContext(linkedAuthToken, requestTimeout)); } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return false; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return false; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -646,13 +655,13 @@ bool CommunicationManager::authenticateToLinkedNotebookShard(LinkedNotebook &boo return true; // We have a share key, so authenticate - linkedAuth = noteStore->authenticateToSharedNotebook(book.sharedNotebookGlobalId, authToken); + linkedAuth = noteStore->authenticateToSharedNotebook(book.sharedNotebookGlobalId, newRequestContext(authToken, requestTimeout)); linkedAuthToken = linkedAuth.authenticationToken; } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return false; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return false; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -668,12 +677,12 @@ bool CommunicationManager::authenticateToLinkedNotebookShard(LinkedNotebook &boo // Get a linked notebook's sync state bool CommunicationManager::getLinkedNotebookSyncState(SyncState &syncState, LinkedNotebook &linkedNotebook) { try { - syncState = linkedNoteStore->getLinkedNotebookSyncState(linkedNotebook, linkedAuthToken); + syncState = linkedNoteStore->getLinkedNotebookSyncState(linkedNotebook, newRequestContext(linkedAuthToken, requestTimeout)); } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return false; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return false; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -690,13 +699,13 @@ bool CommunicationManager::getLinkedNotebookSyncState(SyncState &syncState, Link bool CommunicationManager::getLinkedNotebookSyncChunk(SyncChunk &chunk, LinkedNotebook &book, int start, int chunkSize, bool fullSync) { try { - chunk = linkedNoteStore->getLinkedNotebookSyncChunk(book, start, chunkSize, fullSync, authToken); + chunk = linkedNoteStore->getLinkedNotebookSyncChunk(book, start, chunkSize, fullSync, newRequestContext(authToken, requestTimeout)); processSyncChunk(chunk, linkedAuthToken); } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return false; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return false; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -726,13 +735,13 @@ bool CommunicationManager::getLinkedNotebookSyncChunk(SyncChunk &chunk, LinkedNo // get a list of all prior versions of a note bool CommunicationManager::listNoteVersions(QList &list, QString guid) { try { - list = noteStore->listNoteVersions(guid, authToken); + list = noteStore->listNoteVersions(guid, newRequestContext(authToken, requestTimeout)); return true; } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return false; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return false; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -750,13 +759,13 @@ bool CommunicationManager::getNoteVersion(Note ¬e, QString guid, qint32 usn, try { note = noteStore->getNoteVersion(guid, usn, withResourceData, withResourceRecognition, withResourceAlternateData, - authToken); + newRequestContext(authToken, requestTimeout)); return true; } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return false; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return false; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -773,13 +782,13 @@ bool CommunicationManager::getNote(Note ¬e, QString guid, bool withResource, bool withResourceAlternateData) { try { note = noteStore->getNote(guid, true, withResource, withResourceRecognition, withResourceAlternateData, - authToken); + newRequestContext(authToken, requestTimeout)); return true; } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return false; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return false; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -807,13 +816,13 @@ bool CommunicationManager::getNote(Note ¬e, QString guid, bool withResource, bool CommunicationManager::getNotebookList(QList &list) { QList retval; try { - retval = noteStore->listNotebooks(authToken); + retval = noteStore->listNotebooks(newRequestContext(authToken, requestTimeout)); list = retval; } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return false; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return false; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -830,13 +839,13 @@ bool CommunicationManager::getNotebookList(QList &list) { bool CommunicationManager::getTagList(QList &list) { QList retval; try { - retval = noteStore->listTags(authToken); + retval = noteStore->listTags(newRequestContext(authToken, requestTimeout)); list = retval; } catch (ThriftException &e) { - reportError(CommunicationError::ThriftException, e.type(), e.what()); + reportError(CommunicationError::ThriftException, static_cast(e.type()), e.what()); return false; } catch (EDAMUserException &e) { - reportError(CommunicationError::EDAMUserException, e.errorCode, e.what()); + reportError(CommunicationError::EDAMUserException, static_cast(e.errorCode), e.what()); return false; } catch (EDAMSystemException &e) { handleEDAMSystemException(e); @@ -893,8 +902,13 @@ void CommunicationManager::downloadInkNoteImage(QString guid, Resource *r, QStri QImage *newImage = nullptr; User u; userTable.getUser(u); - if (shard == "") + if (shard == "") { + if (!u.shardId.isSet()) { + return; + } shard = u.shardId; + } + QString urlBase = QString("https://") + evernoteHost + QString("/shard/") + shard @@ -990,11 +1004,12 @@ void CommunicationManager::processSyncChunk(SyncChunk &chunk, QString token) { QList notes; if (chunk.notes.isSet()) notes = chunk.notes; + auto requestContext = newRequestContext(token, requestTimeout); for (int i = 0; i < notes.size(); i++) { QLOG_TRACE() << "Fetching chunk item: " << i << ": " << notes[i].title; Note n = notes[i]; noteList.insert(n.guid, ""); - n = noteStore->getNote(notes[i].guid, true, true, true, true, token); + n = noteStore->getNote(notes[i].guid, true, true, true, true, requestContext); QLOG_TRACE() << "Note Retrieved"; // Load up the tag names because Evernote doesn't give them. @@ -1030,7 +1045,7 @@ void CommunicationManager::processSyncChunk(SyncChunk &chunk, QString token) { for (int i = 0; i < resources.size(); i++) { QLOG_TRACE() << "Fetching chunk resource item: " << i << ": " << resources[i].guid; Resource r; - r = noteStore->getResource(resources[i].guid, true, true, true, true, token); + r = noteStore->getResource(resources[i].guid, true, true, true, true, requestContext); QLOG_TRACE() << "Resource retrieved"; resourceData.append(r); } @@ -1088,11 +1103,11 @@ void CommunicationManager::handleEDAMSystemException(EDAMSystemException e, QStr if (e.rateLimitDuration.isSet()) { msg.append(" # rateLimitDuration=").append(e.rateLimitDuration.ref()); } - reportError(CommunicationError::RateLimitExceeded, e.errorCode, userMessage, msg); + reportError(CommunicationError::RateLimitExceeded, static_cast(e.errorCode), userMessage, msg); return; } - reportError(CommunicationError::EDAMSystemException, e.errorCode, msg); + reportError(CommunicationError::EDAMSystemException, static_cast(e.errorCode), msg); } // Error handler EDAM Not Found exception. diff --git a/src/communication/communicationmanager.h b/src/communication/communicationmanager.h index b643e748..a8c1a041 100644 --- a/src/communication/communicationmanager.h +++ b/src/communication/communicationmanager.h @@ -91,10 +91,10 @@ class CommunicationManager : public QObject QNetworkAccessManager *networkAccessManager; // Network connection to download inknotes void handleEDAMSystemException(EDAMSystemException e, QString additionalInfo = ""); void handleEDAMNotFoundException(EDAMNotFoundException e, QString additionalInfo = ""); - UserStore *userStore; // UserStore class - NoteStore *noteStore; // Notestore class - NoteStore *linkedNoteStore; // Linked notestore class - NoteStore *myNoteStore; // local account notestore class + IUserStore *userStore; // UserStore class + INoteStore *noteStore; // Notestore class + INoteStore *linkedNoteStore; // Linked notestore class + INoteStore *myNoteStore; // local account notestore class void processSyncChunk(SyncChunk &chunk, QString token); // Deal with a sync chunk. void dumpNote(const Note ¬e) const; void reportError(const CommunicationError::CommunicationErrorType errorType, diff --git a/src/nixnote.cpp b/src/nixnote.cpp index 92ff867e..73b79e8d 100644 --- a/src/nixnote.cpp +++ b/src/nixnote.cpp @@ -160,15 +160,6 @@ NixNote::NixNote(QWidget *parent) : QMainWindow(parent) { connect(this, SIGNAL(updateCounts()), &counterRunner, SLOT(countAll())); - // set Evernote http timeout to 4 minutes - // actually it is nor exactly connection timeout nor request timeout - it seems to be time between http reads - // where if nothing happens, timeout is reached - // but actually the excat definition should not matter much in real use cases - // timeout is is set to big enought value to work well even for full sync and slower connections - // but will eventually timeout, if the network is unstable - // see https://github.com/d1vanov/QEverCloud/issues/22#issuecomment-525745982 - setConnectionTimeout(4 * 60 * 1000); - // Setup the counter thread QLOG_DEBUG() << "Setting up sync thread"; connect(this, SIGNAL(syncRequested()), &syncRunner, SLOT(synchronize())); diff --git a/src/qevercloud/CMakeLists.txt b/src/qevercloud/CMakeLists.txt index b4ad9c6d..239e5265 100644 --- a/src/qevercloud/CMakeLists.txt +++ b/src/qevercloud/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.5.1) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/QEverCloud/cmake/modules") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/QEverCloud/cmake/modules/sanitizers") @@ -6,20 +6,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/QEverClo include(QEverCloudCMakePolicies) SET_POLICIES() -if("${CMAKE_MAJOR_VERSION}" GREATER "2") - project(QEverCloud - VERSION 4.1.0) -else() - project(QEverCloud) - set(PROJECT_VERSION_MAJOR "4") - set(PROJECT_VERSION_MINOR "1") - set(PROJECT_VERSION_PATCH "0") - set(PROJECT_VERSION_COUNT 3) - set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") -endif() +project(QEverCloud + VERSION 6.2.0) set(PROJECT_VENDOR "Dmitry Ivanov") -set(PROJECT_COPYRIGHT_YEAR "2015-2018") +set(PROJECT_COPYRIGHT_YEAR "2015-2023") set(PROJECT_DOMAIN_FIRST "qevercloud") set(PROJECT_DOMAIN_SECOND "com") set(PROJECT_DOMAIN "${PROJECT_DOMAIN_FIRST}.${PROJECT_DOMAIN_SECOND}") @@ -29,6 +20,8 @@ include(QEverCloudDoxygen) set(BUILD_DOCUMENTATION ON CACHE BOOL "Build documentation for QEverCloud") set(BUILD_QCH_DOCUMENTATION OFF CACHE BOOL "Build documentation for QEverCloud in qch format") set(BUILD_WITH_OAUTH_SUPPORT ON CACHE BOOL "Build QEverCloud with OAuth support") +set(BUILD_WITH_Q_NAMESPACE ON CACHE BOOL "Use Q_NAMESPACE and Q_ENUM_NS macros for introspection") +set(BUILD_TRANSLATIONS ON CACHE BOOL "Build translations") if(BUILD_DOCUMENTATION) # set Doxygen documentation properties @@ -50,15 +43,10 @@ if(BUILD_DOCUMENTATION) endif() include(QEverCloudCompilerSettings) - -set(BUILD_WITH_QT4 OFF CACHE BOOL "Build against Qt4 instead of Qt5") include(QEverCloudSetupQt) +include(QEverCloudUpdateTranslations) -if(BUILD_WITH_QT4) - set(QEVERCLOUD_QT_VERSION "qt4") -else() - set(QEVERCLOUD_QT_VERSION "qt5") -endif() +set(QEVERCLOUD_QT_VERSION "qt5") if(NOT CMAKE_INSTALL_LIBDIR) set(CMAKE_INSTALL_LIBDIR "lib") @@ -72,6 +60,10 @@ if(NOT CMAKE_INSTALL_INCLUDEDIR) set(CMAKE_INSTALL_INCLUDEDIR "include") endif() +if(NOT CMAKE_INSTALL_TRANSLATIONSDIR) + set(CMAKE_INSTALL_TRANSLATIONSDIR "share/${PROJECT_NAME}/translations") +endif() + if(NOT INSTALL_CMAKE_DIR) if(WIN32 AND NOT CYGWIN) set(INSTALL_CMAKE_DIR "CMake") @@ -81,8 +73,6 @@ if(NOT INSTALL_CMAKE_DIR) endif() set(BUILD_SHARED ON CACHE BOOL "Build shared library, otherwise static library") -set(MAJOR_VERSION_LIB_NAME_SUFFIX OFF CACHE BOOL "If on, the project's major version would be added to the library's name as a suffix") -set(MAJOR_VERSION_DEV_HEADERS_FOLDER_NAME_SUFFIX OFF CACHE BOOL "If on, the project's major version would be added to the library's development headers' folder name as a suffix") if(MSVC) set(QEVERCLOUD_LIBNAME_PREFIX "lib") @@ -90,17 +80,18 @@ else() set(QEVERCLOUD_LIBNAME_PREFIX "") endif() -set(QEVERCLOUD_LIBNAME_SUFFIX "") -if(MAJOR_VERSION_LIB_NAME_SUFFIX) - set(QEVERCLOUD_LIBNAME_SUFFIX "${PROJECT_VERSION_MAJOR}") -endif() - if(QEVERCLOUD_USE_QT_WEB_ENGINE) set(QEVERCLOUD_USES_QT_WEB_ENGINE "set(QEVERCLOUD_USE_QT_WEB_ENGINE TRUE)") else() set(QEVERCLOUD_USES_QT_WEB_ENGINE "set(QEVERCLOUD_USE_QT_WEB_ENGINE FALSE)") endif() +if(QEVERCLOUD_USE_SYSTEM_BROWSER) + set(QEVERCLOUD_USES_SYSTEM_BROWSER "set(QEVERCLOUD_USE_SYSTEM_BROWSER TRUE)") +else() + set(QEVERCLOUD_USES_SYSTEM_BROWSER "set(QEVERCLOUD_USE_SYSTEM_BROWSER FALSE)") +endif() + if(BUILD_WITH_OAUTH_SUPPORT) set(QEVERCLOUD_HAS_OAUTH "set(QEVERCLOUD_HAS_OAUTH TRUE)") else() @@ -114,29 +105,21 @@ configure_file(QEverCloud/cmake/modules/QEverCloudConfig.cmake.in configure_file(QEverCloud/cmake/modules/QEverCloudConfigVersion.cmake.in ${PROJECT_BINARY_DIR}/QEverCloud-${QEVERCLOUD_QT_VERSION}ConfigVersion.cmake @ONLY) -if(BUILD_WITH_QT4) - if(BUILD_WITH_OAUTH_SUPPORT) - file(COPY QEverCloud/cmake/modules/QEverCloudFindQt4DependenciesWithWebKit.cmake DESTINATION ${PROJECT_BINARY_DIR}) - file(RENAME ${PROJECT_BINARY_DIR}/QEverCloudFindQt4DependenciesWithWebKit.cmake ${PROJECT_BINARY_DIR}/QEverCloud-${QEVERCLOUD_QT_VERSION}FindQtDependencies.cmake) - else() - file(COPY QEverCloud/cmake/modules/QEverCloudFindQt4Dependencies.cmake DESTINATION ${PROJECT_BINARY_DIR}) - file(RENAME ${PROJECT_BINARY_DIR}/QEverCloudFindQt4Dependencies.cmake ${PROJECT_BINARY_DIR}/QEverCloud-${QEVERCLOUD_QT_VERSION}FindQtDependencies.cmake) - endif() -else() - file(COPY QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesCore.cmake DESTINATION ${PROJECT_BINARY_DIR}) - file(RENAME ${PROJECT_BINARY_DIR}/QEverCloudFindQt5DependenciesCore.cmake ${PROJECT_BINARY_DIR}/QEverCloud-${QEVERCLOUD_QT_VERSION}FindQtDependencies.cmake) - - if(BUILD_WITH_OAUTH_SUPPORT) - if(USE_QT5_WEBKIT OR (Qt5Core_VERSION VERSION_LESS "5.4.0")) - file(READ QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesWebKit.cmake WEBKIT_DEPS_FILE) - file(APPEND ${PROJECT_BINARY_DIR}/QEverCloud-${QEVERCLOUD_QT_VERSION}FindQtDependencies.cmake "${WEBKIT_DEPS_FILE}") - elseif(Qt5Core_VERSION VERSION_LESS "5.6.0") - file(READ QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesWebEngineNoCore.cmake WEBENGINE_NO_CORE_DEPS_FILE) - file(APPEND ${PROJECT_BINARY_DIR}/QEverCloud-${QEVERCLOUD_QT_VERSION}FindQtDependencies.cmake "${WEBENGINE_NO_CORE_DEPS_FILE}") - else() - file(READ QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesWebEngineCore.cmake WEBENGINE_CORE_DEPS_FILE) - file(APPEND ${PROJECT_BINARY_DIR}/QEverCloud-${QEVERCLOUD_QT_VERSION}FindQtDependencies.cmake "${WEBENGINE_CORE_DEPS_FILE}") - endif() +file(COPY QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesCore.cmake DESTINATION ${PROJECT_BINARY_DIR}) +file(RENAME ${PROJECT_BINARY_DIR}/QEverCloudFindQt5DependenciesCore.cmake ${PROJECT_BINARY_DIR}/QEverCloud-${QEVERCLOUD_QT_VERSION}FindQtDependencies.cmake) + +if(BUILD_TRANSLATIONS) + file(READ QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesTranslations.cmake TRANSLATIONS_DEPS_FILE) + file(APPEND ${PROJECT_BINARY_DIR}/QEverCloud-${QEVERCLOUD_QT_VERSION}FindQtDependencies.cmake "${TRANSLATIONS_DEPS_FILE}") +endif() + +if(BUILD_WITH_OAUTH_SUPPORT) + if(USE_QT5_WEBKIT OR Qt5Core_VERSION VERSION_LESS "5.6.0") + file(READ QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesWebKit.cmake WEBKIT_DEPS_FILE) + file(APPEND ${PROJECT_BINARY_DIR}/QEverCloud-${QEVERCLOUD_QT_VERSION}FindQtDependencies.cmake "${WEBKIT_DEPS_FILE}") + elseif(NOT QEVERCLOUD_USE_SYSTEM_BROWSER) + file(READ QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesWebEngineCore.cmake WEBENGINE_CORE_DEPS_FILE) + file(APPEND ${PROJECT_BINARY_DIR}/QEverCloud-${QEVERCLOUD_QT_VERSION}FindQtDependencies.cmake "${WEBENGINE_CORE_DEPS_FILE}") endif() endif() diff --git a/src/qevercloud/QEverCloud/CMakeLists.txt b/src/qevercloud/QEverCloud/CMakeLists.txt index cd4bf20d..004dbbb2 100644 --- a/src/qevercloud/QEverCloud/CMakeLists.txt +++ b/src/qevercloud/QEverCloud/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.5.1) include(QEverCloudCMakePolicies) SET_POLICIES() @@ -14,51 +14,111 @@ if(BUILD_WITH_OAUTH_SUPPORT) endif() set(NON_GENERATED_HEADERS - headers/export.h - headers/exceptions.h - headers/globals.h - headers/thumbnail.h headers/AsyncResult.h + headers/DurableService.h + headers/EventLoopFinisher.h + headers/EverCloudException.h + headers/Export.h + headers/Exceptions.h + headers/Globals.h + headers/Helpers.h headers/InkNoteImageDownloader.h + headers/Log.h headers/Optional.h - headers/EverCloudException.h - headers/qt4helpers.h - headers/EventLoopFinisher.h) + headers/Printable.h + headers/RequestContext.h + headers/Thumbnail.h) if(BUILD_WITH_OAUTH_SUPPORT) list(APPEND NON_GENERATED_HEADERS - headers/oauth.h) + headers/OAuth.h) endif() set(GENERATED_HEADERS - headers/generated/constants.h - headers/generated/services.h - headers/generated/types.h + headers/generated/Constants.h + headers/generated/Services.h + headers/generated/Servers.h + headers/generated/Types.h headers/generated/EDAMErrorCode.h) set(PRIVATE_HEADERS - src/thrift.h - src/http.h - src/impl.h - src/generated/types_impl.h) + src/AsyncResult_p.h + src/Http.h + src/HttpRequestData.h + src/HttpRequestParser.h + src/HttpUtils.h + src/Impl.h + src/Thrift.h + src/generated/Types_io.h + src/oauth/NetworkCookieJar.h + src/oauth/AbstractOAuthEngine.h + src/oauth/NonceGenerator.h + src/oauth/Utils.h) set(SOURCES - src/globals.cpp - src/exceptions.cpp - src/http.cpp - src/services_nongenerated.cpp src/AsyncResult.cpp - src/EverCloudException.cpp + src/AsyncResult_p.cpp + src/DurableService.cpp src/EventLoopFinisher.cpp - src/thumbnail.cpp + src/EverCloudException.cpp + src/Exceptions.cpp + src/Globals.cpp + src/Http.cpp + src/HttpRequestParser.cpp + src/HttpUtils.cpp src/InkNoteImageDownloader.cpp - src/generated/constants.cpp - src/generated/services.cpp - src/generated/types.cpp) + src/Log.cpp + src/Printable.cpp + src/RequestContext.cpp + src/Thumbnail.cpp + src/VersionInfo.cpp + src/generated/Constants.cpp + src/generated/EDAMErrorCode.cpp + src/generated/Services.cpp + src/generated/Servers.cpp + src/generated/Types.cpp + src/oauth/AbstractOAuthEngine.cpp + src/oauth/NonceGenerator.cpp + src/oauth/Utils.cpp) + +set(${PROJECT_NAME}_TR_SOURCES + ${PUBLIC_HEADERS} + ${NON_GENERATED_HEADERS} + ${GENERATED_HEADERS} + ${PRIVATE_HEADERS} + ${SOURCES} + src/oauth/OAuthWebEngine.h + src/oauth/OAuthWebEngine.cpp + src/oauth/OAuthWebKit.h + src/oauth/OAuthWebKit.cpp + src/oauth/OAuthSystemBrowser.h + src/oauth/OAuthSystemBrowser.cpp + src/oauth/OAuth.cpp) if(BUILD_WITH_OAUTH_SUPPORT) + if(QEVERCLOUD_USE_QT_WEB_ENGINE) + list(APPEND PRIVATE_HEADERS + src/oauth/OAuthWebEngine.h) + + list(APPEND SOURCES + src/oauth/NetworkCookieJar.cpp + src/oauth/OAuthWebEngine.cpp) + elseif(QEVERCLOUD_USE_SYSTEM_BROWSER) + list(APPEND PRIVATE_HEADERS + src/oauth/OAuthSystemBrowser.h) + + list(APPEND SOURCES + src/oauth/OAuthSystemBrowser.cpp) + else() + list(APPEND PRIVATE_HEADERS + src/oauth/OAuthWebKit.h) + + list(APPEND SOURCES + src/oauth/OAuthWebKit.cpp) + endif() + list(APPEND SOURCES - src/oauth.cpp) + src/oauth/OAuth.cpp) endif() set(ALL_HEADERS_AND_SOURCES ${PUBLIC_HEADERS}) @@ -67,31 +127,114 @@ list(APPEND ALL_HEADERS_AND_SOURCES ${GENERATED_HEADERS}) list(APPEND ALL_HEADERS_AND_SOURCES ${PRIVATE_HEADERS}) list(APPEND ALL_HEADERS_AND_SOURCES ${SOURCES}) +set(${PROJECT_NAME}_TR_FILES + QEverCloud/translations/QEverCloud_ru_RU.ts) + +set(${PROJECT_NAME}_QM_FILES "") +update_translation("${${PROJECT_NAME}_TR_SOURCES}" "${${PROJECT_NAME}_TR_FILES}") + if(BUILD_WITH_OAUTH_SUPPORT) set(QEVERCLOUD_HAS_OAUTH "#define QEVERCLOUD_HAS_OAUTH 1") else() set(QEVERCLOUD_HAS_OAUTH "#define QEVERCLOUD_HAS_OAUTH 0") endif() +if(QEVERCLOUD_USE_QT_WEB_ENGINE EQUAL QEVERCLOUD_USE_SYSTEM_BROWSER) + message(FATAL_ERROR "QEverCloud can be built either with QtWebKit or QtWebEngine or system browser backend for OAuth") +endif() + if(QEVERCLOUD_USE_QT_WEB_ENGINE) set(QEVERCLOUD_USES_QT_WEB_ENGINE "#define QEVERCLOUD_USE_QT_WEB_ENGINE 1") else() set(QEVERCLOUD_USES_QT_WEB_ENGINE "#define QEVERCLOUD_USE_QT_WEB_ENGINE 0") endif() +if(QEVERCLOUD_USE_SYSTEM_BROWSER) + set(QEVERCLOUD_USES_SYSTEM_BROWSER "#define QEVERCLOUD_USE_SYSTEM_BROWSER 1") +else() + set(QEVERCLOUD_USES_SYSTEM_BROWSER "#define QEVERCLOUD_USE_SYSTEM_BROWSER 0") +endif() + +if(BUILD_WITH_Q_NAMESPACE) + set(QEVERCLOUD_USES_Q_NAMESPACE "#define QEVERCLOUD_USES_Q_NAMESPACE 1") +else() + set(QEVERCLOUD_USES_Q_NAMESPACE "#define QEVERCLOUD_USES_Q_NAMESPACE 0") +endif() + +set(QEVERCLOUD_VERSION_MAJOR_DEFINE "#define QEVERCLOUD_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}") +set(QEVERCLOUD_VERSION_MINOR_DEFINE "#define QEVERCLOUD_VERSION_MINOR ${PROJECT_VERSION_MINOR}") +set(QEVERCLOUD_VERSION_PATCH_DEFINE "#define QEVERCLOUD_VERSION_PATCH ${PROJECT_VERSION_PATCH}") + +if(NOT QEVERCLOUD_BUILD_INFO) + find_package(Git) + if(GIT_FOUND) + message(STATUS "Git found: ${GIT_EXECUTABLE}") + + # Get git branch + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE QEVERCLOUD_GIT_BRANCH + RESULT_VARIABLE QEVERCLOUD_GIT_BRANCH_RETURN_CODE + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT "${QEVERCLOUD_GIT_BRANCH_RETURN_CODE}" STREQUAL "0") + message(AUTHOR_WARNING "Failed to determine the current git branch, return code ${QEVERCLOUD_GIT_BRANCH_RETURN_CODE}") + set(QEVERCLOUD_GIT_BRANCH "unknown branch") + else() + if(${QEVERCLOUD_GIT_BRANCH} STREQUAL "HEAD") + # Can happen if running on detached HEAD, can happen in CI jobs; workaround: try to get the current branch from environment variables + set(APPVEYOR_REPO_BRANCH "$ENV{APPVEYOR_REPO_BRANCH}") + set(TRAVIS_BRANCH "$ENV{TRAVIS_BRANCH}") + if(NOT "${APPVEYOR_REPO_BRANCH}" STREQUAL "") + set(QEVERCLOUD_GIT_BRANCH "${APPVEYOR_REPO_BRANCH}") + elseif(NOT "${TRAVIS_BRANCH}" STREQUAL "") + set(QEVERCLOUD_GIT_BRANCH "${TRAVIS_BRANCH}") + endif() + endif() + message(STATUS "Git branch: ${QEVERCLOUD_GIT_BRANCH}") + endif() + + # Get last commit short hash + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE QEVERCLOUD_GIT_REVISION + RESULT_VARIABLE QEVERCLOUD_GIT_REVISION_RETURN_CODE + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT "${QEVERCLOUD_GIT_REVISION_RETURN_CODE}" STREQUAL "0") + message(AUTHOR_WARNING "Failed to determine the current git revision") + set(QEVERCLOUD_GIT_REVISION "unknown revision") + else() + message(STATUS "Last commit short hash: ${QEVERCLOUD_GIT_REVISION}") + endif() + + # Check for uncommitted changes + execute_process(COMMAND ${GIT_EXECUTABLE} diff-index --quiet HEAD -- + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + RESULT_VARIABLE QEVERCLOUD_GIT_DIRTY_STATE) + if(NOT "${QEVERCLOUD_GIT_DIRTY_STATE}" STREQUAL "0") + set(QEVERCLOUD_GIT_REVISION "${QEVERCLOUD_GIT_REVISION}, with uncommitted changes") + endif() + + set(QEVERCLOUD_BUILD_INFO "#define QEVERCLOUD_BUILD_INFO \"${QEVERCLOUD_GIT_BRANCH}, ${QEVERCLOUD_GIT_REVISION}\"") + else() + set(QEVERCLOUD_BUILD_INFO "#define QEVERCLOUD_BUILD_INFO \"unknown\"") + endif() +else() + set(QEVERCLOUD_BUILD_INFO "#define QEVERCLOUD_BUILD_INFO \"${QEVERCLOUD_BUILD_INFO}\"") +endif() + configure_file(headers/VersionInfo.h.in ${PROJECT_BINARY_DIR}/VersionInfo.h @ONLY) list(APPEND ALL_HEADERS_AND_SOURCES ${PROJECT_BINARY_DIR}/VersionInfo.h) include_directories(${PROJECT_BINARY_DIR}) -set(LIBNAME "${QEVERCLOUD_LIBNAME_PREFIX}${QEVERCLOUD_QT_VERSION}qevercloud${QEVERCLOUD_LIBNAME_SUFFIX}") +set(LIBNAME "${QEVERCLOUD_LIBNAME_PREFIX}${QEVERCLOUD_QT_VERSION}qevercloud") if(BUILD_SHARED) - add_definitions("-DQEVERCLOUD_SHARED_LIBRARY") add_library(${LIBNAME} SHARED ${ALL_HEADERS_AND_SOURCES}) + target_compile_definitions(${LIBNAME} PRIVATE "-DQEVERCLOUD_SHARED_LIBRARY") else() - add_definitions("-DQEVERCLOUD_STATIC_LIBRARY") add_library(${LIBNAME} STATIC ${ALL_HEADERS_AND_SOURCES}) + target_compile_definitions(${LIBNAME} PRIVATE "-DQEVERCLOUD_STATIC_LIBRARY") endif() add_sanitizers(${LIBNAME}) @@ -99,38 +242,63 @@ add_sanitizers(${LIBNAME}) set_target_properties(${LIBNAME} PROPERTIES VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" SOVERSION ${PROJECT_VERSION_MAJOR} - MACOSX_RPATH 1 - INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + CXX_STANDARD 14 + CXX_EXTENSIONS OFF + MACOSX_RPATH 1) -target_link_libraries(${LIBNAME} ${QT_LIBRARIES}) +target_compile_features(${LIBNAME} INTERFACE + cxx_auto_type + cxx_defaulted_functions + cxx_defaulted_move_initializers + cxx_deleted_functions + cxx_noexcept + cxx_nullptr + cxx_override + cxx_right_angle_brackets + cxx_rvalue_references + cxx_strong_enums) -if(BUILD_WITH_QT4) - # NOTE: working around what seems to be a CMake bug - target_link_libraries(${LIBNAME} Qt4::QtWebKit) -endif() +target_compile_features(${LIBNAME} PRIVATE + cxx_final + cxx_lambdas + cxx_range_for) + +target_link_libraries(${LIBNAME} ${QT_LIBRARIES}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/headers) add_definitions("-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT") # Tests -if(BUILD_WITH_QT4) - find_package(QT4 COMPONENTS QTCORE QTTEST QUIET) -else() - find_package(Qt5Test QUIET) -endif() - -if((NOT BUILD_WITH_QT4 AND Qt5Test_FOUND) OR (BUILD_WITH_QT4 AND Qt4_FOUND)) +find_package(Qt5Test QUIET) +if(Qt5Test_FOUND) + set(TEST_HEADERS + src/HttpRequestData.h + src/HttpRequestParser.h + src/HttpUtils.h + src/tests/MessageHandler.h + src/tests/TestDurableService.h + src/tests/TestOptional.h + src/tests/generated/RandomDataGenerators.h + src/tests/generated/TestNoteStore.h + src/tests/generated/TestUserStore.h) set(TEST_SOURCES - src/tests/TestQEverCloud.cpp) - add_executable(test_${PROJECT_NAME} ${TEST_SOURCES}) + src/HttpRequestParser.cpp + src/HttpUtils.cpp + src/tests/MessageHandler.cpp + src/tests/TestDurableService.cpp + src/tests/TestOptional.cpp + src/tests/TestQEverCloud.cpp + src/tests/generated/RandomDataGenerators.cpp + src/tests/generated/TestNoteStore.cpp + src/tests/generated/TestUserStore.cpp) + add_executable(test_${PROJECT_NAME} ${TEST_HEADERS} ${TEST_SOURCES}) add_sanitizers(test_${PROJECT_NAME}) add_test(test_${PROJECT_NAME} test_${PROJECT_NAME}) - if(BUILD_WITH_QT4) - target_link_libraries(test_${PROJECT_NAME} ${LIBNAME} Qt4::QtCore Qt4::QtGui Qt4::QtNetwork Qt4::QtWebKit Qt4::QtTest) - else() - target_link_libraries(test_${PROJECT_NAME} ${LIBNAME} ${QT_LIBRARIES} Qt5::Test) - endif() + set_target_properties(test_${PROJECT_NAME} PROPERTIES + CXX_STANDARD 14 + CXX_EXTENSIONS OFF) + target_link_libraries(test_${PROJECT_NAME} ${LIBNAME} ${QT_LIBRARIES} Qt5::Test) else() message(STATUS "Haven't found Qt components required for building and running the unit tests") endif() @@ -143,9 +311,6 @@ install(TARGETS ${LIBNAME} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) set(DEV_HEADERS_FOLDER_NAME ${QEVERCLOUD_QT_VERSION}qevercloud) -if(MAJOR_VERSION_DEV_HEADERS_FOLDER_NAME_SUFFIX) - string(CONCAT DEV_HEADERS_FOLDER_NAME ${DEV_HEADERS_FOLDER_NAME} ${PROJECT_VERSION_MAJOR}) -endif() # install public headers foreach(ITEM ${PUBLIC_HEADERS}) @@ -163,6 +328,18 @@ endforeach() # install VersionInfo.h header install(FILES ${PROJECT_BINARY_DIR}/VersionInfo.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${DEV_HEADERS_FOLDER_NAME}) +# install translations +foreach(QM_FILE ${${PROJECT_NAME}_QM_FILES}) + install(CODE " + set(QM_FILE \"${QM_FILE})\") + if(EXISTS \"${QM_FILE}\") + get_filename_component(QM_FILE_BASE_NAME \"${QM_FILE}\" NAME) + message(STATUS \"Installing: \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_TRANSLATIONSDIR}/\${QM_FILE_BASE_NAME}\") + file(COPY \"${QM_FILE}\" DESTINATION \"\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_TRANSLATIONSDIR}\") + endif() + " COMPONENT Runtime) +endforeach() + # install cmake module if(BUILD_SHARED) install(EXPORT QEverCloud-${QEVERCLOUD_QT_VERSION}LibraryDepends DESTINATION ${INSTALL_CMAKE_DIR}) diff --git a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudCompilerSettings.cmake b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudCompilerSettings.cmake index 88f41b30..d6832679 100644 --- a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudCompilerSettings.cmake +++ b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudCompilerSettings.cmake @@ -1,22 +1,15 @@ if(CMAKE_COMPILER_IS_GNUCXX) execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) message(STATUS "Using GNU C++ compiler, version ${GCC_VERSION}") - if(GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8) - message(STATUS "This version of GNU C++ compiler supports C++11 standard.") - set(CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}") - add_definitions("-DCPP11_COMPLIANT=1") - if(GCC_VERSION VERSION_GREATER 8.0 OR GCC_VERSION VERSION_EQUAL 8.0) - if(GCC_VERSION VERSION_LESS 8.2) - # NOTE: workaround for a problem similar to https://issues.apache.org/jira/browse/THRIFT-4584 - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-tree-vrp -fno-inline -fno-tree-fre") - set(CMAKE_C_FLAGS_RELEASE "-g -O0") - set(CMAKE_CXX_FLAGS_RELEASE "-g -O0") - set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O0") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O0") - endif() + if(GCC_VERSION VERSION_GREATER 8.0 OR GCC_VERSION VERSION_EQUAL 8.0) + if(GCC_VERSION VERSION_LESS 8.2) + # NOTE: workaround for a problem similar to https://issues.apache.org/jira/browse/THRIFT-4584 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-tree-vrp -fno-inline -fno-tree-fre") + set(CMAKE_C_FLAGS_RELEASE "-g -O0") + set(CMAKE_CXX_FLAGS_RELEASE "-g -O0") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O0") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O0") endif() - elseif(NOT GCC_VERSION VERSION_LESS 4.4) - set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}") endif() if(BUILD_SHARED) set(CMAKE_CXX_FLAGS "-fvisibility=hidden ${CMAKE_CXX_FLAGS}") @@ -30,15 +23,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE CLANG_VERSION) message(STATUS "Using LLVM/Clang C++ compiler, version info: ${CLANG_VERSION}") - if(NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.1) - message(STATUS "Your compiler supports C++11 standard.") - add_definitions("-DCPP11_COMPLIANT=1") - else() - message(WARNING "Your compiler may not support all the necessary C++11 standard features - to build this project. If you'd get any compilation errors, consider - upgrading to a compiler version which fully supports the C++11 standard.") - endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR USE_LIBCPP) find_library(LIBCPP NAMES libc++.so libc++.so.1.0 libc++.dylib OPTIONAL) if(LIBCPP) @@ -49,5 +34,5 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") endif() elseif(MSVC) message(STATUS "Using VC++ compiler: ${CMAKE_CXX_COMPILER_VERSION}") - set(CMAKE_CXX_FLAGS "-D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS") endif() diff --git a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudConfig.cmake.in b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudConfig.cmake.in index b2016208..8d9a1ed0 100644 --- a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudConfig.cmake.in +++ b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudConfig.cmake.in @@ -5,26 +5,58 @@ # QEVERCLOUD_LIBRARIES - The libraries needed to use QEverCloud # QEVERCLOUD_HAS_OAUTH - Boolean set to true if QEverCloud was built with OAuth support # QEVERCLOUD_USE_QT_WEB_ENGINE - Boolean set to true if QEverCloud was built with OAuth support using QtWebEngine backend +# QEVERCLOUD_USE_SYSTEM_BROWSER - Boolean set to true if QEverCloud was built with OAuth support using system browser # Compute paths -get_filename_component(QEVERCLOUD_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -if(EXISTS "${QEVERCLOUD_CMAKE_DIR}/CMakeCache.txt") +if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/CMakeCache.txt") # in build tree - include("${QEVERCLOUD_CMAKE_DIR}/QEverCloud-@QEVERCLOUD_QT_VERSION@BuildTreeSettings.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/QEverCloud-@QEVERCLOUD_QT_VERSION@BuildTreeSettings.cmake") else() - set(QEVERCLOUD_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@") + function(_qevercloud_find_prefix_dir _qevercloud_prefix_dir) + set(current_dir "${CMAKE_CURRENT_LIST_DIR}") + set(parent_dir "") + while(1) + get_filename_component(parent_dir ${current_dir} DIRECTORY) + if ("${parent_dir}" STREQUAL "${current_dir}") + break() + endif() + + set(parent_dir_len "0") + string(LENGTH "${parent_dir}" parent_dir_len) + if ("${parent_dir_len}" STREQUAL "0") + break() + endif() + + if(EXISTS "${parent_dir}/@CMAKE_INSTALL_INCLUDEDIR@/qt5qevercloud/QEverCloud.h") + set(_qevercloud_prefix_dir "${parent_dir}" PARENT_SCOPE) + return() + endif() + + set(current_dir "${parent_dir}") + endwhile() + endfunction() + + set(_qevercloud_prefix_dir "") + _qevercloud_find_prefix_dir(_qevercloud_prefix_dir) + + if (_qevercloud_prefix_dir) + set(QEVERCLOUD_INCLUDE_DIRS "${_qevercloud_prefix_dir}/@CMAKE_INSTALL_INCLUDEDIR@") + else() + message(FATAL_ERROR "Failed to find QEverCloud prefix dir") + endif() endif() # Find the QEverCloud's Qt dependencies -include("${QEVERCLOUD_CMAKE_DIR}/QEverCloudFindPackageWrapperMacro.cmake") -include("${QEVERCLOUD_CMAKE_DIR}/QEverCloud-@QEVERCLOUD_QT_VERSION@FindQtDependencies.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/QEverCloudFindPackageWrapperMacro.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/QEverCloud-@QEVERCLOUD_QT_VERSION@FindQtDependencies.cmake") # Our library dependencies (contains definitions for IMPORTED targets) -include("${QEVERCLOUD_CMAKE_DIR}/QEverCloud-@QEVERCLOUD_QT_VERSION@LibraryDepends.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/QEverCloud-@QEVERCLOUD_QT_VERSION@LibraryDepends.cmake") # These are IMPORTED targets created by FooBarLibraryDepends.cmake set(QEVERCLOUD_LIBRARIES "@QEVERCLOUD_LIBNAME_PREFIX@@QEVERCLOUD_QT_VERSION@qevercloud@QEVERCLOUD_LIBNAME_SUFFIX@") @QEVERCLOUD_HAS_OAUTH@ @QEVERCLOUD_USES_QT_WEB_ENGINE@ +@QEVERCLOUD_USES_SYSTEM_BROWSER@ set(QEVERCLOUD_FOUND TRUE) diff --git a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt4Dependencies.cmake b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt4Dependencies.cmake deleted file mode 100644 index 4c145084..00000000 --- a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt4Dependencies.cmake +++ /dev/null @@ -1,9 +0,0 @@ -find_package(Qt4 COMPONENTS QTCORE QTGUI QTNETWORK QUIET REQUIRED) - -include(${QT_USE_FILE}) - -# Workaround what seems to be a CMake 3.x bug with Qt4 libraries -list(FIND QT_LIBRARIES "${QT_QTGUI_LIBRARY}" HasGui) -if(HasGui EQUAL -1) - list(APPEND QT_LIBRARIES ${QT_QTGUI_LIBRARY}) -endif() diff --git a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt4DependenciesWithWebKit.cmake b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt4DependenciesWithWebKit.cmake deleted file mode 100644 index c0da4281..00000000 --- a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt4DependenciesWithWebKit.cmake +++ /dev/null @@ -1,9 +0,0 @@ -find_package(Qt4 COMPONENTS QTCORE QTGUI QTNETWORK QTWEBKIT QUIET REQUIRED) - -include(${QT_USE_FILE}) - -# Workaround what seems to be a CMake 3.x bug with Qt4 libraries -list(FIND QT_LIBRARIES "${QT_QTGUI_LIBRARY}" HasGui) -if(HasGui EQUAL -1) - list(APPEND QT_LIBRARIES ${QT_QTGUI_LIBRARY}) -endif() diff --git a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesTranslations.cmake b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesTranslations.cmake new file mode 100644 index 00000000..48b7d785 --- /dev/null +++ b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesTranslations.cmake @@ -0,0 +1 @@ +QEverCloudFindPackageWrapper(Qt5LinguistTools ${QEVERCLOUD_FIND_PACKAGE_ARG}) diff --git a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesWebEngineNoCore.cmake b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesWebEngineNoCore.cmake deleted file mode 100644 index 0cf3d301..00000000 --- a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudFindQt5DependenciesWebEngineNoCore.cmake +++ /dev/null @@ -1,2 +0,0 @@ -QEverCloudFindPackageWrapper(Qt5WebEngine ${QEVERCLOUD_FIND_PACKAGE_ARG}) -QEverCloudFindPackageWrapper(Qt5WebEngineWidgets ${QEVERCLOUD_FIND_PACKAGE_ARG}) diff --git a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudSetupQt.cmake b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudSetupQt.cmake index a71df648..753b0580 100644 --- a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudSetupQt.cmake +++ b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudSetupQt.cmake @@ -1,54 +1,81 @@ -if(NOT BUILD_WITH_QT4) - set(QEVERCLOUD_FIND_PACKAGE_ARG "VERBOSE") - - find_package(Qt5Core QUIET REQUIRED) - message(STATUS "Found Qt5 installation, version ${Qt5Core_VERSION}") - - include(QEverCloudFindPackageWrapperMacro) - include(QEverCloudFindQt5DependenciesCore) - - list(APPEND QT_INCLUDES ${Qt5Core_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) - list(APPEND QT_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Widgets_LIBRARIES}) - list(APPEND QT_DEFINITIONS ${Qt5Core_DEFINITIONS} ${Qt5Network_DEFINITIONS} ${Qt5Widgets_DEFINITIONS}) - - if(BUILD_WITH_OAUTH_SUPPORT) - if(USE_QT5_WEBKIT OR (Qt5Core_VERSION VERSION_LESS "5.4.0")) - include(QEverCloudFindQt5DependenciesWebKit) - elseif(Qt5Core_VERSION VERSION_LESS "5.6.0") - include(QEverCloudFindQt5DependenciesWebEngineNoCore) - set(QEVERCLOUD_USE_QT_WEB_ENGINE TRUE) - else() - include(QEverCloudFindQt5DependenciesWebEngineCore) - set(QEVERCLOUD_USE_QT_WEB_ENGINE TRUE) - endif() - - if(QEVERCLOUD_USE_QT_WEB_ENGINE) - add_definitions(-DQEVERCLOUD_USE_QT_WEB_ENGINE) - endif() - - if(USE_QT5_WEBKIT OR (Qt5Core_VERSION VERSION_LESS "5.4.0")) - list(APPEND QT_INCLUDES ${QT_INCLUDES} ${Qt5WebKit_INCLUDE_DIRS} ${Qt5WebKitWidgets_INCLUDE_DIRS}) - list(APPEND QT_LIBRARIES ${QT_LIBRARIES} ${Qt5WebKit_LIBRARIES} ${Qt5WebKitWidgets_LIBRARIES}) - list(APPEND QT_DEFINITIONS ${QT_DEFINITIONS} ${Qt5WebKit_DEFINITIONS} ${Qt5WebKitWidgets_DEFINITIONS}) - else() - if(Qt5WebEngine_VERSION VERSION_LESS "5.6.0") - list(APPEND QT_INCLUDES ${QT_INCLUDES} ${Qt5WebEngine_INCLUDE_DIRS} ${Qt5WebEngineWidgets_INCLUDE_DIRS}) - list(APPEND QT_LIBRARIES ${QT_LIBRARIES} ${Qt5WebEngine_LIBRARIES} ${Qt5WebEngineWidgets_LIBRARIES}) - list(APPEND QT_DEFINITIONS ${QT_DEFINITIONS} ${Qt5WebEngine_DEFINITIONS} ${Qt5WebEngineWidgets_DEFINITIONS}) - else() - list(APPEND QT_INCLUDES ${QT_INCLUDES} ${Qt5WebEngineCore_INCLUDE_DIRS}) - list(APPEND QT_LIBRARIES ${QT_LIBRARIES} ${Qt5WebEngineCore_LIBRARIES}) - list(APPEND QT_DEFINITIONS ${QT_DEFINITIONS} ${Qt5WebEngineCore_DEFINITIONS}) - endif() - endif() - endif(BUILD_WITH_OAUTH_SUPPORT) -else() - find_package(Qt4 COMPONENTS QTCORE QUIET REQUIRED) - message(STATUS "Found Qt4 installation, version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}") - if(BUILD_WITH_OAUTH_SUPPORT) - include(QEverCloudFindQt4DependenciesWithWebKit) +set(QEVERCLOUD_FIND_PACKAGE_ARG "VERBOSE") + +find_package(Qt5Core 5.5 REQUIRED) +message(STATUS "Found Qt5 installation, version ${Qt5Core_VERSION}") + +include(QEverCloudFindPackageWrapperMacro) +include(QEverCloudFindQt5DependenciesCore) + +list(APPEND QT_INCLUDES + ${Qt5Core_INCLUDE_DIRS} + ${Qt5Network_INCLUDE_DIRS} + ${Qt5Widgets_INCLUDE_DIRS}) + +list(APPEND QT_LIBRARIES + ${Qt5Core_LIBRARIES} + ${Qt5Network_LIBRARIES} + ${Qt5Widgets_LIBRARIES}) + +list(APPEND QT_DEFINITIONS + ${Qt5Core_DEFINITIONS} + ${Qt5Network_DEFINITIONS} + ${Qt5Widgets_DEFINITIONS}) + +if(BUILD_TRANSLATIONS) + include(QEverCloudFindQt5DependenciesTranslations) + + list(APPEND QT_INCLUDES + ${Qt5LinguistTools_INCLUDE_DIRS}) + + list(APPEND QT_LIBRARIES + ${Qt5LinguistTools_LIBRARIES}) + + list(APPEND QT_DEFINITIONS + ${Qt5LinguistTools_DEFINITIONS}) +endif() + +if(BUILD_WITH_OAUTH_SUPPORT AND NOT QEVERCLOUD_USE_SYSTEM_BROWSER) + if(USE_QT5_WEBKIT OR Qt5Core_VERSION VERSION_LESS "5.6.0") + include(QEverCloudFindQt5DependenciesWebKit) + else() + include(QEverCloudFindQt5DependenciesWebEngineCore) + set(QEVERCLOUD_USE_QT_WEB_ENGINE TRUE) + endif() + + if(QEVERCLOUD_USE_QT_WEB_ENGINE) + add_definitions(-DQEVERCLOUD_USE_QT_WEB_ENGINE) + endif() + + if(USE_QT5_WEBKIT) + list(APPEND QT_INCLUDES + ${QT_INCLUDES} + ${Qt5WebKit_INCLUDE_DIRS} + ${Qt5WebKitWidgets_INCLUDE_DIRS}) + + list(APPEND QT_LIBRARIES + ${QT_LIBRARIES} + ${Qt5WebKit_LIBRARIES} + ${Qt5WebKitWidgets_LIBRARIES}) + + list(APPEND QT_DEFINITIONS + ${QT_DEFINITIONS} + ${Qt5WebKit_DEFINITIONS} + ${Qt5WebKitWidgets_DEFINITIONS}) else() - include(QEverCloudFindQt4Dependencies) + list(APPEND QT_INCLUDES + ${QT_INCLUDES} + ${Qt5WebEngineCore_INCLUDE_DIRS} + ${Qt5WebEngineWidgets_INCLUDE_DIRS}) + + list(APPEND QT_LIBRARIES + ${QT_LIBRARIES} + ${Qt5WebEngineCore_LIBRARIES} + ${Qt5WebEngineWidgets_LIBRARIES}) + + list(APPEND QT_DEFINITIONS + ${QT_DEFINITIONS} + ${Qt5WebEngineCore_DEFINITIONS} + ${Qt5WebEngineWidgets_DEFINITIONS}) endif() endif() diff --git a/src/qevercloud/QEverCloud/cmake/modules/QEverCloudUpdateTranslations.cmake b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudUpdateTranslations.cmake new file mode 100644 index 00000000..43b22ecd --- /dev/null +++ b/src/qevercloud/QEverCloud/cmake/modules/QEverCloudUpdateTranslations.cmake @@ -0,0 +1,53 @@ +macro(update_translation SOURCES TRANSLATIONS) + # First generate the fake .pro file for lupdate utility + set(fake_pro_file "${PROJECT_BINARY_DIR}/fake_pro_file.pro") + + # generate .pro file for lupdate utility + file(WRITE "${fake_pro_file}" + "#\n" + "# This file was autogenerated by update_translation macro\n" + "# All changes will be lost\n" + "#\n") + + # INCLUDEPATH section + file(APPEND "${fake_pro_file}" + "\n" + "INCLUDEPATH += ${PROJECT_SOURCE_DIR}/QEverCloud/headers\n") + + # SOURCES section + file(APPEND "${fake_pro_file}" + "\n" + "SOURCES =\\\n") + + foreach(source_file ${SOURCES}) + file(APPEND "${fake_pro_file}" " ${PROJECT_SOURCE_DIR}/QEverCloud/${source_file}\\\n") + endforeach() + + # TRANSLATIONS section + file(APPEND "${fake_pro_file}" + "\n" + "TRANSLATIONS =\\\n") + + foreach(translation_file ${TRANSLATIONS}) + file(APPEND "${fake_pro_file}" " ${PROJECT_SOURCE_DIR}/${translation_file}\\\n") + endforeach() + + file(APPEND "${fake_pro_file}" + "\n") + + set(LUPDATE ${Qt5_LUPDATE_EXECUTABLE}) + set(LRELEASE ${Qt5_LRELEASE_EXECUTABLE}) + + add_custom_target(lupdate COMMAND ${LUPDATE} -verbose -noobsolete \"${fake_pro_file}\" DEPENDS ${fake_pro_file}) + + add_custom_target(lrelease) + file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/QEverCloud/translations") + foreach(translation_file ${TRANSLATIONS}) + string(FIND ${translation_file} "." DOT_POS) + string(SUBSTRING ${translation_file} 0 ${DOT_POS} QM_FILE_NAME) + # NOTE: "translations/" is already included into QM_FILE_NAME + set(QM_FILE "${PROJECT_BINARY_DIR}/${QM_FILE_NAME}.qm") + list(APPEND ${PROJECT_NAME}_QM_FILES ${QM_FILE}) + add_custom_command(COMMAND ${LRELEASE} ${PROJECT_SOURCE_DIR}/${translation_file} -qm \"${QM_FILE}\" TARGET lrelease) + endforeach() +endmacro() diff --git a/src/qevercloud/QEverCloud/headers/AsyncResult.h b/src/qevercloud/QEverCloud/headers/AsyncResult.h index c9e885ff..c656226e 100644 --- a/src/qevercloud/QEverCloud/headers/AsyncResult.h +++ b/src/qevercloud/QEverCloud/headers/AsyncResult.h @@ -1,23 +1,27 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT */ #ifndef QEVERCLOUD_ASYNC_RESULT_H #define QEVERCLOUD_ASYNC_RESULT_H -#include "qt4helpers.h" -#include "export.h" #include "EverCloudException.h" -#include +#include "Export.h" +#include "Helpers.h" +#include "RequestContext.h" + #include +#include +#include namespace qevercloud { QT_FORWARD_DECLARE_CLASS(AsyncResultPrivate) +QT_FORWARD_DECLARE_CLASS(DurableService) /** * @brief Returned by asynchonous versions of functions. @@ -30,36 +34,53 @@ QT_FORWARD_DECLARE_CLASS(AsyncResultPrivate) NoteStore* ns; Note note; ... -QObject::connect(ns->createNoteAsync(note), &AsyncResult::finished, [ns](QVariant result, QSharedPointer error) { - if(!error.isNull()) { - // do something in case of an error - } else { - Note note = result.value(); - // process returned result - } -}); +QObject::connect(ns->createNoteAsync(note), &AsyncResult::finished, + [ns]( + QVariant result, + EverCloudExceptionDataPtr error, + IRequestContextPtr ctx) + { + if (error) { + // do something in case of an error + } + else { + Note note = result.value(); + // process returned result + } + }); @endcode */ class QEVERCLOUD_EXPORT AsyncResult: public QObject { Q_OBJECT Q_DISABLE_COPY(AsyncResult) -private: +public: static QVariant asIs(QByteArray replyData); -public: typedef QVariant (*ReadFunctionType)(QByteArray replyData); - AsyncResult(QString url, QByteArray postData, ReadFunctionType readFunction = AsyncResult::asIs, - bool autoDelete = true, QObject * parent = Q_NULLPTR); + AsyncResult(QString url, QByteArray postData, + IRequestContextPtr ctx, + ReadFunctionType readFunction = AsyncResult::asIs, + bool autoDelete = true, QObject * parent = nullptr); - AsyncResult(QNetworkRequest request, QByteArray postData, ReadFunctionType readFunction = AsyncResult::asIs, - bool autoDelete = true, QObject * parent = Q_NULLPTR); + AsyncResult(QNetworkRequest request, QByteArray postData, + IRequestContextPtr ctx, + ReadFunctionType readFunction = AsyncResult::asIs, + bool autoDelete = true, QObject * parent = nullptr); + + /** + * Constructor accepting already prepared value and/or exception, + * for use in tests + */ + AsyncResult(QVariant result, EverCloudExceptionDataPtr error, + IRequestContextPtr ctx, bool autoDelete = true, + QObject * parent = nullptr); ~AsyncResult(); /** - * @brief Wait for asyncronous operation to complete. + * @brief Wait for asynchronous operation to complete. * @param timeout * Maximum time to wait in milliseconds. Forever if < 0. * @return true if finished successfully, false in case of the timeout @@ -68,18 +89,23 @@ class QEVERCLOUD_EXPORT AsyncResult: public QObject Q_SIGNALS: /** - * @brief Emitted upon asyncronous call completition. - * @param result - * @param error - * error.isNull() != true in case of an error. See EverCloudExceptionData for more details. + * @brief Emitted upon asynchronous call completition. + * @param result Request result + * @param error Non-nullptr in case of an error. See + * EverCloudExceptionData for more details + * @param ctx Request context used to make the request * - * AsyncResult deletes itself after emitting this signal. You don't have to manage it's lifetime explicitly. + * AsyncResult deletes itself after emitting this signal (if autoDelete + * parameter passed to its constructor was set to true). You don't have to + * manage it's lifetime explicitly. */ - void finished(QVariant result, QSharedPointer error); + void finished( + QVariant result, + EverCloudExceptionDataPtr error, + IRequestContextPtr ctx); -private Q_SLOTS: - void onReplyFetched(QObject * rp); - void start(); +private: + friend class DurableService; private: AsyncResultPrivate * const d_ptr; diff --git a/src/qevercloud/QEverCloud/headers/DurableService.h b/src/qevercloud/QEverCloud/headers/DurableService.h new file mode 100644 index 00000000..6d1dca7b --- /dev/null +++ b/src/qevercloud/QEverCloud/headers/DurableService.h @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_DURABLE_SERVICE_H +#define QEVERCLOUD_DURABLE_SERVICE_H + +#include "AsyncResult.h" +#include "Export.h" +#include "RequestContext.h" + +#include +#include + +#include +#include +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +struct QEVERCLOUD_EXPORT IRetryPolicy +{ + virtual bool shouldRetry( + const EverCloudExceptionDataPtr & exceptionData) = 0; +}; + +using IRetryPolicyPtr = std::shared_ptr; + +//////////////////////////////////////////////////////////////////////////////// + +QT_FORWARD_DECLARE_CLASS(DurableServicePrivate) + +class QEVERCLOUD_EXPORT IDurableService +{ +public: + using SyncResult = std::pair; + using SyncServiceCall = std::function; + using AsyncServiceCall = std::function; + + struct QEVERCLOUD_EXPORT SyncRequest + { + const char * m_name; + QString m_description; + SyncServiceCall m_call; + + SyncRequest(const char * name, QString description, + SyncServiceCall && call) : + m_name(name), + m_description(std::move(description)), + m_call(std::move(call)) + {} + }; + + struct QEVERCLOUD_EXPORT AsyncRequest + { + const char * m_name; + QString m_description; + AsyncServiceCall m_call; + + AsyncRequest(const char * name, QString description, + AsyncServiceCall && call) : + m_name(name), + m_description(std::move(description)), + m_call(std::move(call)) + {} + }; + +public: + virtual SyncResult executeSyncRequest( + SyncRequest && syncRequest, IRequestContextPtr ctx) = 0; + + virtual AsyncResult * executeAsyncRequest( + AsyncRequest && asyncRequest, IRequestContextPtr ctx) = 0; +}; + +using IDurableServicePtr = std::shared_ptr; + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT IRetryPolicyPtr newRetryPolicy(); + +QEVERCLOUD_EXPORT IRetryPolicyPtr nullRetryPolicy(); + +QEVERCLOUD_EXPORT IDurableServicePtr newDurableService( + IRetryPolicyPtr = {}, + IRequestContextPtr = {}); + +} // namespace qevercloud + +#endif // QEVERCLOUD_DURABLE_SERVICE_H diff --git a/src/qevercloud/QEverCloud/headers/EventLoopFinisher.h b/src/qevercloud/QEverCloud/headers/EventLoopFinisher.h index af8d53a0..1edd9f5a 100644 --- a/src/qevercloud/QEverCloud/headers/EventLoopFinisher.h +++ b/src/qevercloud/QEverCloud/headers/EventLoopFinisher.h @@ -1,18 +1,19 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT */ #ifndef QEVERCLOUD_EVENT_LOOP_FINISHER_H #define QEVERCLOUD_EVENT_LOOP_FINISHER_H -#include "qt4helpers.h" -#include "export.h" -#include +#include "Export.h" +#include "Helpers.h" + #include +#include namespace qevercloud { @@ -22,7 +23,9 @@ class QEVERCLOUD_EXPORT EventLoopFinisher: public QObject { Q_OBJECT public: - explicit EventLoopFinisher(QEventLoop * loop, int exitCode, QObject * parent = Q_NULLPTR); + explicit EventLoopFinisher( + QEventLoop * loop, int exitCode, QObject * parent = Q_NULLPTR); + ~EventLoopFinisher(); public Q_SLOTS: diff --git a/src/qevercloud/QEverCloud/headers/EverCloudException.h b/src/qevercloud/QEverCloud/headers/EverCloudException.h index d150cb30..ea8b0e94 100644 --- a/src/qevercloud/QEverCloud/headers/EverCloudException.h +++ b/src/qevercloud/QEverCloud/headers/EverCloudException.h @@ -1,27 +1,33 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT */ #ifndef QEVERCLOUD_EVER_CLOUD_EXCEPTION_H #define QEVERCLOUD_EVER_CLOUD_EXCEPTION_H -#include "qt4helpers.h" -#include "export.h" +#include "Export.h" +#include "Helpers.h" + #include #include -#include + #include +#include namespace qevercloud { +//////////////////////////////////////////////////////////////////////////////// + class QEVERCLOUD_EXPORT EverCloudExceptionData; +//////////////////////////////////////////////////////////////////////////////// + /** - * All exceptions throws by the library are of this class or its descendants. + * All exceptions thrown by the library are of this class or its descendants. */ class QEVERCLOUD_EXPORT EverCloudException: public std::exception { @@ -33,54 +39,90 @@ class QEVERCLOUD_EXPORT EverCloudException: public std::exception explicit EverCloudException(QString error); explicit EverCloudException(const std::string & error); explicit EverCloudException(const char * error); - ~EverCloudException() throw(); - const char * what() const throw(); + virtual ~EverCloudException() noexcept override; + + virtual const char * what() const noexcept override; - virtual QSharedPointer exceptionData() const; + virtual std::shared_ptr exceptionData() const; }; +//////////////////////////////////////////////////////////////////////////////// + /** * @brief EverCloudException counterpart for asynchronous API. * - * Asynchronous functions cannot throw exceptions so descendants of EverCloudExceptionData are retunded instead - * in case of an error. Every exception class has its own counterpart. - * The EverCloudExceptionData descendants hierarchy is a copy of the EverCloudException descendants hierarchy. + * Asynchronous functions cannot throw exceptions so descendants of + * EverCloudExceptionData are retunded instead in case of an error. Every + * exception class has its own counterpart. The EverCloudExceptionData + * descendants hierarchy is a copy of the EverCloudException descendants + * hierarchy. * - * The main reason not to use exception classes directly is that dynamic_cast does not work across module (exe, dll, etc) boundaries - * in general, while `qobject_cast` do work as expected. That's why I decided to inherit my error classes from QObject. + * The main reason not to use exception classes directly is that dynamic_cast + * does not work across module (exe, dll, etc) boundaries in general, while + * `qobject_cast` do work as expected. That's why I decided to inherit my error + * classes from QObject. * * In general error checking in asynchronous API look like this: * * @code NoteStore* ns; ... -QObject::connect(ns->getNotebook(notebookGuid), &AsyncResult::finished, [](QVariant result, QSharedPointer error) { - if(!error.isNull()) { - QSharedPointer errorNotFound = error.objectCast(); - QSharedPointer errorUser = error.objectCast(); - QSharedPointer errorSystem = error.objectCast(); - if(!errorNotFound.isNull()) { - qDebug() << "notebook not found" << errorNotFound.identifier << errorNotFound.key; - } else if(!errorUser.isNull()) { - qDebug() << errorUser.errorMessage; - } else if(!errorSystem.isNull()) { - if(errorSystem.errorCode == EDAMErrorCode::RATE_LIMIT_REACHED) { - qDebug() << "Evernote API rate limits are reached"; - } else if(errorSystem.errorCode == EDAMErrorCode::AUTH_EXPIRED) { - qDebug() << "Authorization token is inspired"; - } else { - // some other Evernote trouble - qDebug() << errorSystem.errorMessage; - } - } else { - // some unexpected error - qDebug() << error.errorMessage; - } - } else { - // success - } -}); +QObject::connect(ns->getNotebook(notebookGuid), &AsyncResult::finished, + [](QVariant result, EverCloudExceptionData error) + { + if (!error.isNull()) + { + auto errorNotFound = + std::dynamic_pointer_cast( + error); + + auto errorUser = + std::dynamic_pointer_cast( + error); + + auto errorSystem = + std::dynamic_pointer_cast( + error); + + if (!errorNotFound.isNull()) + { + qDebug() << "notebook not found" + << errorNotFound.identifier << errorNotFound.key; + } + else if (!errorUser.isNull()) + { + qDebug() << errorUser.errorMessage; + } + else if (!errorSystem.isNull()) + { + if (errorSystem.errorCode == + EDAMErrorCode::RATE_LIMIT_REACHED) + { + qDebug() << "Evernote API rate limits are reached"; + } + else if (errorSystem.errorCode == + EDAMErrorCode::AUTH_EXPIRED) + { + qDebug() << "Authorization token is inspired"; + } + else + { + // some other Evernote trouble + qDebug() << errorSystem.errorMessage; + } + } + else + { + // some unexpected error + qDebug() << error.errorMessage; + } + } + else + { + // success + } + }); @endcode */ @@ -97,15 +139,20 @@ class QEVERCLOUD_EXPORT EverCloudExceptionData: public QObject explicit EverCloudExceptionData(QString error); /** - * If you want to throw an exception that corresponds to a recrived EverCloudExceptionData - * descendant than call this function. Do not use `throw` statement, it's not polymorphic. + * If you want to throw an exception that corresponds to a received + * EverCloudExceptionData descendant than call this function. Do not use + * `throw` statement, it's not polymorphic. */ virtual void throwException() const; }; +using EverCloudExceptionDataPtr = std::shared_ptr; + +//////////////////////////////////////////////////////////////////////////////// + /** - * All exception sent by Evernote servers (as opposed to other error conditions, for example http errors) are - * descendants of this class. + * All exception sent by Evernote servers (as opposed to other error conditions, + * for example http errors) are descendants of this class. */ class QEVERCLOUD_EXPORT EvernoteException: public EverCloudException { @@ -115,17 +162,22 @@ class QEVERCLOUD_EXPORT EvernoteException: public EverCloudException explicit EvernoteException(const std::string & error); explicit EvernoteException(const char * error); - virtual QSharedPointer exceptionData() const Q_DECL_OVERRIDE; + virtual EverCloudExceptionDataPtr exceptionData() const override; }; -/** Asynchronous API conterpart of EvernoteException. See EverCloudExceptionData for more details.*/ +//////////////////////////////////////////////////////////////////////////////// + +/** + * Asynchronous API conterpart of EvernoteException. See EverCloudExceptionData + * for more details. + */ class QEVERCLOUD_EXPORT EvernoteExceptionData: public EverCloudExceptionData { Q_OBJECT Q_DISABLE_COPY(EvernoteExceptionData) public: explicit EvernoteExceptionData(QString error); - virtual void throwException() const Q_DECL_OVERRIDE; + virtual void throwException() const override; }; } // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/headers/Exceptions.h b/src/qevercloud/QEverCloud/headers/Exceptions.h new file mode 100644 index 00000000..d3a943a5 --- /dev/null +++ b/src/qevercloud/QEverCloud/headers/Exceptions.h @@ -0,0 +1,276 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_EXCEPTIONS_H +#define QEVERCLOUD_EXCEPTIONS_H + +#include "EverCloudException.h" +#include "Export.h" +#include "Optional.h" +#include "generated/EDAMErrorCode.h" +#include "generated/Types.h" + +#include +#include +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +/** + * @brief The NetworkException class represents QNetworkReply level errors. + */ +class QEVERCLOUD_EXPORT NetworkException: public EverCloudException +{ +public: + NetworkException(); + NetworkException(QNetworkReply::NetworkError error); + NetworkException(QNetworkReply::NetworkError error, QString message); + virtual ~NetworkException() noexcept override; + + bool operator==(const NetworkException & other) const; + bool operator!=(const NetworkException & other) const; + + QNetworkReply::NetworkError type() const; + + const char * what() const noexcept override; + + virtual EverCloudExceptionDataPtr exceptionData() const override; + +protected: + QNetworkReply::NetworkError m_type; +}; + +/** + * Asynchronous API counterpart of NetworkException. See EverCloudExceptionData + * for more details. + */ +class QEVERCLOUD_EXPORT NetworkExceptionData: public EverCloudExceptionData +{ + Q_OBJECT + Q_DISABLE_COPY(NetworkExceptionData) +public: + explicit NetworkExceptionData(QString error, QNetworkReply::NetworkError type); + virtual void throwException() const override; + +protected: + QNetworkReply::NetworkError m_type; +}; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Errors of the Thrift protocol level. It could be wrongly formatted parameters + * or return values for example. + */ +class QEVERCLOUD_EXPORT ThriftException: public EverCloudException +{ +public: + enum class Type { + UNKNOWN = 0, + UNKNOWN_METHOD = 1, + INVALID_MESSAGE_TYPE = 2, + WRONG_METHOD_NAME = 3, + BAD_SEQUENCE_ID = 4, + MISSING_RESULT = 5, + INTERNAL_ERROR = 6, + PROTOCOL_ERROR = 7, + INVALID_DATA = 8 + }; + + friend QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & strm, const Type type); + + ThriftException(); + ThriftException(Type type); + ThriftException(Type type, QString message); + virtual ~ThriftException() noexcept override; + + bool operator==(const ThriftException & other) const; + bool operator!=(const ThriftException & other) const; + + Type type() const; + + const char * what() const noexcept override; + + virtual EverCloudExceptionDataPtr exceptionData() const override; + +protected: + Type m_type; +}; + +/** + * Asynchronous API counterpart of ThriftException. See EverCloudExceptionData + * for more details. + */ +class QEVERCLOUD_EXPORT ThriftExceptionData: public EverCloudExceptionData +{ + Q_OBJECT + Q_DISABLE_COPY(ThriftExceptionData) +public: + explicit ThriftExceptionData(QString error, ThriftException::Type type); + virtual void throwException() const override; + +protected: + ThriftException::Type m_type; +}; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Asynchronous API counterpart of EDAMUserException. See EverCloudExceptionData + * for more details. + */ +class QEVERCLOUD_EXPORT EDAMUserExceptionData: public EvernoteExceptionData +{ + Q_OBJECT + Q_DISABLE_COPY(EDAMUserExceptionData) +public: + explicit EDAMUserExceptionData( + QString error, EDAMErrorCode errorCode, Optional parameter); + + virtual void throwException() const override; + +protected: + EDAMErrorCode m_errorCode; + Optional m_parameter; +}; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Asynchronous API counterpart of EDAMSystemException. + * See EverCloudExceptionData for more details. + */ +class QEVERCLOUD_EXPORT EDAMSystemExceptionData: public EvernoteExceptionData +{ + Q_OBJECT + Q_DISABLE_COPY(EDAMSystemExceptionData) +public: + explicit EDAMSystemExceptionData( + QString err, EDAMErrorCode errorCode, Optional message, + Optional rateLimitDuration); + + virtual void throwException() const override; + +protected: + EDAMErrorCode m_errorCode; + Optional m_message; + Optional m_rateLimitDuration; +}; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Asynchronous API counterpart of EDAMNotFoundException. + * See EverCloudExceptionData for more details. + */ +class QEVERCLOUD_EXPORT EDAMNotFoundExceptionData: public EvernoteExceptionData +{ + Q_OBJECT + Q_DISABLE_COPY(EDAMNotFoundExceptionData) +public: + explicit EDAMNotFoundExceptionData( + QString error, Optional identifier, Optional key); + + virtual void throwException() const override; + +protected: + Optional m_identifier; + Optional m_key; +}; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Asynchronous API counterpart of EDAMInvalidContactsException. + * See EverCloudExceptionData for more details. + */ +class QEVERCLOUD_EXPORT EDAMInvalidContactsExceptionData: + public EvernoteExceptionData +{ + Q_OBJECT + Q_DISABLE_COPY(EDAMInvalidContactsExceptionData) +public: + explicit EDAMInvalidContactsExceptionData( + QList contacts, Optional parameter, + Optional > reasons); + + virtual void throwException() const override; + +protected: + QList m_contacts; + Optional m_parameter; + Optional> m_reasons; +}; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * EDAMSystemException for `errorCode = RATE_LIMIT_REACHED` + */ +class QEVERCLOUD_EXPORT EDAMSystemExceptionRateLimitReached: + public EDAMSystemException +{ +public: + virtual EverCloudExceptionDataPtr exceptionData() const override; +}; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Asynchronous API counterpart of EDAMSystemExceptionRateLimitReached. + * See EverCloudExceptionData for more details. + */ +class QEVERCLOUD_EXPORT EDAMSystemExceptionRateLimitReachedData: + public EDAMSystemExceptionData +{ + Q_OBJECT + Q_DISABLE_COPY(EDAMSystemExceptionRateLimitReachedData) +public: + explicit EDAMSystemExceptionRateLimitReachedData( + QString error, EDAMErrorCode errorCode, Optional message, + Optional rateLimitDuration); + + virtual void throwException() const override; +}; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * EDAMSystemException for `errorCode = AUTH_EXPIRED` + */ +class QEVERCLOUD_EXPORT EDAMSystemExceptionAuthExpired: public EDAMSystemException +{ +public: + virtual EverCloudExceptionDataPtr exceptionData() const override; +}; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Asynchronous API counterpart of EDAMSystemExceptionAuthExpired. + * See EverCloudExceptionData for more details. + */ +class QEVERCLOUD_EXPORT EDAMSystemExceptionAuthExpiredData: + public EDAMSystemExceptionData +{ + Q_OBJECT + Q_DISABLE_COPY(EDAMSystemExceptionAuthExpiredData) +public: + explicit EDAMSystemExceptionAuthExpiredData( + QString error, EDAMErrorCode errorCode, Optional message, + Optional rateLimitDuration); + + virtual void throwException() const override; +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_EXCEPTIONS_H diff --git a/src/qevercloud/QEverCloud/headers/export.h b/src/qevercloud/QEverCloud/headers/Export.h similarity index 71% rename from src/qevercloud/QEverCloud/headers/export.h rename to src/qevercloud/QEverCloud/headers/Export.h index c67cefdc..4fbf5aeb 100644 --- a/src/qevercloud/QEverCloud/headers/export.h +++ b/src/qevercloud/QEverCloud/headers/Export.h @@ -1,9 +1,9 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2017 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT */ #ifndef QEVERCLOUD_EXPORT_H @@ -16,7 +16,7 @@ #elif defined(QEVERCLOUD_STATIC_LIBRARY) # define QEVERCLOUD_EXPORT Q_DECL_EXPORT #else -# define QEVERCLOUD_EXPORT Q_DECL_EXPORT +# define QEVERCLOUD_EXPORT Q_DECL_IMPORT #endif #endif // QEVERCLOUD_EXPORT_H diff --git a/src/qevercloud/QEverCloud/headers/Globals.h b/src/qevercloud/QEverCloud/headers/Globals.h new file mode 100644 index 00000000..19542554 --- /dev/null +++ b/src/qevercloud/QEverCloud/headers/Globals.h @@ -0,0 +1,86 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_GLOBALS_H +#define QEVERCLOUD_GLOBALS_H + +#include "Export.h" + +#include + +/** + * All the library lives in this namespace. + */ +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Getter for network proxy settings used by QEverCloud. If none were set + * explicitly, returns the same result as QNetworkProxy::applicationProxy. + * Hence, QEverCloud uses the same proxy settings as the application which uses + * QEverCloud by default. + * + * This function is thread-safe although internally it operates on a static + * object containing proxy settings so it's not recommended to read and write + * proxy settings concurrently to avoid contention for static object. + * + * WARNING: when QEverCloud is built with QtWebEngine and some proxy settings + * different from QNetworkProxy::applicationProxy are set, the OAuth call + * which loads the web page would not use them; instead it would use proxy + * settings from QNetworkProxy::applicationProxy. This limitation is imposed + * by Qt: https://doc.qt.io/qt-5/qtwebengine-overview.html#proxy-support + */ +QEVERCLOUD_EXPORT QNetworkProxy evernoteNetworkProxy(); + +/** + * Setter for network proxy settings used by QEverCloud. If this function is + * never called, QEverCloud would use proxy settings returned from + * QNetworkProxy::applicationProxy static method. + * + * This function is thread-safe although internally it operates on a static + * object containing proxy settings so it's not recommended to read and write + * proxy settings concurrently to avoid contention for static object. + * + * WARNING: when QEverCloud is built with QtWebEngine and some proxy settings + * different from QNetworkProxy::applicationProxy are set, the OAuth call + * which loads the web page would not use them; instead it would use proxy + * settings from QNetworkProxy::applicationProxy. This limitation is imposed + * by Qt: https://doc.qt.io/qt-5/qtwebengine-overview.html#proxy-support + */ +QEVERCLOUD_EXPORT void setEvernoteNetworkProxy(QNetworkProxy proxy); + +/** + * Reset network proxy settings used by QEverCloud to those returned from + * QNetworkProxy::applicationProxy static method. + * + * This function is thread-safe although internally it operates on a static + * object containing proxy settings so it's not recommended to read and write + * proxy settings concurrently to avoid contention for static object. + */ +QEVERCLOUD_EXPORT void resetEvernoteNetworkProxy(); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * QEverCloud library version. + */ +Q_DECL_DEPRECATED_X("libraryVersion is deprecated, use qevercloudVersionMajor/Minor/Patch instead") +QEVERCLOUD_EXPORT int libraryVersion(); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Initialization function for QEverCloud, needs to be called once + * before using the library. There is no harm if it is called multiple times + */ +QEVERCLOUD_EXPORT void initializeQEverCloud(); + +} // namespace qevercloud + +#endif // QEVERCLOUD_GLOBALS_H diff --git a/src/qevercloud/QEverCloud/headers/Helpers.h b/src/qevercloud/QEverCloud/headers/Helpers.h new file mode 100644 index 00000000..aaed1830 --- /dev/null +++ b/src/qevercloud/QEverCloud/headers/Helpers.h @@ -0,0 +1,149 @@ +/** + * Copyright (c) 2019-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_HELPERS_H +#define QEVERCLOUD_HELPERS_H + +#include +#include + +#include "VersionInfo.h" + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0) + +// this adds const to non-const objects (like std::as_const) +template +Q_DECL_CONSTEXPR +typename std::add_const::type & qAsConst(T & t) Q_DECL_NOTHROW +{ + return t; +} + +// prevent rvalue arguments: +template +void qAsConst(const T &&) Q_DECL_EQ_DELETE; + +#endif // QT_VERSION_CHECK + +//////////////////////////////////////////////////////////////////////////////// + +template +class QAssociativeContainerReferenceWrapper +{ +public: + struct iterator + { + typename Container::iterator m_iterator; + iterator(const typename Container::iterator it) : + m_iterator(it) + {} + + typename Container::iterator operator*() + { + return m_iterator; + } + + iterator & operator++() + { + ++m_iterator; + return *this; + } + + bool operator!=(const iterator & other) const + { + return m_iterator != other.m_iterator; + } + }; + +public: + QAssociativeContainerReferenceWrapper(Container & container) + : m_container(container) + {} + + iterator begin() { + return m_container.begin(); + } + + iterator end() { + return m_container.end(); + } + +private: + Container & m_container; +}; + +//////////////////////////////////////////////////////////////////////////////// + +template +class QAssociativeContainerConstReferenceWrapper +{ +public: + struct iterator + { + typename Container::const_iterator m_iterator; + iterator(const typename Container::const_iterator it) : + m_iterator(it) + {} + + typename Container::const_iterator operator*() + { + return m_iterator; + } + + iterator & operator++() + { + ++m_iterator; + return *this; + } + + bool operator!=(const iterator & other) const + { + return m_iterator != other.m_iterator; + } + }; + +public: + QAssociativeContainerConstReferenceWrapper(const Container & container) + : m_container(container) + {} + + iterator begin() const { + return m_container.begin(); + } + + iterator end() const { + return m_container.end(); + } + +private: + const Container & m_container; +}; + +//////////////////////////////////////////////////////////////////////////////// + +template +QAssociativeContainerReferenceWrapper toRange(Container & container) +{ + return QAssociativeContainerReferenceWrapper(container); +} + +//////////////////////////////////////////////////////////////////////////////// + +template +QAssociativeContainerConstReferenceWrapper toRange( + const Container & container) +{ + return QAssociativeContainerConstReferenceWrapper(container); +} + +} // namespace qevercloud + +#endif // QEVERCLOUD_HELPERS_H diff --git a/src/qevercloud/QEverCloud/headers/InkNoteImageDownloader.h b/src/qevercloud/QEverCloud/headers/InkNoteImageDownloader.h index 073e1cb7..1077f272 100644 --- a/src/qevercloud/QEverCloud/headers/InkNoteImageDownloader.h +++ b/src/qevercloud/QEverCloud/headers/InkNoteImageDownloader.h @@ -1,16 +1,18 @@ /** - * Copyright (c) 2016 Dmitry Ivanov + * Copyright (c) 2016-2020 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT */ #ifndef QEVERCLOD_INK_NOTE_IMAGE_DOWNLOADER_H #define QEVERCLOD_INK_NOTE_IMAGE_DOWNLOADER_H -#include "export.h" #include "AsyncResult.h" -#include "generated/types.h" +#include "Export.h" + +#include "generated/Types.h" + #include #include #include @@ -22,17 +24,20 @@ class InkNoteImageDownloaderPrivate; /** @endcond */ /** - * @brief the class is for downloading the images of ink notes which can be created - * with the official Evernote client on Windows (only with it, at least at the time - * of this writing). + * @brief the InkNoteImageDownloader class is for downloading the images of ink + * notes which can be created with the official Evernote client on Windows + * (only with it, at least at the time of this writing). * * On all other platforms the most one can get instead of the actual ink note - * is its non-editable image. This class retrieves just these, exclusively in PNG format. + * is its non-editable image. This class retrieves just these, exclusively in + * PNG format. * * NOTE: almost the entirety of this class' content represents an ad-hoc solution * to a completely undocumented feature of Evernote service. A very small glimpse - * of information can be found e.g. here - * but it is practically all one can find. + * of information was once available on Evernote forums but it's deleted now... + * I collected an even smaller glimpse of information in this SO question: + * https://stackoverflow.com/q/39179012/1217285. For all practical purposes + * it is the only piece of information on this feature in existence now. */ class QEVERCLOUD_EXPORT InkNoteImageDownloader { @@ -40,8 +45,8 @@ class QEVERCLOUD_EXPORT InkNoteImageDownloader /** * @brief Default constructor. * - * host, shardId, authenticationToken, width, height have to be specified before calling - * @link download @endlink or @link createPostRequest @endlink + * host, shardId, authenticationToken, width, height have to be specified + * before calling @link download @endlink or @link createPostRequest @endlink */ InkNoteImageDownloader(); @@ -50,7 +55,8 @@ class QEVERCLOUD_EXPORT InkNoteImageDownloader * @param host * www.evernote.com or sandbox.evernote.com * @param shardId - * You can get the value from UserStore service or as a result of an authentication. + * You can get the value from UserStore service or as a result of an + * authentication. * @param authenticationToken * For working private ink notes you must supply a valid authentication token. * For public resources the value specified is not used. @@ -59,7 +65,9 @@ class QEVERCLOUD_EXPORT InkNoteImageDownloader * @param height * Height of the ink note's resource */ - InkNoteImageDownloader(QString host, QString shardId, QString authenticationToken, int width, int height); + InkNoteImageDownloader( + QString host, QString shardId, QString authenticationToken, int width, + int height); virtual ~InkNoteImageDownloader(); @@ -71,16 +79,18 @@ class QEVERCLOUD_EXPORT InkNoteImageDownloader /** * @param shardId - * You can get the value from UserStore service or as a result of an authentication. + * You can get the value from UserStore service or as a result of an + * authentication. */ InkNoteImageDownloader & setShardId(QString shardId); /** * @param authenticationToken - * For working private ink notes you must supply a valid authentication token. - * For public resources the value specified is not used. + * For working private ink notes you must supply a valid authentication + * token. For public resources the value specified is not used. */ - InkNoteImageDownloader & setAuthenticationToken(QString authenticationToken); + InkNoteImageDownloader & setAuthenticationToken( + QString authenticationToken); /** * @param width @@ -97,26 +107,31 @@ class QEVERCLOUD_EXPORT InkNoteImageDownloader /** * @brief Downloads the image for the ink note. * - * Unlike other pieces of QEverCloud API, downloading of ink note images is currently - * synchronous only. The reason for that is that AsyncResult is bounded to a single - * QNetworkRequest object but downloading of the ink note image might take multiple - * requests for several ink note image's vertical stripes which are then merged - * together to form a single image. Downloading the entire ink note's image - * via a single request works sometimes but sometimes Evernote replies to such request - * with messed up data which cannot be loaded into a QImage. The reason for that behaviour - * is unknown at the moment, and, given the state of official documentation - missing - - * it is likely to stay so. if someone has an idea how to make it more reliable, - * please let me know. + * Unlike other pieces of QEverCloud API, downloading of ink note images is + * currently synchronous only. The reason for that is that AsyncResult is + * bounded to a single QNetworkRequest object but downloading of the ink + * note image might take multiple requests for several ink note image's + * vertical stripes which are then merged together to form a single image. + * Downloading the entire ink note's image via a single request works + * sometimes but sometimes Evernote replies to such request with messed up + * data which cannot be loaded into a QImage. The reason for that behaviour + * is unknown at the moment, and, given the state of official documentation + * - missing - it is likely to stay so. if someone has an idea how to make + * it more reliable, please let me know. * * @param guid * The guid of the ink note's resource * @param isPublic - * Specify true for public ink notes. In this case authentication token is not sent to - * with the request as it shoud be according to the docs. + * Specify true for public ink notes. In this case authentication token is + * not sent to with the request as it should be according to the docs. + * @param timeoutMsec + * Timeout for download request in milliseconds * @return downloaded data. * */ - QByteArray download(Guid guid, bool isPublic = false); + QByteArray download( + Guid guid, const bool isPublic = false, + const qint64 timeoutMsec = 30000); private: InkNoteImageDownloaderPrivate * const d_ptr; diff --git a/src/qevercloud/QEverCloud/headers/Log.h b/src/qevercloud/QEverCloud/headers/Log.h new file mode 100644 index 00000000..379f063a --- /dev/null +++ b/src/qevercloud/QEverCloud/headers/Log.h @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2019-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_LOG_H +#define QEVERCLOUD_LOG_H + +#include "Export.h" +#include "Helpers.h" + +#include +#include +#include +#include + +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +enum class LogLevel +{ + Trace = 0, + Debug, + Info, + Warn, + Error +}; + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const LogLevel level); + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const LogLevel level); + +//////////////////////////////////////////////////////////////////////////////// + +class QEVERCLOUD_EXPORT ILogger +{ +public: + virtual bool shouldLog( + const LogLevel level, const char * component) const = 0; + + virtual void log( + const LogLevel level, const char * component, const char * fileName, + const quint32 lineNumber, const qint64 timestamp, + const QString & message) = 0; + + virtual void setLevel(const LogLevel level) = 0; + + virtual LogLevel level() const = 0; +}; + +using ILoggerPtr = std::shared_ptr; + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT ILoggerPtr logger(); + +QEVERCLOUD_EXPORT void setLogger(ILoggerPtr logger); + +QEVERCLOUD_EXPORT ILoggerPtr nullLogger(); + +QEVERCLOUD_EXPORT ILoggerPtr newStdErrLogger(LogLevel level = LogLevel::Warn); + +//////////////////////////////////////////////////////////////////////////////// + +#define __QEVERCLOUD_LOG_BASE(component, level, message) \ + { \ + auto __qevercloudLogger = ::qevercloud::logger(); \ + if (__qevercloudLogger->shouldLog(level, component)) \ + { \ + QString msg; \ + QDebug dbg(&msg); \ + dbg.nospace(); \ + dbg.noquote(); \ + dbg << message; \ + __qevercloudLogger->log( \ + level, \ + component, \ + __FILE__, \ + __LINE__, \ + QDateTime::currentMSecsSinceEpoch(), \ + msg); \ + } \ + } \ +// __QEVERCLOUD_LOG_BASE + +#define QEC_TRACE(component, message) \ + __QEVERCLOUD_LOG_BASE(component, LogLevel::Trace, message) \ +// QEC_TRACE + +#define QEC_DEBUG(component, message) \ + __QEVERCLOUD_LOG_BASE(component, LogLevel::Debug, message) \ +// QEC_DEBUG + +#define QEC_INFO(component, message) \ + __QEVERCLOUD_LOG_BASE(component, LogLevel::Info, message) \ +// QEC_INFO + +#define QEC_WARNING(component, message) \ + __QEVERCLOUD_LOG_BASE(component, LogLevel::Warn, message) \ +// QEC_WARNING + +#define QEC_ERROR(component, message) \ + __QEVERCLOUD_LOG_BASE(component, LogLevel::Error, message) \ +// QEC_ERROR + +} // namespace qevercloud + +#endif // QEVERCLOUD_LOG_H diff --git a/src/qevercloud/QEverCloud/headers/oauth.h b/src/qevercloud/QEverCloud/headers/OAuth.h similarity index 57% rename from src/qevercloud/QEverCloud/headers/oauth.h rename to src/qevercloud/QEverCloud/headers/OAuth.h index 532e15a1..56685b40 100644 --- a/src/qevercloud/QEverCloud/headers/oauth.h +++ b/src/qevercloud/QEverCloud/headers/OAuth.h @@ -1,43 +1,38 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT */ #ifndef QEVERCLOUD_OAUTH_H #define QEVERCLOUD_OAUTH_H -// Workarounding https://bugreports.qt.io/browse/QTBUG-28885 -#if defined(_MSC_VER) && (_MSC_VER <= 1600) -#define QT_NO_UNICODE_LITERAL -#endif +#include "Export.h" +#include "Helpers.h" +#include "Printable.h" -#include "generated/types.h" -#include "export.h" -#include "qt4helpers.h" -#include -#include +#include "generated/Types.h" -#if defined(_MSC_VER) && _MSC_VER <= 1600 // MSVC <= 2010 -// VS2010 is supposed to be C++11 but does not fulfull the entire standard. -#ifdef QStringLiteral -#undef QStringLiteral -#define QStringLiteral(str) QString::fromUtf8("" str "", sizeof(str) - 1) -#endif -#endif +#include +#include +#include +#include namespace qevercloud { /** * @brief Sets the function to use for nonce generation for OAuth authentication. * - * The default algorithm uses qrand() so do not forget to call qsrand() in your application! + * The default algorithm uses qrand() so do not forget to call qsrand() in your + * application! * - * qrand() is not guaranteed to be cryptographically strong. I try to amend the fact by using - * QUuid::createUuid() which uses /dev/urandom if it's available. But this is no guarantee either. - * So if you want total control over nonce generation you can write you own algorithm. + * qrand() is not guaranteed to be cryptographically strong. I try to amend + * the fact by using QUuid::createUuid() which uses /dev/urandom if it's + * available. But this is no guarantee either. + * So if you want total control over nonce generation you can write you own + * algorithm. * * setNonceGenerator is NOT thread safe. */ @@ -50,12 +45,14 @@ class EvernoteOAuthWebViewPrivate; /** * @brief The class is tailored specifically for OAuth authorization with Evernote. * - * While it is functional by itself you probably will prefer to use EvernoteOAuthDialog. + * While it is functional by itself you probably will prefer to use + * EvernoteOAuthDialog. * - * %Note that you have to include QEverCloudOAuth.h header. + * %Note that you have to include OAuth.h header. * - * By deafult EvernoteOAuthWebView uses qrand() for generating nonce so do not forget to call qsrand() - * in your application. See @link setNonceGenerator @endlink If you want more control over nonce generation. + * By default EvernoteOAuthWebView uses qrand() for generating nonce so do not + * forget to call qsrand() in your application. See @link setNonceGenerator @endlink + * If you want more control over nonce generation. */ class QEVERCLOUD_EXPORT EvernoteOAuthWebView: public QWidget { @@ -64,9 +61,11 @@ class QEVERCLOUD_EXPORT EvernoteOAuthWebView: public QWidget EvernoteOAuthWebView(QWidget * parent = Q_NULLPTR); /** - * This function starts the OAuth sequence. In the end of the sequence will be emitted one of the signals: authenticationSuceeded or authenticationFailed. + * This function starts the OAuth sequence. In the end of the sequence will + * be emitted one of the signals: authenticationSuceeded or authenticationFailed. * - * Do not call the function while its call is in effect, i.e. one of the signals is not emitted. + * Do not call the function while its call is in effect, i.e. one of + * the signals is not emitted. * * @param host * Evernote host to authorize with. You need one of this: @@ -78,24 +77,47 @@ class QEVERCLOUD_EXPORT EvernoteOAuthWebView: public QWidget * get it from the Evernote * @param consumerSecret * along with this + * @param timeoutMsec + * Timeout for network requests in milliseconds */ - void authenticate(QString host, QString consumerKey, QString consumerSecret); + void authenticate( + QString host, QString consumerKey, QString consumerSecret, + const qint64 timeoutMsec = 30000); - /** @return true if the last call to authenticate resulted in a successful authentication. */ + /** + * @return true if the last call to authenticate resulted in a successful + * authentication. + */ bool isSucceeded() const; /** @return error message resulted from the last call to authenticate */ QString oauthError() const; /** Holds data that is returned by Evernote on a successful authentication */ - struct OAuthResult + struct QEVERCLOUD_EXPORT OAuthResult: public Printable { - QString noteStoreUrl; ///< note store url for the user; no need to question UserStore::getNoteStoreUrl for it. + QString noteStoreUrl; ///< note store url for the user; no need to + /// question UserStore::getNoteStoreUrl for it. Timestamp expires; ///< authenticationToken time of expiration. QString shardId; ///< usually is not used UserID userId; ///< same as PublicUserInfo::userId QString webApiUrlPrefix; ///< see PublicUserInfo::webApiUrlPrefix QString authenticationToken; ///< This is what this all was for! + + ///< Cookies set by Evernote during OAuth procedure. In April 2020 these + /// cookies silently started to be required for UserStore API calls. + /// Probably it was a bug on Evernote side which hopefully would be + /// fixed at some point but nevertheless cookies set during OAuth + /// procedure are now available as a part of OAuth result and can be + /// used in subsequent calls to Evernote service. These cookies can + /// be set when creating an instance of IRequestContext. Then this + /// context can be used in QEverCloud calls. Cookies from context would + /// propagate to HTTP requests performed by QEverCloud. + /// See this thread on Evernote discussions for more details: + /// https://discussion.evernote.com/topic/124257-calls-to-userstore-from-evernote-api-stopped-working + QList cookies; + + virtual void print(QTextStream & strm) const override; }; /** @returns the result of the last authentication, i.e. authenticate() call.*/ @@ -104,16 +126,22 @@ class QEVERCLOUD_EXPORT EvernoteOAuthWebView: public QWidget /** The method is useful to specify default size for a EverOAuthWebView. */ void setSizeHint(QSize sizeHint); - virtual QSize sizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; Q_SIGNALS: /** Emitted when the OAuth sequence started with authenticate() call is finished */ void authenticationFinished(bool success); - /** Emitted when the OAuth sequence is successfully finished. Call oauthResult() to get the data.*/ + /** + * Emitted when the OAuth sequence is successfully finished. Call + * oauthResult() to get the data. + */ void authenticationSuceeded(); - /** Emitted when the OAuth sequence is finished with a failure. Some error info may be available with errorText().*/ + /** + * Emitted when the OAuth sequence is finished with a failure. Some error + * info may be available with errorText(). + */ void authenticationFailed(); private: @@ -126,16 +154,17 @@ class EvernoteOAuthDialogPrivate; /** @endcond */ /** - * @brief Authorizes your app with the Evernote service by means of OAuth authentication. + * @brief Authorizes your app with the Evernote service by means of OAuth + * authentication. * * Intended usage: * @code #include -OAuthDialog d(myConsumerKey, myConsumerSecret); +EvernoteOAuthDialog d(myConsumerKey, myConsumerSecret); if(d.exec() == QDialog::Accepted) { - OAuthDialog::OAuthResult res = d.oauthResult(); + EvernoteOAuthDialog::OAuthResult res = d.oauthResult(); // Connect to Evernote ... } else { @@ -148,15 +177,17 @@ if(d.exec() == QDialog::Accepted) { * * %Note that you have to include QEverCloudOAuth.h header. * - * By default EvernoteOAuthDialog uses qrand() for generating nonce so do not forget to call qsrand() - * in your application. See @link setNonceGenerator @endlink If you want more control over nonce generation. + * By default EvernoteOAuthDialog uses qrand() for generating nonce so do not + * forget to call qsrand() in your application. + * See @link setNonceGenerator @endlink If you want more control over nonce + * generation. */ class QEVERCLOUD_EXPORT EvernoteOAuthDialog: public QDialog { Q_OBJECT public: - typedef EvernoteOAuthWebView::OAuthResult OAuthResult; + using OAuthResult = EvernoteOAuthWebView::OAuthResult; /** Constructs the dialog. * @@ -171,24 +202,29 @@ class QEVERCLOUD_EXPORT EvernoteOAuthDialog: public QDialog * @param consumerSecret * along with this */ - EvernoteOAuthDialog(QString consumerKey, QString consumerSecret, QString host = QStringLiteral("www.evernote.com"), QWidget * parent = Q_NULLPTR); - ~EvernoteOAuthDialog(); + EvernoteOAuthDialog( + QString consumerKey, QString consumerSecret, + QString host = QStringLiteral("www.evernote.com"), + QWidget * parent = Q_NULLPTR); + + virtual ~EvernoteOAuthDialog() override; /** - * The dialog adjusts its initial size automatically based on the contained QWebView preffered size. - * Use this method to set the size. + * The dialog adjusts its initial size automatically based on the contained + * QWebView preffered size. Use this method to set the size. * * @param sizeHint will be used as the preffered size of the contained QWebView. */ void setWebViewSizeHint(QSize sizeHint); /** @return true in case of a successful authentication. - * You probably better chech exec() return value instead. + * You probably better check exec() return value instead. */ bool isSucceeded() const; /** - * @return In case of an authentification error may return some information about the error. + * @return In case of an authentification error may return some information + * about the error. */ QString oauthError() const; @@ -201,19 +237,11 @@ class QEVERCLOUD_EXPORT EvernoteOAuthDialog: public QDialog * @return * QDialog::Accepted on a successful authentication. */ -#if QT_VERSION < 0x050000 - int exec(); -#else - virtual int exec() Q_DECL_OVERRIDE; -#endif + virtual int exec() override; /** Shows the dialog as a window modal dialog, returning immediately. */ -#if QT_VERSION < 0x050000 - void open(); -#else - virtual void open() Q_DECL_OVERRIDE; -#endif + virtual void open() override; private: EvernoteOAuthDialogPrivate * const d_ptr; diff --git a/src/qevercloud/QEverCloud/headers/Optional.h b/src/qevercloud/QEverCloud/headers/Optional.h index b3b4cc92..2f21815a 100644 --- a/src/qevercloud/QEverCloud/headers/Optional.h +++ b/src/qevercloud/QEverCloud/headers/Optional.h @@ -1,15 +1,16 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT */ #ifndef QEVERCLOUD_OPTIONAL_H #define QEVERCLOUD_OPTIONAL_H #include "EverCloudException.h" + #include namespace qevercloud { @@ -17,20 +18,25 @@ namespace qevercloud { /** * Supports optional values. * - * Most of the fields in the Evernote API structs are optional. But C++ does not support this notion directly. + * Most of the fields in the Evernote API structs are optional. But C++ does not + * support this notion directly. * - * To implement the concept of optional values conventional Thrift C++ wrapper uses a special field of a struct type - * where each field is of type bool with the same name as a field in the struct. This bool flag indicated was - * the field with the same name in the outer struct assigned or not. + * To implement the concept of optional values conventional Thrift C++ wrapper + * uses a special field of a struct type where each field is of type bool with + * the same name as a field in the struct. This bool flag indicated was the field + * with the same name in the outer struct assigned or not. * - * While this method have its advantages (obviousness and simplicity) I found it very inconvenient to work with. - * You have to check by hand that both values (value itself and its __isset flag) are in sync. - * There is no checks whatsoever against an error and such an error is too easy to make. + * While this method have its advantages (obviousness and simplicity) I found + * it very inconvenient to work with. You have to check by hand that both values + * (value itself and its __isset flag) are in sync. There is no checks whatsoever + * against an error and such an error is too easy to make. * - * So for my library I created a special class that supports the optional value notion explicitly. - * Basically Optional class just holds a bool value that tracks the fact that a value was assigned. But this tracking - * is done automatically and attempts to use unissigned values throw exceptions. In this way errors are much harder to - * make and it's harder for them to slip through testing unnoticed too. + * So for my library I created a special class that supports the optional value + * notion explicitly. Basically Optional class just holds a bool value that + * tracks the fact that a value was assigned. But this tracking is done + * automatically and attempts to use unassigned values throw exceptions. In this + * way errors are much harder to make and it's harder for them to slip through + * testing unnoticed too. * */ template @@ -54,7 +60,8 @@ class Optional {} /** - * Template copy constructor. Allows to be initialized with Optional of any compatible type. + * Template copy constructor. Allows to be initialized with Optional of any + * compatible type. */ template Optional(const Optional & o) : @@ -129,7 +136,8 @@ class Optional operator const T&() const { if (!m_isSet) { - throw EverCloudException("qevercloud::Optional: nonexistent value access"); + throw EverCloudException( + "qevercloud::Optional: nonexistent value access"); } return m_value; @@ -143,7 +151,8 @@ class Optional operator T&() { if (!m_isSet) { - throw EverCloudException("qevercloud::Optional: nonexistent value access"); + throw EverCloudException( + "qevercloud::Optional: nonexistent value access"); } return m_value; @@ -158,7 +167,8 @@ class Optional const T & ref() const { if (!m_isSet) { - throw EverCloudException("qevercloud::Optional: nonexistent value access"); + throw EverCloudException( + "qevercloud::Optional: nonexistent value access"); } return m_value; @@ -167,7 +177,8 @@ class Optional /** * Returs reference to the holded value. * - * There are contexts in C++ where impicit type conversions can't help. For example: + * There are contexts in C++ where impicit type conversions can't help. + * For example: * * @code Optional l; @@ -183,7 +194,8 @@ class Optional * * ... but this is indeed ugly as hell. * - * So I implemented ref() function that returns a reference to the holded value. + * So I implemented ref() function that returns a reference to the holded + * value. * @code Optional l; for(auto s : l.ref()); // not ideal but OK @@ -192,7 +204,8 @@ class Optional T & ref() { if (!m_isSet) { - throw EverCloudException("qevercloud::Optional: nonexistent value access"); + throw EverCloudException( + "qevercloud::Optional: nonexistent value access"); } return m_value; @@ -257,11 +270,13 @@ class Optional } /** - * Two syntatic constructs come to mind to use for implementation of access to a struct's/class's field directly from Optional. + * Two syntatic constructs come to mind to use for implementation of access + * to a struct's/class's field directly from Optional. * * One is the dereference operator. * This is what boost::optional uses. While it's conceptually nice - * I found it to be not a very convenient way to refer to structs, especially nested ones. + * I found it to be not a very convenient way to refer to structs, + * especially nested ones. * So I overloaded the operator-> and use smart pointer semantics. * * @code @@ -275,19 +290,24 @@ class Optional @endcode * - * I admit, boost::optional is much more elegant overall. It uses pointer semantics quite clearly and - * in an instantly understandable way. It's universal (* works for any type and not just structs). There is - * no need for implicit type concersions and so there is no subtleties because of it. And so on. + * I admit, boost::optional is much more elegant overall. It uses pointer + * semantics quite clearly and in an instantly understandable way. It's + * universal (works for any type and not just structs). There is no need for + * implicit type concersions and so there is no subtleties because of it. + * And so on. * - * But then referring to struct fields is a chore. And this is the most common use case of Optionals in QEverCloud. + * But then referring to struct fields is a chore. And this is the most + * common use case of Optionals in QEverCloud. * - * So I decided to use non-obvious-on-the-first-sight semantics for my Optional. IMO it's much more convenient when gotten used to. + * So I decided to use non-obvious-on-the-first-sight semantics for my + * Optional. IMO it's much more convenient when gotten used to. * */ T * operator->() { if (!m_isSet) { - throw EverCloudException("qevercloud::Optional: nonexistent value access"); + throw EverCloudException( + "qevercloud::Optional: nonexistent value access"); } return &m_value; @@ -299,14 +319,16 @@ class Optional const T * operator->() const { if (!m_isSet) { - throw EverCloudException("qevercloud::Optional: nonexistent value access"); + throw EverCloudException( + "qevercloud::Optional: nonexistent value access"); } return &m_value; } /** - * The function is sometimes useful to simplify checking for the value being set. + * The function is sometimes useful to simplify checking for the value being + * set. * @param defaultValue * The value to return if Optional is not set. * @return Optional value if set and defaultValue otherwise. @@ -319,17 +341,40 @@ class Optional /** * Two optionals are equal if they are both not set or have * equal values. - * - * I do not define `operator==` due to not easily resolvable conflicts with `operator T&`. - * - * Note that `optional == other_optional` may throw but `optional.isEqual(other_optional)` will not. */ bool isEqual(const Optional & other) const { - if(m_isSet != other.m_isSet) return false; + if (m_isSet != other.m_isSet) { + return false; + } + return !m_isSet || (m_value == other.m_value); } + bool operator==(const Optional & other) const + { + return isEqual(other); + } + + bool operator!=(const Optional & other) const + { + return !operator==(other); + } + + bool operator==(const T & other) const + { + if (!m_isSet) { + return false; + } + + return m_value == other; + } + + bool operator!=(const T & other) const + { + return !operator==(other); + } + template friend class Optional; friend void swap(Optional & first, Optional & second) @@ -339,8 +384,6 @@ class Optional swap(first.m_value, second.m_value); } -// Visual C++ does not to generate implicit move constructors so this stuff doesn't work with even recent MSVC compilers -#if defined(Q_COMPILER_RVALUE_REFS) && !defined(_MSC_VER) Optional(Optional && other) { swap(*this, other); @@ -366,7 +409,6 @@ class Optional swap(m_value, other); return *this; } -#endif private: bool m_isSet; diff --git a/src/qevercloud/QEverCloud/headers/Printable.h b/src/qevercloud/QEverCloud/headers/Printable.h new file mode 100644 index 00000000..e7204421 --- /dev/null +++ b/src/qevercloud/QEverCloud/headers/Printable.h @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_PRINTABLE_H +#define QEVERCLOUD_PRINTABLE_H + +#include "Export.h" + +#include +#include + +namespace qevercloud { + +class QEVERCLOUD_EXPORT Printable +{ +public: + Printable() = default; + virtual ~Printable() = default; + + virtual void print(QTextStream & strm) const = 0; + + virtual QString toString() const; + + friend QEVERCLOUD_EXPORT QTextStream & operator <<( + QTextStream & strm, const Printable & printable); + + friend QEVERCLOUD_EXPORT QDebug & operator <<( + QDebug & dbg, const Printable & printable); +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_PRINTABLE_H diff --git a/src/qevercloud/QEverCloud/headers/QEverCloud.h b/src/qevercloud/QEverCloud/headers/QEverCloud.h index b74cd01c..e392e079 100644 --- a/src/qevercloud/QEverCloud/headers/QEverCloud.h +++ b/src/qevercloud/QEverCloud/headers/QEverCloud.h @@ -1,28 +1,32 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT */ #ifndef QEVERCLOUD_INFTHEADER_H #define QEVERCLOUD_INFTHEADER_H #include "AsyncResult.h" +#include "DurableService.h" #include "EventLoopFinisher.h" #include "EverCloudException.h" -#include "exceptions.h" -#include "export.h" -#include "globals.h" -#include "Optional.h" -#include "qt4helpers.h" -#include "thumbnail.h" +#include "Exceptions.h" +#include "Export.h" +#include "Globals.h" +#include "Helpers.h" #include "InkNoteImageDownloader.h" +#include "Log.h" +#include "Optional.h" +#include "Printable.h" +#include "RequestContext.h" +#include "Thumbnail.h" #include "VersionInfo.h" #include "generated/EDAMErrorCode.h" -#include "generated/constants.h" -#include "generated/services.h" -#include "generated/types.h" +#include "generated/Constants.h" +#include "generated/Services.h" +#include "generated/Types.h" #endif // QEVERCLOUD_INFTHEADER_H diff --git a/src/qevercloud/QEverCloud/headers/QEverCloudOAuth.h b/src/qevercloud/QEverCloud/headers/QEverCloudOAuth.h index 2888ad44..3b541c52 100644 --- a/src/qevercloud/QEverCloud/headers/QEverCloudOAuth.h +++ b/src/qevercloud/QEverCloud/headers/QEverCloudOAuth.h @@ -1,15 +1,15 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT */ #ifndef QEVERCLOUDOAUTH_INFTHEADER_H #define QEVERCLOUDOAUTH_INFTHEADER_H +#include "OAuth.h" #include "QEverCloud.h" -#include "oauth.h" #endif // QEVERCLOUDOAUTH_INFTHEADER_H diff --git a/src/qevercloud/QEverCloud/headers/RequestContext.h b/src/qevercloud/QEverCloud/headers/RequestContext.h new file mode 100644 index 00000000..db5f9718 --- /dev/null +++ b/src/qevercloud/QEverCloud/headers/RequestContext.h @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_REQUEST_CONTEXT_H +#define QEVERCLOUD_REQUEST_CONTEXT_H + +#include "Export.h" + +#include +#include +#include +#include +#include + +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +static constexpr quint64 DEFAULT_REQUEST_TIMEOUT_MSEC = 10000ull; + +static constexpr bool DEFAULT_REQUEST_TIMEOUT_EXPONENTIAL_INCREASE = true; + +static constexpr quint64 DEFAULT_MAX_REQUEST_TIMEOUT_MSEC = 600000ull; + +static constexpr quint32 DEFAULT_MAX_REQUEST_RETRY_COUNT = 10; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * IRequestContext carries several request scoped values defining the way + * request is handled by QEverCloud + */ +class QEVERCLOUD_EXPORT IRequestContext +{ +public: + /** Automatically generated unique identifier for each request */ + virtual QUuid requestId() const = 0; + + /** Authentication token to use along with the request */ + virtual QString authenticationToken() const = 0; + + /** Request timeout in milliseconds */ + virtual qint64 requestTimeout() const = 0; + + /** Should request timeout be exponentially increased on retries or not */ + virtual bool increaseRequestTimeoutExponentially() const = 0; + + /** + * Max request timeout in milliseconds (upper boundary for exponentially + * increasing timeouts on retries) + */ + virtual qint64 maxRequestTimeout() const = 0; + + /** Max number of attempts to retry a request */ + virtual quint32 maxRequestRetryCount() const = 0; + + /** Cookies to set to QNetworkRequest corresponding to Evernote API call */ + virtual QList cookies() const = 0; + + /** + * Create a new instance of IRequestContext with all the same parameters + * as in the source but a distinct id + */ + virtual IRequestContext * clone() const = 0; + + virtual ~IRequestContext() = default; + + friend QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & strm, const IRequestContext & ctx); + + friend QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & dbg, const IRequestContext & ctx); +}; + +using IRequestContextPtr = std::shared_ptr; + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT IRequestContextPtr newRequestContext( + QString authenticationToken = {}, + qint64 requestTimeout = DEFAULT_REQUEST_TIMEOUT_MSEC, + bool increaseRequestTimeoutExponentially = DEFAULT_REQUEST_TIMEOUT_EXPONENTIAL_INCREASE, + qint64 maxRequestTimeout = DEFAULT_MAX_REQUEST_TIMEOUT_MSEC, + quint32 maxRequestRetryCount = DEFAULT_MAX_REQUEST_RETRY_COUNT, + QList cookies = {}); + +} // namespace qevercloud + +#endif // QEVERCLOUD_REQUEST_CONTEXT_H diff --git a/src/qevercloud/QEverCloud/headers/thumbnail.h b/src/qevercloud/QEverCloud/headers/Thumbnail.h similarity index 65% rename from src/qevercloud/QEverCloud/headers/thumbnail.h rename to src/qevercloud/QEverCloud/headers/Thumbnail.h index 633c1803..440e1108 100644 --- a/src/qevercloud/QEverCloud/headers/thumbnail.h +++ b/src/qevercloud/QEverCloud/headers/Thumbnail.h @@ -1,20 +1,24 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT */ #ifndef QEVERCLOUD_THUMBNAIL_H #define QEVERCLOUD_THUMBNAIL_H -#include "export.h" #include "AsyncResult.h" -#include "generated/types.h" +#include "Export.h" + +#include "generated/Types.h" + #include -#include #include +#include + +#include namespace qevercloud { @@ -23,9 +27,11 @@ class ThumbnailPrivate; /** @endcond */ /** - * @brief The class is for downloading thumbnails for notes and resources from Evernote servers. + * @brief The class is for downloading thumbnails for notes and resources from + * Evernote servers. * - * These thumbnails are not available with general EDAM Thrift interface as explained in the + * These thumbnails are not available with general EDAM Thrift interface as + * explained in the * documentation. * * Usage: @@ -36,7 +42,7 @@ QByteArray pngImage = thumb.download(noteGuid); @endcode * - * By defualt 300x300 PNG images are requested. + * By default 300x300 PNG images are requested. */ class QEVERCLOUD_EXPORT Thumbnail { @@ -46,10 +52,20 @@ class QEVERCLOUD_EXPORT Thumbnail * * Can be PNG, JPEG, GIF or BMP. */ - struct ImageType { - enum type {PNG, JPEG, GIF, BMP}; + enum class ImageType + { + PNG, + JPEG, + GIF, + BMP }; + friend QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & strm, const ImageType imageType); + + friend QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & dbg, const ImageType imageType); + /** * @brief Default constructor. * @@ -63,17 +79,21 @@ class QEVERCLOUD_EXPORT Thumbnail * @param host * www.evernote.com or sandbox.evernote.com * @param shardId - * You can get the value from UserStore service or as a result of an authentication. + * You can get the value from UserStore service or as a result of an + * authentication. * @param authenticationToken - * For working private notes/resources you must supply a valid authentication token. + * For working private notes/resources you must supply a valid + * authentication token. * For public resources the value specified is not used. * @param size - * The size of the thumbnail. Evernote supports values from from 1 to 300. By defualt 300 is used. + * The size of the thumbnail. Evernote supports values from from 1 to 300. + * By default 300 is used. * @param imageType * Thumbnail image type. See ImageType. By default PNG is used. */ - Thumbnail(QString host, QString shardId, QString authenticationToken, - int size = 300, ImageType::type imageType = ImageType::PNG); + Thumbnail( + QString host, QString shardId, QString authenticationToken, + int size = 300, ImageType imageType = ImageType::PNG); virtual ~Thumbnail(); @@ -85,20 +105,23 @@ class QEVERCLOUD_EXPORT Thumbnail /** * @param shardId - * You can get the value from UserStore service or as a result of an authentication. + * You can get the value from UserStore service or as a result of an + * authentication. */ Thumbnail & setShardId(QString shardId); /** * @param authenticationToken - * For working private notes/resources you must supply a valid authentication token. + * For working private notes/resources you must supply a valid + * authentication token. * For public resources the value specified is not used. */ Thumbnail & setAuthenticationToken(QString authenticationToken); /** * @param size - * The size of the thumbnail. Evernote supports values from from 1 to 300. By defualt 300 is used. + * The size of the thumbnail. Evernote supports values from from 1 to 300. + * By default 300 is used. */ Thumbnail & setSize(int size); @@ -106,39 +129,45 @@ class QEVERCLOUD_EXPORT Thumbnail * @param imageType * Thumbnail image type. See ImageType. By default PNG is used. */ - Thumbnail & setImageType(ImageType::type imageType); + Thumbnail & setImageType(ImageType imageType); /** * @brief Downloads the thumbnail for a resource or a note. * @param guid * The note or resource guid * @param isPublic - * Specify true for public notes/resources. In this case authentication token is not sent to - * with the request as it shoud be according to the docs. + * Specify true for public notes/resources. In this case authentication + * token is not sent to with the request as it shoud be according to the docs. * @param isResourceGuid * true if guid denotes a resource and false if it denotes a note. + * @param timeoutMsec + * Timeout for download request in milliseconds * @return downloaded data. * */ - QByteArray download(Guid guid, bool isPublic = false, bool isResourceGuid = false); + QByteArray download( + Guid guid, const bool isPublic = false, const bool isResourceGuid = false, + const qint64 timeoutMsec = 30000); /** Asynchronous version of @link download @endlink function*/ - AsyncResult * downloadAsync(Guid guid, bool isPublic = false, bool isResourceGuid = false); + AsyncResult * downloadAsync( + Guid guid, const bool isPublic = false, const bool isResourceGuid = false, + const qint64 timeoutMsec = 30000); /** * @brief Prepares a POST request for a thumbnail download. * @param guid * The note or resource guid * @param isPublic - * Specify true for public notes/resources. In this case authentication token is not sent to - * with the request as it shoud be according to the docs. + * Specify true for public notes/resources. In this case authentication + * token is not sent to with the request as it shoud be according to the docs. * @param isResourceGuid * true if guid denotes a resource and false if it denotes a note. - * @return a pair of QNetworkRequest for the POST request and data that must be posted with the request. + * @return a pair of QNetworkRequest for the POST request and data that must + * be posted with the request. */ - QPair createPostRequest(qevercloud::Guid guid, - bool isPublic = false, - bool isResourceGuid = false); + std::pair createPostRequest( + qevercloud::Guid guid, bool isPublic = false, bool isResourceGuid = false); private: ThumbnailPrivate * const d_ptr; diff --git a/src/qevercloud/QEverCloud/headers/VersionInfo.h b/src/qevercloud/QEverCloud/headers/VersionInfo.h deleted file mode 100644 index 737beeff..00000000 --- a/src/qevercloud/QEverCloud/headers/VersionInfo.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2017 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - */ - -#ifndef QEVERCLOUD_VERSION_INFO_H -#define QEVERCLOUD_VERSION_INFO_H - -/** - * This file contains configuration-specific macro definitions - * which can then be tested in compile time by library users - */ - -/** - * This macro tells whether QEverCloud library was built with OAuth support - */ -#define QEVERCLOUD_HAS_OAUTH 1 - -/** - * This macro tells whether QEverCloud library uses QtWebEngine backend for OAuth support - * (if it was built with OAuth support) - */ -#define QEVERCLOUD_USES_QT_WEB_ENGINE 0 - -#endif // QEVERCLOUD_VERSION_INFO_H diff --git a/src/qevercloud/QEverCloud/headers/VersionInfo.h.in b/src/qevercloud/QEverCloud/headers/VersionInfo.h.in index c9363de9..021930c4 100644 --- a/src/qevercloud/QEverCloud/headers/VersionInfo.h.in +++ b/src/qevercloud/QEverCloud/headers/VersionInfo.h.in @@ -1,13 +1,17 @@ /** - * Copyright (c) 2017 Dmitry Ivanov + * Copyright (c) 2017-2020 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT */ #ifndef QEVERCLOUD_VERSION_INFO_H #define QEVERCLOUD_VERSION_INFO_H +#include \"Export.h\" + +#include + /** * This file contains configuration-specific macro definitions * which can then be tested in compile time by library users @@ -16,12 +20,94 @@ /** * This macro tells whether QEverCloud library was built with OAuth support */ -@QEVERCLOUD_HAS_OAUTH@ +#define QEVERCLOUD_HAS_OAUTH 1 + +/** + * This macro tells whether QEverCloud library uses QtWebEngine backend for + * OAuth support (if it was built with OAuth support) + */ +#define QEVERCLOUD_USE_QT_WEB_ENGINE $$QEVERCLOUD_USE_QT_WEB_ENGINE + +/** + * This macro tells whether QEverCloud library uses system browser for OAuth + * support (if it was built with OAuth support) + */ +#define QEVERCLOUD_USE_SYSTEM_BROWSER $$QEVERCLOUD_USE_SYSTEM_BROWSER + +/** + * This macro tells whether QEverCloud library was built with use of Q_NAMESPACE + * and Q_ENUM_NS + */ +#define QEVERCLOUD_USES_Q_NAMESPACE 0 + +/** + * This macro is set to a string holding the information about + * the current QEverCloud build + */ +#define QEVERCLOUD_BUILD_INFO \"nixnote2 integrated\" + +/** + * This macro is set to the major version number of QEverCloud + */ +#define QEVERCLOUD_VERSION_MAJOR 6 + +/** + * This macro is set to the minor version of QEverCloud + */ +#define QEVERCLOUD_VERSION_MINOR 1 + +/** + * This macro is set to the patch version of QEverCloud + */ +#define QEVERCLOUD_VERSION_PATCH 0 + +namespace qevercloud { + +/** + * @return Major version of QEverCloud + */ +int QEVERCLOUD_EXPORT qevercloudVersionMajor(); + +/** + * @return Minor version of QEverCloud + */ +int QEVERCLOUD_EXPORT qevercloudVersionMinor(); + +/** + * @return Patch version of QEverCloud + */ +int QEVERCLOUD_EXPORT qevercloudVersionPatch(); /** - * This macro tells whether QEverCloud library uses QtWebEngine backend for OAuth support - * (if it was built with OAuth support) + * @return String containing information about + * the current QEverCloud build */ -@QEVERCLOUD_USES_QT_WEB_ENGINE@ +QString QEVERCLOUD_EXPORT qevercloudBuildInfo(); + +/** + * @return String representing the version of Qt against which + * QEverCloud was built + */ +QString QEVERCLOUD_EXPORT qevercloudBuiltWithQtVersion(); + +/** + * @return True if QEverCloud was built with OAuth support, false + * otherwise + */ +bool QEVERCLOUD_EXPORT qevercloudHasOAuth(); + +/** + * @return True if QEverCloud was built with QtWebEngine, false + * otherwise + */ +bool QEVERCLOUD_EXPORT qevercloudUsesQtWebEngine(); + +/** + * @return True if QEverCloud was built with use of Q_NAMESPACE and + * Q_ENUM_NS, false otherwise + */ +bool QEVERCLOUD_EXPORT qevercloudUsesQNamespace(); + +} // namespace qevercloud #endif // QEVERCLOUD_VERSION_INFO_H diff --git a/src/qevercloud/QEverCloud/headers/exceptions.h b/src/qevercloud/QEverCloud/headers/exceptions.h deleted file mode 100644 index f0da48a3..00000000 --- a/src/qevercloud/QEverCloud/headers/exceptions.h +++ /dev/null @@ -1,176 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - */ - -#ifndef QEVERCLOUD_EXCEPTIONS_H -#define QEVERCLOUD_EXCEPTIONS_H - -#include "Optional.h" -#include "export.h" -#include "EverCloudException.h" -#include "generated/EDAMErrorCode.h" -#include "generated/types.h" -#include -#include -#include - -namespace qevercloud { - -/** - * Errors of the Thrift protocol level. It could be wrongly formatted parameters - * or return values for example. - */ -class QEVERCLOUD_EXPORT ThriftException: public EverCloudException -{ -public: - struct Type { - enum type { - UNKNOWN = 0, - UNKNOWN_METHOD = 1, - INVALID_MESSAGE_TYPE = 2, - WRONG_METHOD_NAME = 3, - BAD_SEQUENCE_ID = 4, - MISSING_RESULT = 5, - INTERNAL_ERROR = 6, - PROTOCOL_ERROR = 7, - INVALID_DATA = 8 - }; - }; - - ThriftException(); - ThriftException(Type::type type); - ThriftException(Type::type type, QString message); - - Type::type type() const; - - const char * what() const throw() Q_DECL_OVERRIDE; - - virtual QSharedPointer exceptionData() const Q_DECL_OVERRIDE; - -protected: - Type::type m_type; -}; - -/** Asynchronous API conterpart of ThriftException. See EverCloudExceptionData for more details.*/ -class QEVERCLOUD_EXPORT ThriftExceptionData: public EverCloudExceptionData -{ - Q_OBJECT - Q_DISABLE_COPY(ThriftExceptionData) -public: - explicit ThriftExceptionData(QString error, ThriftException::Type::type type); - virtual void throwException() const Q_DECL_OVERRIDE; - -protected: - ThriftException::Type::type m_type; -}; - -inline QSharedPointer ThriftException::exceptionData() const -{ - return QSharedPointer(new ThriftExceptionData(QString::fromUtf8(what()), type())); -} - -/** Asynchronous API conterpart of EDAMUserException. See EverCloudExceptionData for more details.*/ -class QEVERCLOUD_EXPORT EDAMUserExceptionData: public EvernoteExceptionData -{ - Q_OBJECT - Q_DISABLE_COPY(EDAMUserExceptionData) -public: - explicit EDAMUserExceptionData(QString error, EDAMErrorCode::type errorCode, Optional parameter); - virtual void throwException() const Q_DECL_OVERRIDE; - -protected: - EDAMErrorCode::type m_errorCode; - Optional m_parameter; -}; - -/** Asynchronous API conterpart of EDAMSystemException. See EverCloudExceptionData for more details.*/ -class QEVERCLOUD_EXPORT EDAMSystemExceptionData: public EvernoteExceptionData -{ - Q_OBJECT - Q_DISABLE_COPY(EDAMSystemExceptionData) -public: - explicit EDAMSystemExceptionData(QString err, EDAMErrorCode::type errorCode, Optional message, Optional rateLimitDuration); - virtual void throwException() const Q_DECL_OVERRIDE; - -protected: - EDAMErrorCode::type m_errorCode; - Optional m_message; - Optional m_rateLimitDuration; -}; - -/** Asynchronous API conterpart of EDAMNotFoundException. See EverCloudExceptionData for more details.*/ -class QEVERCLOUD_EXPORT EDAMNotFoundExceptionData: public EvernoteExceptionData -{ - Q_OBJECT - Q_DISABLE_COPY(EDAMNotFoundExceptionData) -public: - explicit EDAMNotFoundExceptionData(QString error, Optional identifier, Optional key); - virtual void throwException() const Q_DECL_OVERRIDE; - -protected: - Optional m_identifier; - Optional m_key; -}; - -/** Asynchronous API conterpart of EDAMInvalidContactsException. See EverCloudExceptionData for more details.*/ -class QEVERCLOUD_EXPORT EDAMInvalidContactsExceptionData: public EvernoteExceptionData -{ - Q_OBJECT - Q_DISABLE_COPY(EDAMInvalidContactsExceptionData) -public: - explicit EDAMInvalidContactsExceptionData(QList contacts, Optional parameter, Optional > reasons); - virtual void throwException() const Q_DECL_OVERRIDE; - -protected: - QList< Contact > m_contacts; - Optional< QString > m_parameter; - Optional< QList< EDAMInvalidContactReason::type > > m_reasons; -}; - -/** - * EDAMSystemException for `errorCode = RATE_LIMIT_REACHED` - */ -class QEVERCLOUD_EXPORT EDAMSystemExceptionRateLimitReached: public EDAMSystemException -{ -public: - virtual QSharedPointer exceptionData() const Q_DECL_OVERRIDE; -}; - -/** Asynchronous API conterpart of EDAMSystemExceptionRateLimitReached. See EverCloudExceptionData for more details.*/ -class QEVERCLOUD_EXPORT EDAMSystemExceptionRateLimitReachedData: public EDAMSystemExceptionData -{ - Q_OBJECT - Q_DISABLE_COPY(EDAMSystemExceptionRateLimitReachedData) -public: - explicit EDAMSystemExceptionRateLimitReachedData(QString error, EDAMErrorCode::type errorCode, Optional message, - Optional rateLimitDuration); - virtual void throwException() const Q_DECL_OVERRIDE; -}; - -/** - * EDAMSystemException for `errorCode = AUTH_EXPIRED` - */ -class QEVERCLOUD_EXPORT EDAMSystemExceptionAuthExpired: public EDAMSystemException -{ -public: - virtual QSharedPointer exceptionData() const Q_DECL_OVERRIDE; -}; - -/** Asynchronous API conterpart of EDAMSystemExceptionAuthExpired. See EverCloudExceptionData for more details.*/ -class QEVERCLOUD_EXPORT EDAMSystemExceptionAuthExpiredData: public EDAMSystemExceptionData -{ - Q_OBJECT - Q_DISABLE_COPY(EDAMSystemExceptionAuthExpiredData) -public: - explicit EDAMSystemExceptionAuthExpiredData(QString error, EDAMErrorCode::type errorCode, Optional message, - Optional rateLimitDuration); - virtual void throwException() const Q_DECL_OVERRIDE; -}; - -} // namespace qevercloud - -#endif // QEVERCLOUD_EXCEPTIONS_H diff --git a/src/qevercloud/QEverCloud/headers/generated/constants.h b/src/qevercloud/QEverCloud/headers/generated/Constants.h similarity index 90% rename from src/qevercloud/QEverCloud/headers/generated/constants.h rename to src/qevercloud/QEverCloud/headers/generated/Constants.h index e1164abe..24c167ce 100644 --- a/src/qevercloud/QEverCloud/headers/generated/constants.h +++ b/src/qevercloud/QEverCloud/headers/generated/Constants.h @@ -1,102 +1,108 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: * https://opensource.org/licenses/MIT * * This file was generated from Evernote Thrift API */ - #ifndef QEVERCLOUD_GENERATED_CONSTANTS_H #define QEVERCLOUD_GENERATED_CONSTANTS_H -#include "../Optional.h" -#include "../export.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "../Export.h" namespace qevercloud { +//////////////////////////////////////////////////////////////////////////////// + // Limits.thrift /** * Minimum length of any string-based attribute, in Unicode chars */ QEVERCLOUD_EXPORT extern const qint32 EDAM_ATTRIBUTE_LEN_MIN; +// Limits.thrift /** * Maximum length of any string-based attribute, in Unicode chars */ QEVERCLOUD_EXPORT extern const qint32 EDAM_ATTRIBUTE_LEN_MAX; +// Limits.thrift /** * Any string-based attribute must match the provided regular expression. * This excludes all Unicode line endings and control characters. */ QEVERCLOUD_EXPORT extern const QString EDAM_ATTRIBUTE_REGEX; +// Limits.thrift /** * The maximum number of values that can be stored in a list-based attribute * (e.g. see UserAttributes.recentMailedAddresses) */ QEVERCLOUD_EXPORT extern const qint32 EDAM_ATTRIBUTE_LIST_MAX; +// Limits.thrift /** * The maximum number of entries that can be stored in a map-based attribute * such as applicationData fields in Resources and Notes. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_ATTRIBUTE_MAP_MAX; +// Limits.thrift /** * The minimum length of a GUID generated by the Evernote service */ QEVERCLOUD_EXPORT extern const qint32 EDAM_GUID_LEN_MIN; +// Limits.thrift /** * The maximum length of a GUID generated by the Evernote service */ QEVERCLOUD_EXPORT extern const qint32 EDAM_GUID_LEN_MAX; +// Limits.thrift /** * GUIDs generated by the Evernote service will match the provided pattern */ QEVERCLOUD_EXPORT extern const QString EDAM_GUID_REGEX; +// Limits.thrift /** * The minimum length of any email address */ QEVERCLOUD_EXPORT extern const qint32 EDAM_EMAIL_LEN_MIN; +// Limits.thrift /** * The maximum length of any email address */ QEVERCLOUD_EXPORT extern const qint32 EDAM_EMAIL_LEN_MAX; +// Limits.thrift /** * A regular expression that matches the part of an email address before * the '@' symbol. */ QEVERCLOUD_EXPORT extern const QString EDAM_EMAIL_LOCAL_REGEX; +// Limits.thrift /** * A regular expression that matches the part of an email address after * the '@' symbol. */ QEVERCLOUD_EXPORT extern const QString EDAM_EMAIL_DOMAIN_REGEX; +// Limits.thrift /** * A regular expression that must match any email address given to Evernote. * Email addresses must comply with RFC 2821 and 2822. */ QEVERCLOUD_EXPORT extern const QString EDAM_EMAIL_REGEX; +// Limits.thrift /** * A regular expression that must match any VAT ID given to Evernote. * ref http://en.wikipedia.org/wiki/VAT_identification_number @@ -104,16 +110,19 @@ QEVERCLOUD_EXPORT extern const QString EDAM_EMAIL_REGEX; */ QEVERCLOUD_EXPORT extern const QString EDAM_VAT_REGEX; +// Limits.thrift /** * The minimum length of a timezone specification string */ QEVERCLOUD_EXPORT extern const qint32 EDAM_TIMEZONE_LEN_MIN; +// Limits.thrift /** * The maximum length of a timezone specification string */ QEVERCLOUD_EXPORT extern const qint32 EDAM_TIMEZONE_LEN_MAX; +// Limits.thrift /** * Any timezone string given to Evernote must match the provided pattern. * This permits either a locale-based standard timezone or a GMT offset. @@ -124,94 +133,117 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_TIMEZONE_LEN_MAX; */ QEVERCLOUD_EXPORT extern const QString EDAM_TIMEZONE_REGEX; +// Limits.thrift /** * The minimum length of any MIME type string given to Evernote */ QEVERCLOUD_EXPORT extern const qint32 EDAM_MIME_LEN_MIN; +// Limits.thrift /** * The maximum length of any MIME type string given to Evernote */ QEVERCLOUD_EXPORT extern const qint32 EDAM_MIME_LEN_MAX; +// Limits.thrift /** * Any MIME type string given to Evernote must match the provided pattern. * E.g.: image/gif */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_REGEX; +// Limits.thrift /** Canonical MIME type string for GIF image resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_GIF; +// Limits.thrift /** Canonical MIME type string for JPEG image resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_JPEG; +// Limits.thrift /** Canonical MIME type string for PNG image resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_PNG; +// Limits.thrift /** Canonical MIME type string for TIFF image resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_TIFF; +// Limits.thrift /** Canonical MIME type string for BMP image resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_BMP; +// Limits.thrift /** Canonical MIME type string for WAV audio resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_WAV; +// Limits.thrift /** Canonical MIME type string for MP3 audio resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_MP3; +// Limits.thrift /** Canonical MIME type string for AMR audio resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_AMR; +// Limits.thrift /** Canonical MIME type string for AAC audio resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_AAC; +// Limits.thrift /** Canonical MIME type string for MP4 audio resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_M4A; +// Limits.thrift /** Canonical MIME type string for MP4 video resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_MP4_VIDEO; +// Limits.thrift /** Canonical MIME type string for Evernote Ink resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_INK; +// Limits.thrift /** Canonical MIME type string for PDF resources */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_PDF; +// Limits.thrift /** MIME type used for attachments of an unspecified type */ QEVERCLOUD_EXPORT extern const QString EDAM_MIME_TYPE_DEFAULT; +// Limits.thrift /** * The set of resource MIME types that are expected to be handled * correctly by all of the major Evernote client applications. */ -QEVERCLOUD_EXPORT extern const QSet< QString > EDAM_MIME_TYPES; +QEVERCLOUD_EXPORT extern const QSet EDAM_MIME_TYPES; +// Limits.thrift /** * The set of MIME types that Evernote will parse and index for * searching. With exception of images, PDFs and plain text files, * which are handled in a different way. */ -QEVERCLOUD_EXPORT extern const QSet< QString > EDAM_INDEXABLE_RESOURCE_MIME_TYPES; +QEVERCLOUD_EXPORT extern const QSet EDAM_INDEXABLE_RESOURCE_MIME_TYPES; +// Limits.thrift /** * The set of plain text MIME types that Evernote will parse and index * for searching. The MIME types which start with "text/" will be handled * separately by each client (i.e. hard-coded in each client). */ -QEVERCLOUD_EXPORT extern const QSet< QString > EDAM_INDEXABLE_PLAINTEXT_MIME_TYPES; +QEVERCLOUD_EXPORT extern const QSet EDAM_INDEXABLE_PLAINTEXT_MIME_TYPES; +// Limits.thrift /** * The minimum length of a user search query string in Unicode chars */ QEVERCLOUD_EXPORT extern const qint32 EDAM_SEARCH_QUERY_LEN_MIN; +// Limits.thrift /** * The maximum length of a user search query string in Unicode chars */ QEVERCLOUD_EXPORT extern const qint32 EDAM_SEARCH_QUERY_LEN_MAX; +// Limits.thrift /** * Search queries must match the provided pattern. This is used for * both ad-hoc queries and SavedSearch.query fields. @@ -219,6 +251,7 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_SEARCH_QUERY_LEN_MAX; */ QEVERCLOUD_EXPORT extern const QString EDAM_SEARCH_QUERY_REGEX; +// Limits.thrift /** * The exact length of a MD5 hash checksum, in binary bytes. * This is the exact length that must be matched for any binary hash @@ -226,16 +259,19 @@ QEVERCLOUD_EXPORT extern const QString EDAM_SEARCH_QUERY_REGEX; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_HASH_LEN; +// Limits.thrift /** * The minimum length of an Evernote username */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_USERNAME_LEN_MIN; +// Limits.thrift /** * The maximum length of an Evernote username */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_USERNAME_LEN_MAX; +// Limits.thrift /** * Any Evernote User.username field must match this pattern. This * restricts usernames to a format that could permit use as a domain @@ -243,32 +279,38 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_USERNAME_LEN_MAX; */ QEVERCLOUD_EXPORT extern const QString EDAM_USER_USERNAME_REGEX; +// Limits.thrift /** * Minimum length of the User.name field */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_NAME_LEN_MIN; +// Limits.thrift /** * Maximum length of the User.name field */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_NAME_LEN_MAX; +// Limits.thrift /** * The User.name field must match this pattern, which excludes line * endings and control characters. */ QEVERCLOUD_EXPORT extern const QString EDAM_USER_NAME_REGEX; +// Limits.thrift /** * The minimum length of a Tag.name, in Unicode characters */ QEVERCLOUD_EXPORT extern const qint32 EDAM_TAG_NAME_LEN_MIN; +// Limits.thrift /** * The maximum length of a Tag.name, in Unicode characters */ QEVERCLOUD_EXPORT extern const qint32 EDAM_TAG_NAME_LEN_MAX; +// Limits.thrift /** * All Tag.name fields must match this pattern. * This excludes control chars, commas or line/paragraph separators. @@ -276,16 +318,19 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_TAG_NAME_LEN_MAX; */ QEVERCLOUD_EXPORT extern const QString EDAM_TAG_NAME_REGEX; +// Limits.thrift /** * The minimum length of a Note.title, in Unicode characters */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_TITLE_LEN_MIN; +// Limits.thrift /** * The maximum length of a Note.title, in Unicode characters */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_TITLE_LEN_MAX; +// Limits.thrift /** * All Note.title fields must match this pattern. * This excludes control chars or line/paragraph separators. @@ -293,18 +338,21 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_TITLE_LEN_MAX; */ QEVERCLOUD_EXPORT extern const QString EDAM_NOTE_TITLE_REGEX; +// Limits.thrift /** * Minimum length of a Note.content field. * Note.content fields must comply with the ENML DTD. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_CONTENT_LEN_MIN; +// Limits.thrift /** * Maximum length of a Note.content field * Note.content fields must comply with the ENML DTD. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_CONTENT_LEN_MAX; +// Limits.thrift /** * Minimum length of an application name, which is the key in an * applicationData LazyMap found in entities such as Resources and @@ -312,6 +360,7 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_CONTENT_LEN_MAX; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_APPLICATIONDATA_NAME_LEN_MIN; +// Limits.thrift /** * Maximum length of an application name, which is the key in an * applicationData LazyMap found in entities such as Resources and @@ -319,12 +368,14 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_APPLICATIONDATA_NAME_LEN_MIN; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_APPLICATIONDATA_NAME_LEN_MAX; +// Limits.thrift /** * Minimum length of an applicationData value in a LazyMap, found * in entities such as Resources and Notes. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_APPLICATIONDATA_VALUE_LEN_MIN; +// Limits.thrift /** * Maximum length of an applicationData value in a LazyMap, found * in entities such as Resources and Notes. Note, however, that @@ -334,12 +385,14 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_APPLICATIONDATA_VALUE_LEN_MIN; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_APPLICATIONDATA_VALUE_LEN_MAX; +// Limits.thrift /** * The total length of an entry in an applicationData LazyMap, which * is the sum of the length of the key and the value for the entry. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_APPLICATIONDATA_ENTRY_LEN_MAX; +// Limits.thrift /** * An application name must match this regex. An application * name is the key portion of an entry in an applicationData @@ -350,6 +403,7 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_APPLICATIONDATA_ENTRY_LEN_MAX; */ QEVERCLOUD_EXPORT extern const QString EDAM_APPLICATIONDATA_NAME_REGEX; +// Limits.thrift /** * An applicationData map value must match this regex. * Note that even if both the name and value regexes match, @@ -358,16 +412,19 @@ QEVERCLOUD_EXPORT extern const QString EDAM_APPLICATIONDATA_NAME_REGEX; */ QEVERCLOUD_EXPORT extern const QString EDAM_APPLICATIONDATA_VALUE_REGEX; +// Limits.thrift /** * The minimum length of a Notebook.name, in Unicode characters */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTEBOOK_NAME_LEN_MIN; +// Limits.thrift /** * The maximum length of a Notebook.name, in Unicode characters */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTEBOOK_NAME_LEN_MAX; +// Limits.thrift /** * All Notebook.name fields must match this pattern. * This excludes control chars or line/paragraph separators. @@ -375,16 +432,19 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTEBOOK_NAME_LEN_MAX; */ QEVERCLOUD_EXPORT extern const QString EDAM_NOTEBOOK_NAME_REGEX; +// Limits.thrift /** * The minimum length of a Notebook.stack, in Unicode characters */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTEBOOK_STACK_LEN_MIN; +// Limits.thrift /** * The maximum length of a Notebook.stack, in Unicode characters */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTEBOOK_STACK_LEN_MAX; +// Limits.thrift /** * All Notebook.stack fields must match this pattern. * This excludes control chars or line/paragraph separators. @@ -392,21 +452,25 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTEBOOK_STACK_LEN_MAX; */ QEVERCLOUD_EXPORT extern const QString EDAM_NOTEBOOK_STACK_REGEX; +// Limits.thrift /** * The minimum length of a Workspace.name, in Unicode characters */ QEVERCLOUD_EXPORT extern const qint32 EDAM_WORKSPACE_NAME_LEN_MIN; +// Limits.thrift /** * The maximum length of a Workspace.name, in Unicode characters */ QEVERCLOUD_EXPORT extern const qint32 EDAM_WORKSPACE_NAME_LEN_MAX; +// Limits.thrift /** * The maximum length of a Workspace.description, in Unicode characters */ QEVERCLOUD_EXPORT extern const qint32 EDAM_WORKSPACE_DESCRIPTION_LEN_MAX; +// Limits.thrift /** * All Workspace.name fields must match this pattern. * This excludes control chars or line/paragraph separators. @@ -414,36 +478,43 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_WORKSPACE_DESCRIPTION_LEN_MAX; */ QEVERCLOUD_EXPORT extern const QString EDAM_WORKSPACE_NAME_REGEX; +// Limits.thrift /** * The minimum length of a public notebook URI component */ QEVERCLOUD_EXPORT extern const qint32 EDAM_PUBLISHING_URI_LEN_MIN; +// Limits.thrift /** * The maximum length of a public notebook URI component */ QEVERCLOUD_EXPORT extern const qint32 EDAM_PUBLISHING_URI_LEN_MAX; +// Limits.thrift /** * A public notebook URI component must match the provided pattern */ QEVERCLOUD_EXPORT extern const QString EDAM_PUBLISHING_URI_REGEX; +// Limits.thrift /** * The set of strings that may not be used as a publishing URI */ -QEVERCLOUD_EXPORT extern const QSet< QString > EDAM_PUBLISHING_URI_PROHIBITED; +QEVERCLOUD_EXPORT extern const QSet EDAM_PUBLISHING_URI_PROHIBITED; +// Limits.thrift /** * The minimum length of a Publishing.publicDescription field. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_PUBLISHING_DESCRIPTION_LEN_MIN; +// Limits.thrift /** * The maximum length of a Publishing.publicDescription field. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_PUBLISHING_DESCRIPTION_LEN_MAX; +// Limits.thrift /** * Any public notebook's Publishing.publicDescription field must match * this pattern. @@ -452,16 +523,19 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_PUBLISHING_DESCRIPTION_LEN_MAX; */ QEVERCLOUD_EXPORT extern const QString EDAM_PUBLISHING_DESCRIPTION_REGEX; +// Limits.thrift /** * The minimum length of a SavedSearch.name field */ QEVERCLOUD_EXPORT extern const qint32 EDAM_SAVED_SEARCH_NAME_LEN_MIN; +// Limits.thrift /** * The maximum length of a SavedSearch.name field */ QEVERCLOUD_EXPORT extern const qint32 EDAM_SAVED_SEARCH_NAME_LEN_MAX; +// Limits.thrift /** * SavedSearch.name fields must match this pattern. * No control chars or line/paragraph separators, and can't start or @@ -469,92 +543,110 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_SAVED_SEARCH_NAME_LEN_MAX; */ QEVERCLOUD_EXPORT extern const QString EDAM_SAVED_SEARCH_NAME_REGEX; +// Limits.thrift /** * The minimum length of an Evernote user password */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_PASSWORD_LEN_MIN; +// Limits.thrift /** * The maximum length of an Evernote user password */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_PASSWORD_LEN_MAX; +// Limits.thrift /** * Evernote user passwords must match this regular expression */ QEVERCLOUD_EXPORT extern const QString EDAM_USER_PASSWORD_REGEX; +// Limits.thrift /** * The maximum length of an Evernote Business URI */ QEVERCLOUD_EXPORT extern const qint32 EDAM_BUSINESS_URI_LEN_MAX; +// Limits.thrift /** * Valid Evernote Business marketing code / affiliate code format. */ QEVERCLOUD_EXPORT extern const QString EDAM_BUSINESS_MARKETING_CODE_REGEX_PATTERN; +// Limits.thrift /** * The maximum number of Tags per Note */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_TAGS_MAX; +// Limits.thrift /** * The maximum number of Resources per Note */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_RESOURCES_MAX; +// Limits.thrift /** * Maximum number of Tags per account */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_TAGS_MAX; +// Limits.thrift /** * Maximum number of Tags per business account. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_BUSINESS_TAGS_MAX; +// Limits.thrift /** * Maximum number of SavedSearches per account */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_SAVED_SEARCHES_MAX; +// Limits.thrift /** * Maximum number of Notes per user */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_NOTES_MAX; +// Limits.thrift /** * Maximum number of Notes per business account */ QEVERCLOUD_EXPORT extern const qint32 EDAM_BUSINESS_NOTES_MAX; +// Limits.thrift /** * Maximum number of Notebooks per user */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_NOTEBOOKS_MAX; +// Limits.thrift /** * Maximum number of Workspaces per user */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_WORKSPACES_MAX; +// Limits.thrift /** * Maximum number of Notebooks in a business account */ QEVERCLOUD_EXPORT extern const qint32 EDAM_BUSINESS_NOTEBOOKS_MAX; +// Limits.thrift /** * Maximum number of Workspaces in a business account */ QEVERCLOUD_EXPORT extern const qint32 EDAM_BUSINESS_WORKSPACES_MAX; +// Limits.thrift /** * Maximum number of recent email addresses that are maintained * (see UserAttributes.recentMailedAddresses) */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_RECENT_MAILED_ADDRESSES_MAX; +// Limits.thrift /** * The number of emails of any type that can be sent by a user with a Free * account from the service per day. If an email is sent to two different @@ -562,6 +654,7 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_RECENT_MAILED_ADDRESSES_MAX; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_MAIL_LIMIT_DAILY_FREE; +// Limits.thrift /** * The number of emails of any type that can be sent by a user with a Premium * account from the service per day. If an email is sent to two different @@ -569,36 +662,42 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_MAIL_LIMIT_DAILY_FREE; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_MAIL_LIMIT_DAILY_PREMIUM; +// Limits.thrift /** * The number of bytes of new data that may be uploaded to a Free user's * account each month. */ QEVERCLOUD_EXPORT extern const qint64 EDAM_USER_UPLOAD_LIMIT_FREE; +// Limits.thrift /** * The number of bytes of new data that may be uploaded to a Premium user's * account each month. */ QEVERCLOUD_EXPORT extern const qint64 EDAM_USER_UPLOAD_LIMIT_PREMIUM; +// Limits.thrift /** * The number of bytes of new data that may be uploaded to new business * account during the first month. 50GB. */ QEVERCLOUD_EXPORT extern const qint64 EDAM_USER_UPLOAD_LIMIT_BUSINESS_FIRST_MONTH; +// Limits.thrift /** * The number of bytes of new data that may be uploaded to a business * account for the next month. 20GB. */ QEVERCLOUD_EXPORT extern const qint64 EDAM_USER_UPLOAD_LIMIT_BUSINESS_NEXT_MONTH; +// Limits.thrift /** * The number of bytes of new data that may be uploaded each month to an account at * a Plus service level. */ QEVERCLOUD_EXPORT extern const qint64 EDAM_USER_UPLOAD_LIMIT_PLUS; +// Limits.thrift /** * The number of bytes of new data uploaded in a monthly quota cycle at which point * users should be prompted with a survey to gather information on how they are using @@ -606,6 +705,7 @@ QEVERCLOUD_EXPORT extern const qint64 EDAM_USER_UPLOAD_LIMIT_PLUS; */ QEVERCLOUD_EXPORT extern const qint64 EDAM_USER_UPLOAD_SURVEY_THRESHOLD; +// Limits.thrift /** * The number of bytes of new data that may be uploaded to a Business user's * personal account each month. Note that content uploaded into the Business @@ -613,6 +713,7 @@ QEVERCLOUD_EXPORT extern const qint64 EDAM_USER_UPLOAD_SURVEY_THRESHOLD; */ QEVERCLOUD_EXPORT extern const qint64 EDAM_USER_UPLOAD_LIMIT_BUSINESS; +// Limits.thrift /** * The number of bytes of new data that may be uploaded to a Business for each * member of the business per month. The total bytes available can be determined @@ -620,6 +721,7 @@ QEVERCLOUD_EXPORT extern const qint64 EDAM_USER_UPLOAD_LIMIT_BUSINESS; */ QEVERCLOUD_EXPORT extern const qint64 EDAM_USER_UPLOAD_LIMIT_BUSINESS_PER_USER; +// Limits.thrift /** * Maximum total size of a Note that can be added to a Free account. * The size of a note is calculated as: @@ -628,6 +730,7 @@ QEVERCLOUD_EXPORT extern const qint64 EDAM_USER_UPLOAD_LIMIT_BUSINESS_PER_USER; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_SIZE_MAX_FREE; +// Limits.thrift /** * Maximum total size of a Note that can be added to a Premium account. * The size of a note is calculated as: @@ -636,22 +739,26 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_SIZE_MAX_FREE; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_SIZE_MAX_PREMIUM; +// Limits.thrift /** * Maximum size of a resource, in bytes, for Free accounts */ QEVERCLOUD_EXPORT extern const qint32 EDAM_RESOURCE_SIZE_MAX_FREE; +// Limits.thrift /** * Maximum size of a resource, in bytes, for Premium accounts */ QEVERCLOUD_EXPORT extern const qint32 EDAM_RESOURCE_SIZE_MAX_PREMIUM; +// Limits.thrift /** * Maximum number of linked notebooks per account, for a free * account. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_LINKED_NOTEBOOK_MAX; +// Limits.thrift /** * Maximum number of linked notebooks per account, for a premium * account. Users who are part of an active business are also @@ -659,42 +766,50 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_LINKED_NOTEBOOK_MAX; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_LINKED_NOTEBOOK_MAX_PREMIUM; +// Limits.thrift /** * Maximum number of shared notebooks per business notebook */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTEBOOK_BUSINESS_SHARED_NOTEBOOK_MAX; +// Limits.thrift /** * Maximum number of shared notebooks per personal notebook */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTEBOOK_PERSONAL_SHARED_NOTEBOOK_MAX; +// Limits.thrift /** * Maximum number of SharedNote records per business note */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_BUSINESS_SHARED_NOTE_MAX; +// Limits.thrift /** * Maximum number of SharedNote records per personal note */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_PERSONAL_SHARED_NOTE_MAX; +// Limits.thrift /** * The minimum length of the content class attribute of a note. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_CONTENT_CLASS_LEN_MIN; +// Limits.thrift /** * The maximum length of the content class attribute of a note. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_CONTENT_CLASS_LEN_MAX; +// Limits.thrift /** * The regular expression that the content class of a note must match * to be valid. */ QEVERCLOUD_EXPORT extern const QString EDAM_NOTE_CONTENT_CLASS_REGEX; +// Limits.thrift /** * The content class prefix used for all notes created by Evernote Hello. * This prefix can be used to assemble individual content class strings, @@ -704,6 +819,7 @@ QEVERCLOUD_EXPORT extern const QString EDAM_NOTE_CONTENT_CLASS_REGEX; */ QEVERCLOUD_EXPORT extern const QString EDAM_HELLO_APP_CONTENT_CLASS_PREFIX; +// Limits.thrift /** * The content class prefix used for all notes created by Evernote Food. * This prefix can be used to assemble individual content class strings, @@ -713,6 +829,7 @@ QEVERCLOUD_EXPORT extern const QString EDAM_HELLO_APP_CONTENT_CLASS_PREFIX; */ QEVERCLOUD_EXPORT extern const QString EDAM_FOOD_APP_CONTENT_CLASS_PREFIX; +// Limits.thrift /** * The content class prefix used for structured notes created by Evernote * Hello that represents an encounter with a person. When performing a @@ -721,6 +838,7 @@ QEVERCLOUD_EXPORT extern const QString EDAM_FOOD_APP_CONTENT_CLASS_PREFIX; */ QEVERCLOUD_EXPORT extern const QString EDAM_CONTENT_CLASS_HELLO_ENCOUNTER; +// Limits.thrift /** * The content class prefix used for structured notes created by Evernote * Hello that represents the user's profile. When performing a @@ -729,6 +847,7 @@ QEVERCLOUD_EXPORT extern const QString EDAM_CONTENT_CLASS_HELLO_ENCOUNTER; */ QEVERCLOUD_EXPORT extern const QString EDAM_CONTENT_CLASS_HELLO_PROFILE; +// Limits.thrift /** * The content class prefix used for structured notes created by * Evernote Food that captures the experience of a particular meal. @@ -737,6 +856,7 @@ QEVERCLOUD_EXPORT extern const QString EDAM_CONTENT_CLASS_HELLO_PROFILE; */ QEVERCLOUD_EXPORT extern const QString EDAM_CONTENT_CLASS_FOOD_MEAL; +// Limits.thrift /** * The content class prefix used for structured notes created by Evernote * Skitch. When performing a wildcard search via filtered sync chunks @@ -744,18 +864,21 @@ QEVERCLOUD_EXPORT extern const QString EDAM_CONTENT_CLASS_FOOD_MEAL; */ QEVERCLOUD_EXPORT extern const QString EDAM_CONTENT_CLASS_SKITCH_PREFIX; +// Limits.thrift /** * The content class value used for structured image notes created by Evernote * Skitch. */ QEVERCLOUD_EXPORT extern const QString EDAM_CONTENT_CLASS_SKITCH; +// Limits.thrift /** * The content class value used for structured PDF notes created by Evernote * Skitch. */ QEVERCLOUD_EXPORT extern const QString EDAM_CONTENT_CLASS_SKITCH_PDF; +// Limits.thrift /** * The content class prefix used for structured notes created by Evernote * Penultimate. When performing a wildcard search via filtered sync chunks @@ -763,65 +886,76 @@ QEVERCLOUD_EXPORT extern const QString EDAM_CONTENT_CLASS_SKITCH_PDF; */ QEVERCLOUD_EXPORT extern const QString EDAM_CONTENT_CLASS_PENULTIMATE_PREFIX; +// Limits.thrift /** * The content class value used for structured notes created by Evernote * Penultimate that represents a Penultimate notebook. */ QEVERCLOUD_EXPORT extern const QString EDAM_CONTENT_CLASS_PENULTIMATE_NOTEBOOK; +// Limits.thrift /** * The NoteAttributes.sourceApplication value used for notes captured by the Post-it * camera. */ QEVERCLOUD_EXPORT extern const QString EDAM_SOURCE_APPLICATION_POSTIT; +// Limits.thrift /** * The NoteAttributes.sourceApplication value used for notes captured by the Moleskine * page camera. */ QEVERCLOUD_EXPORT extern const QString EDAM_SOURCE_APPLICATION_MOLESKINE; +// Limits.thrift /** * The NoteAttributes.sourceApplication value used for notes captured by * PFU ScanSnap Evernote Edition. */ QEVERCLOUD_EXPORT extern const QString EDAM_SOURCE_APPLICATION_EN_SCANSNAP; +// Limits.thrift /** * The NoteAttributes.sourceApplication value used for notes captured with the Embedded * Web Clipper. */ QEVERCLOUD_EXPORT extern const QString EDAM_SOURCE_APPLICATION_EWC; +// Limits.thrift /** * The NoteAttributes.sourceApplication value used for notes captured with the Android * share extension. */ QEVERCLOUD_EXPORT extern const QString EDAM_SOURCE_APPLICATION_ANDROID_SHARE_EXTENSION; +// Limits.thrift /** * The NoteAttributes.sourceApplication value used for notes captured with the iOS share * extension. */ QEVERCLOUD_EXPORT extern const QString EDAM_SOURCE_APPLICATION_IOS_SHARE_EXTENSION; +// Limits.thrift /** * The NoteAttributes.sourceApplication value used for notes captured with the Evernote * Web Clipper. */ QEVERCLOUD_EXPORT extern const QString EDAM_SOURCE_APPLICATION_WEB_CLIPPER; +// Limits.thrift /** * The NoteAttributes.source value used for notes captured by the Microsoft Outlook clipper. */ QEVERCLOUD_EXPORT extern const QString EDAM_SOURCE_OUTLOOK_CLIPPER; +// Limits.thrift /** * A NoteAttributes.noteTitleQuality value indicating that a note has no meaningful title, * only a placeholder value such as "Untitled Note". */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_TITLE_QUALITY_UNTITLED; +// Limits.thrift /** * A NoteAttributes.noteTitleQuality value indicating that the quality of an automatically * generated note title is low. Examples of low quality titles include those based on a @@ -829,6 +963,7 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_TITLE_QUALITY_UNTITLED; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_TITLE_QUALITY_LOW; +// Limits.thrift /** * A NoteAttributes.noteTitleQuality value indicating that the quality of an automatically * generated note title is medium. Examples of medium quality titles include those based on a @@ -836,6 +971,7 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_TITLE_QUALITY_LOW; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_TITLE_QUALITY_MEDIUM; +// Limits.thrift /** * A NoteAttributes.noteTitleQuality value indicating that the quality of an automatically * generated note title is high. Examples of high quality titles include those based on a @@ -843,58 +979,68 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_TITLE_QUALITY_MEDIUM; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_TITLE_QUALITY_HIGH; +// Limits.thrift /** * The minimum length of the plain text in a findRelated query, assuming that * plaintext is being provided. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_RELATED_PLAINTEXT_LEN_MIN; +// Limits.thrift /** * The maximum length of the plain text in a findRelated query, assuming that * plaintext is being provided. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_RELATED_PLAINTEXT_LEN_MAX; +// Limits.thrift /** * The maximum number of notes that will be returned from a findRelated() * query. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_RELATED_MAX_NOTES; +// Limits.thrift /** * The maximum number of notebooks that will be returned from a findRelated() * query. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_RELATED_MAX_NOTEBOOKS; +// Limits.thrift /** * The maximum number of tags that will be returned from a findRelated() query. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_RELATED_MAX_TAGS; +// Limits.thrift /** * The maximum number of experts that will be returned from a findRelated() query */ QEVERCLOUD_EXPORT extern const qint32 EDAM_RELATED_MAX_EXPERTS; +// Limits.thrift /** * The maximum number of related content snippets that will be returned from a * findRelated() query. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_RELATED_MAX_RELATED_CONTENT; +// Limits.thrift /** * The minimum length, in Unicode characters, of a description for a business * notebook. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_BUSINESS_NOTEBOOK_DESCRIPTION_LEN_MIN; +// Limits.thrift /** * The maximum length, in Unicode characters, of a description for a business * notebook. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_BUSINESS_NOTEBOOK_DESCRIPTION_LEN_MAX; +// Limits.thrift /** * All business notebook descriptions must match this pattern. * This excludes control chars or line/paragraph separators. @@ -902,42 +1048,50 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_BUSINESS_NOTEBOOK_DESCRIPTION_LEN_MAX */ QEVERCLOUD_EXPORT extern const QString EDAM_BUSINESS_NOTEBOOK_DESCRIPTION_REGEX; +// Limits.thrift /** * The maximum length of a business phone number. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_BUSINESS_PHONE_NUMBER_LEN_MAX; +// Limits.thrift /** * Minimum length of a preference name */ QEVERCLOUD_EXPORT extern const qint32 EDAM_PREFERENCE_NAME_LEN_MIN; +// Limits.thrift /** * Maximum length of a preference name */ QEVERCLOUD_EXPORT extern const qint32 EDAM_PREFERENCE_NAME_LEN_MAX; +// Limits.thrift /** * Minimum length of a preference value */ QEVERCLOUD_EXPORT extern const qint32 EDAM_PREFERENCE_VALUE_LEN_MIN; +// Limits.thrift /** * Maximum length of a preference value */ QEVERCLOUD_EXPORT extern const qint32 EDAM_PREFERENCE_VALUE_LEN_MAX; +// Limits.thrift /** * Maximum number of name/value pairs allowed */ QEVERCLOUD_EXPORT extern const qint32 EDAM_MAX_PREFERENCES; +// Limits.thrift /** * Maximum number of values per preference name when using * values of size no greater than EDAM_PREFERENCE_VALUE_LEN_MAX. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_MAX_VALUES_PER_PREFERENCE; +// Limits.thrift /** * The maximum length of a preference value if you only use one value * per preference rather than up to EDAM_MAX_VALUES_PER_PREFERENCE. @@ -947,28 +1101,33 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_MAX_VALUES_PER_PREFERENCE; */ QEVERCLOUD_EXPORT extern const qint32 EDAM_PREFERENCE_ONLY_ONE_VALUE_LEN_MAX; +// Limits.thrift /** * A preference name must match this regex. */ QEVERCLOUD_EXPORT extern const QString EDAM_PREFERENCE_NAME_REGEX; +// Limits.thrift /** * A preference value must match this regex if you are using more * than a single value for a preference. */ QEVERCLOUD_EXPORT extern const QString EDAM_PREFERENCE_VALUE_REGEX; +// Limits.thrift /** * A preference value must match this regex if you are using a single * value for a preference. */ QEVERCLOUD_EXPORT extern const QString EDAM_PREFERENCE_ONLY_ONE_VALUE_REGEX; +// Limits.thrift /** * The name of the preferences entry that contains shortcuts. */ QEVERCLOUD_EXPORT extern const QString EDAM_PREFERENCE_SHORTCUTS; +// Limits.thrift /** * The name of the preferences entry that contains the notebook GUID (not the linked notebook) of * the default business notebook. It must be in the format EDAM_GUID_REGEX. @@ -981,6 +1140,7 @@ QEVERCLOUD_EXPORT extern const QString EDAM_PREFERENCE_SHORTCUTS; */ QEVERCLOUD_EXPORT extern const QString EDAM_PREFERENCE_BUSINESS_DEFAULT_NOTEBOOK; +// Limits.thrift /** * The name of the preferences entry that contains a boolean indicating that default * quicknotes should go into a business notebook. The EDAM_PREFERENCE_BUSINESS_DEFAULT_NOTEBOOK @@ -997,145 +1157,172 @@ QEVERCLOUD_EXPORT extern const QString EDAM_PREFERENCE_BUSINESS_DEFAULT_NOTEBOOK */ QEVERCLOUD_EXPORT extern const QString EDAM_PREFERENCE_BUSINESS_QUICKNOTE; +// Limits.thrift /** * The maximum number of shortcuts that a user may have. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_PREFERENCE_SHORTCUTS_MAX_VALUES; +// Limits.thrift /** * Maximum length of the device identifier string associated with long sessions. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_DEVICE_ID_LEN_MAX; +// Limits.thrift /** * Regular expression for device identifier strings associated with long sessions. */ QEVERCLOUD_EXPORT extern const QString EDAM_DEVICE_ID_REGEX; +// Limits.thrift /** * Maximum length of the device description string associated with long sessions. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_DEVICE_DESCRIPTION_LEN_MAX; +// Limits.thrift /** * Regular expression for device description strings associated with long sessions. */ QEVERCLOUD_EXPORT extern const QString EDAM_DEVICE_DESCRIPTION_REGEX; +// Limits.thrift /** * Maximum number of search suggestions that can be returned */ QEVERCLOUD_EXPORT extern const qint32 EDAM_SEARCH_SUGGESTIONS_MAX; +// Limits.thrift /** * Maximum length of the search suggestion prefix */ QEVERCLOUD_EXPORT extern const qint32 EDAM_SEARCH_SUGGESTIONS_PREFIX_LEN_MAX; +// Limits.thrift /** * Minimum length of the search suggestion prefix */ QEVERCLOUD_EXPORT extern const qint32 EDAM_SEARCH_SUGGESTIONS_PREFIX_LEN_MIN; +// Limits.thrift /** * Default maximum number of results the service will return for findContact */ QEVERCLOUD_EXPORT extern const qint32 EDAM_FIND_CONTACT_DEFAULT_MAX_RESULTS; +// Limits.thrift /** * Absolute maximum number of results the service will return for findContact */ QEVERCLOUD_EXPORT extern const qint32 EDAM_FIND_CONTACT_MAX_RESULTS; +// Limits.thrift /** * The maximum number of separate notes that may be queried in a single call to * NoteStore.getViewersForNotes. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_NOTE_LOCK_VIEWERS_NOTES_MAX; +// Limits.thrift /** * Absolute maximum number of results the servce will return for PersistentInternalMarket.getOrders() */ QEVERCLOUD_EXPORT extern const qint32 EDAM_GET_ORDERS_MAX_RESULTS; +// Limits.thrift /** * The maximum length of a message body in unicode characters. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_MESSAGE_BODY_LEN_MAX; +// Limits.thrift /** * The regex to validate message.body against */ QEVERCLOUD_EXPORT extern const QString EDAM_MESSAGE_BODY_REGEX; +// Limits.thrift /** * The maximum number of recipients on a MessageThread. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_MESSAGE_RECIPIENTS_MAX; +// Limits.thrift /** * The maximum number of attachments a Message can have. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_MESSAGE_ATTACHMENTS_MAX; +// Limits.thrift /** * The maximum length of a message attachment title in unicode characters. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_MESSAGE_ATTACHMENT_TITLE_LEN_MAX; +// Limits.thrift /** * The regex to validate message attachment titles against */ QEVERCLOUD_EXPORT extern const QString EDAM_MESSAGE_ATTACHMENT_TITLE_REGEX; +// Limits.thrift /** * The maximum length of a message attachment snippet in unicode characters. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_MESSAGE_ATTACHMENT_SNIPPET_LEN_MAX; +// Limits.thrift /** * The regex to validate message attachment snippets against */ QEVERCLOUD_EXPORT extern const QString EDAM_MESSAGE_ATTACHMENT_SNIPPET_REGEX; +// Limits.thrift /** * Maximum user profile photo size, in bytes, that clients may send to the service. * Photos may be resized before being stored on the service. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_USER_PROFILE_PHOTO_MAX_BYTES; +// Limits.thrift /** * The maximum length of a promotion ID in unicode characters. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_PROMOTION_ID_LEN_MAX; +// Limits.thrift /** * The regex to validate promotion IDs against. */ QEVERCLOUD_EXPORT extern const QString EDAM_PROMOTION_ID_REGEX; +// Limits.thrift /** App Feedback Rating range */ QEVERCLOUD_EXPORT extern const qint16 EDAM_APP_RATING_MIN; +// Limits.thrift QEVERCLOUD_EXPORT extern const qint16 EDAM_APP_RATING_MAX; +// Limits.thrift /** * The maximium number of note snippets you can retrieve in a single request */ QEVERCLOUD_EXPORT extern const qint32 EDAM_SNIPPETS_NOTES_MAX; +// Limits.thrift /** * The maximum number of connected identities a client can request. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_CONNECTED_IDENTITY_REQUEST_MAX; +// Limits.thrift /** * Maximum length for OpenID token. There is no official enforced limit. The length of the Token ID depends * on the provider. 1000 seems to be the safest value at this time. */ QEVERCLOUD_EXPORT extern const qint32 EDAM_OPEN_ID_ACCESS_TOKEN_MAX; - // Types.thrift /** * A value for the "recipe" key in the "classifications" map in NoteAttributes @@ -1143,43 +1330,48 @@ QEVERCLOUD_EXPORT extern const qint32 EDAM_OPEN_ID_ACCESS_TOKEN_MAX; */ QEVERCLOUD_EXPORT extern const QString CLASSIFICATION_RECIPE_USER_NON_RECIPE; +// Types.thrift /** * A value for the "recipe" key in the "classifications" map in NoteAttributes * that indicates the user has classified a note as being a recipe. */ QEVERCLOUD_EXPORT extern const QString CLASSIFICATION_RECIPE_USER_RECIPE; +// Types.thrift /** * A value for the "recipe" key in the "classifications" map in NoteAttributes * that indicates the Evernote service has classified a note as being a recipe. */ QEVERCLOUD_EXPORT extern const QString CLASSIFICATION_RECIPE_SERVICE_RECIPE; +// Types.thrift /** * Standardized value for the 'source' NoteAttribute for notes that * were clipped from the web in some manner. */ QEVERCLOUD_EXPORT extern const QString EDAM_NOTE_SOURCE_WEB_CLIP; +// Types.thrift /** * Standardized value for the 'source' NoteAttribute for notes that * were clipped using the "simplified article" function of the clipper. */ QEVERCLOUD_EXPORT extern const QString EDAM_NOTE_SOURCE_WEB_CLIP_SIMPLIFIED; +// Types.thrift /** * Standardized value for the 'source' NoteAttribute for notes that * were clipped from an email message. */ QEVERCLOUD_EXPORT extern const QString EDAM_NOTE_SOURCE_MAIL_CLIP; +// Types.thrift /** * Standardized value for the 'source' NoteAttribute for notes that * were created via email sent to Evernote's email interface. */ QEVERCLOUD_EXPORT extern const QString EDAM_NOTE_SOURCE_MAIL_SMTP_GATEWAY; - // UserStore.thrift /** * The major version number for the current revision of the EDAM protocol. @@ -1188,6 +1380,7 @@ QEVERCLOUD_EXPORT extern const QString EDAM_NOTE_SOURCE_MAIL_SMTP_GATEWAY; */ QEVERCLOUD_EXPORT extern const qint16 EDAM_VERSION_MAJOR; +// UserStore.thrift /** * The minor version number for the current revision of the EDAM protocol. * Clients pass this to the service using UserStore.checkVersion at the diff --git a/src/qevercloud/QEverCloud/headers/generated/EDAMErrorCode.h b/src/qevercloud/QEverCloud/headers/generated/EDAMErrorCode.h index 4ceef164..79c15f0a 100644 --- a/src/qevercloud/QEverCloud/headers/generated/EDAMErrorCode.h +++ b/src/qevercloud/QEverCloud/headers/generated/EDAMErrorCode.h @@ -1,21 +1,36 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: * https://opensource.org/licenses/MIT * * This file was generated from Evernote Thrift API */ - #ifndef QEVERCLOUD_GENERATED_EDAMERRORCODE_H #define QEVERCLOUD_GENERATED_EDAMERRORCODE_H -#include "../export.h" +#include "../Export.h" + +#include "../Helpers.h" +#include +#include +#include namespace qevercloud { +//////////////////////////////////////////////////////////////////////////////// + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_NAMESPACE +#endif +#endif + +//////////////////////////////////////////////////////////////////////////////// + /** * Numeric codes indicating the type of error that occurred on the * service. @@ -86,50 +101,1035 @@ namespace qevercloud { * using a different email address. *
ACCOUNT_CLEAR
*
The user's account has been disabled. Clients should deal with this errorCode - * by logging the user out and purging all locally saved content, including local - * edits not yet pushed to the server.
+ * by logging the user out and purging all locally saved content, including local + * edits not yet pushed to the server. *
SSO_AUTHENTICATION_REQUIRED
- *
SSO authentication is the only type of authentication allowed for the user's - * account. This error is thrown when the user attempts to authenticate by another - * method (password, OpenId, etc).
- * - */ -struct QEVERCLOUD_EXPORT EDAMErrorCode -{ - enum type - { - UNKNOWN = 1, - BAD_DATA_FORMAT = 2, - PERMISSION_DENIED = 3, - INTERNAL_ERROR = 4, - DATA_REQUIRED = 5, - LIMIT_REACHED = 6, - QUOTA_REACHED = 7, - INVALID_AUTH = 8, - AUTH_EXPIRED = 9, - DATA_CONFLICT = 10, - ENML_VALIDATION = 11, - SHARD_UNAVAILABLE = 12, - LEN_TOO_SHORT = 13, - LEN_TOO_LONG = 14, - TOO_FEW = 15, - TOO_MANY = 16, - UNSUPPORTED_OPERATION = 17, - TAKEN_DOWN = 18, - RATE_LIMIT_REACHED = 19, - BUSINESS_SECURITY_LOGIN_REQUIRED = 20, - DEVICE_LIMIT_REACHED = 21, - OPENID_ALREADY_TAKEN = 22, - INVALID_OPENID_TOKEN = 23, - USER_NOT_ASSOCIATED = 24, - USER_NOT_REGISTERED = 25, - USER_ALREADY_ASSOCIATED = 26, - ACCOUNT_CLEAR = 27, - SSO_AUTHENTICATION_REQUIRED = 28 - }; + *
SSO authentication is the only type of authentication allowed for the user's + * account. This error is thrown when the user attempts to authenticate by another + * method (password, OpenId, etc).
+ * + */ +enum class EDAMErrorCode +{ + UNKNOWN = 1, + BAD_DATA_FORMAT = 2, + PERMISSION_DENIED = 3, + INTERNAL_ERROR = 4, + DATA_REQUIRED = 5, + LIMIT_REACHED = 6, + QUOTA_REACHED = 7, + INVALID_AUTH = 8, + AUTH_EXPIRED = 9, + DATA_CONFLICT = 10, + ENML_VALIDATION = 11, + SHARD_UNAVAILABLE = 12, + LEN_TOO_SHORT = 13, + LEN_TOO_LONG = 14, + TOO_FEW = 15, + TOO_MANY = 16, + UNSUPPORTED_OPERATION = 17, + TAKEN_DOWN = 18, + RATE_LIMIT_REACHED = 19, + BUSINESS_SECURITY_LOGIN_REQUIRED = 20, + DEVICE_LIMIT_REACHED = 21, + OPENID_ALREADY_TAKEN = 22, + INVALID_OPENID_TOKEN = 23, + USER_NOT_ASSOCIATED = 24, + USER_NOT_REGISTERED = 25, + USER_ALREADY_ASSOCIATED = 26, + ACCOUNT_CLEAR = 27, + SSO_AUTHENTICATION_REQUIRED = 28 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(EDAMErrorCode) +#endif +#endif + +inline uint qHash(EDAMErrorCode value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const EDAMErrorCode value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const EDAMErrorCode value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * An enumeration that provides a reason for why a given contact was invalid, for example, + * as thrown via an EDAMInvalidContactsException. + * + *
+ *
BAD_ADDRESS
+ *
The contact information does not represent a valid address for a recipient. + * Clients should be validating and normalizing contacts, so receiving this + * error code commonly represents a client error. + *
+ *
DUPLICATE_CONTACT
+ *
If the method throwing this exception accepts a list of contacts, this error + * code indicates that the given contact is a duplicate of another contact in + * the list. Note that the server may clean up contacts, and that this cleanup + * occurs before checking for duplication. Receiving this error is commonly + * an indication of a client issue, since client should be normalizing contacts + * and removing duplicates. All instances that are duplicates are returned. For + * example, if a list of 5 contacts has the same e-mail address twice, the two + * conflicting e-mail address contacts will be returned. + *
+ *
NO_CONNECTION
+ *
Indicates that the given contact, an Evernote type contact, is not connected + * to the user for which the call is being made. It is possible that clients are + * out of sync with the server and should re-synchronize their identities and + * business user state. See Identity.userConnected for more information on user + * connections. + *
+ *
+ * + * Note that if multiple reasons may apply, only one is returned. The precedence order + * is BAD_ADDRESS, DUPLICATE_CONTACT, NO_CONNECTION, meaning that if a contact has a bad + * address and is also duplicated, it will be returned as a BAD_ADDRESS. + */ +enum class EDAMInvalidContactReason +{ + BAD_ADDRESS, + DUPLICATE_CONTACT, + NO_CONNECTION +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(EDAMInvalidContactReason) +#endif +#endif + +inline uint qHash(EDAMInvalidContactReason value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const EDAMInvalidContactReason value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const EDAMInvalidContactReason value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Privilege levels for accessing shared notebooks. + * + * READ_NOTEBOOK: Recipient is able to read the contents of the shared notebook + * but does not have access to information about other recipients of the + * notebook or the activity stream information. + * + * READ_NOTEBOOK_PLUS_ACTIVITY: Recipient has READ_NOTEBOOK rights and can also + * access information about other recipients and the activity stream. + * + * MODIFY_NOTEBOOK_PLUS_ACTIVITY: Recipient has rights to read and modify the contents + * of the shared notebook, including the right to move notes to the trash and to create + * notes in the notebook. The recipient can also access information about other + * recipients and the activity stream. + * + * FULL_ACCESS: Recipient has full rights to the shared notebook and recipient lists, + * including privilege to revoke and create invitations and to change privilege + * levels on invitations for individuals. If the user is a member of the same group, + * (e.g. the same business) as the shared notebook, they will additionally be granted + * permissions to update the publishing status of the notebook. + */ +enum class ShareRelationshipPrivilegeLevel +{ + READ_NOTEBOOK = 0, + READ_NOTEBOOK_PLUS_ACTIVITY = 10, + MODIFY_NOTEBOOK_PLUS_ACTIVITY = 20, + FULL_ACCESS = 30 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(ShareRelationshipPrivilegeLevel) +#endif +#endif + +inline uint qHash(ShareRelationshipPrivilegeLevel value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const ShareRelationshipPrivilegeLevel value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const ShareRelationshipPrivilegeLevel value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * This enumeration defines the possible permission levels for a user. + * Free accounts will have a level of NORMAL and paid Premium accounts + * will have a level of PREMIUM. + */ +enum class PrivilegeLevel +{ + NORMAL = 1, + PREMIUM = 3, + VIP = 5, + MANAGER = 7, + SUPPORT = 8, + ADMIN = 9 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(PrivilegeLevel) +#endif +#endif + +inline uint qHash(PrivilegeLevel value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const PrivilegeLevel value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const PrivilegeLevel value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * This enumeration defines the possible tiers of service that a user may have. A + * ServiceLevel of BUSINESS signifies a business-only account, which can never be any + * other ServiceLevel. + */ +enum class ServiceLevel +{ + BASIC = 1, + PLUS = 2, + PREMIUM = 3, + BUSINESS = 4 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(ServiceLevel) +#endif +#endif + +inline uint qHash(ServiceLevel value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const ServiceLevel value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const ServiceLevel value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Every search query is specified as a sequence of characters. + * Currently, only the USER query format is supported. + */ +enum class QueryFormat +{ + USER = 1, + SEXP = 2 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(QueryFormat) +#endif +#endif + +inline uint qHash(QueryFormat value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const QueryFormat value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const QueryFormat value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * This enumeration defines the possible sort ordering for notes when + * they are returned from a search result. + */ +enum class NoteSortOrder +{ + CREATED = 1, + UPDATED = 2, + RELEVANCE = 3, + UPDATE_SEQUENCE_NUMBER = 4, + TITLE = 5 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(NoteSortOrder) +#endif +#endif + +inline uint qHash(NoteSortOrder value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const NoteSortOrder value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const NoteSortOrder value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * This enumeration defines the possible states of a premium account + * + * NONE: the user has never attempted to become a premium subscriber + * + * PENDING: the user has requested a premium account but their charge has not + * been confirmed + * + * ACTIVE: the user has been charged and their premium account is in good + * standing + * + * FAILED: the system attempted to charge the was denied. We will periodically attempt to + * re-validate their order. + * + * CANCELLATION_PENDING: the user has requested that no further charges be made + * but the current account is still active. + * + * CANCELED: the premium account was canceled either because of failure to pay + * or user cancelation. No more attempts will be made to activate the account. + */ +enum class PremiumOrderStatus +{ + NONE = 0, + PENDING = 1, + ACTIVE = 2, + FAILED = 3, + CANCELLATION_PENDING = 4, + CANCELED = 5 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(PremiumOrderStatus) +#endif +#endif + +inline uint qHash(PremiumOrderStatus value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const PremiumOrderStatus value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const PremiumOrderStatus value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Privilege levels for accessing shared notebooks. + * + * Note that as of 2014-04, FULL_ACCESS is synonymous with BUSINESS_FULL_ACCESS. If a + * user is a member of a business and has FULL_ACCESS privileges, then they will + * automatically be granted BUSINESS_FULL_ACCESS for notebooks in their business. This + * will happen implicitly when they attempt to access the corresponding notebooks of + * the business. BUSINESS_FULL_ACCESS is therefore deprecated. + * + * READ_NOTEBOOK: Recipient is able to read the contents of the shared notebook + * but does not have access to information about other recipients of the + * notebook or the activity stream information. + * + * MODIFY_NOTEBOOK_PLUS_ACTIVITY: Recipient has rights to read and modify the contents + * of the shared notebook, including the right to move notes to the trash and to create + * notes in the notebook. The recipient can also access information about other + * recipients and the activity stream. + * + * READ_NOTEBOOK_PLUS_ACTIVITY: Recipient has READ_NOTEBOOK rights and can also + * access information about other recipients and the activity stream. + * + * GROUP: If the user belongs to a group, such as a Business, that has a defined + * privilege level, use the privilege level of the group as the privilege for + * the individual. + * + * FULL_ACCESS: Recipient has full rights to the shared notebook and recipient lists, + * including privilege to revoke and create invitations and to change privilege + * levels on invitations for individuals. For members of a business, FULL_ACCESS + * privilege on business notebooks also grants the ability to change how the notebook + * will appear when shared with the business, including the rights to share and + * unshare the notebook with the business. + * + * BUSINESS_FULL_ACCESS: Deprecated. See the note above about BUSINESS_FULL_ACCESS and + * FULL_ACCESS being synonymous. + */ +enum class SharedNotebookPrivilegeLevel +{ + READ_NOTEBOOK = 0, + MODIFY_NOTEBOOK_PLUS_ACTIVITY = 1, + READ_NOTEBOOK_PLUS_ACTIVITY = 2, + GROUP = 3, + FULL_ACCESS = 4, + BUSINESS_FULL_ACCESS = 5 }; +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(SharedNotebookPrivilegeLevel) +#endif +#endif + +inline uint qHash(SharedNotebookPrivilegeLevel value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const SharedNotebookPrivilegeLevel value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const SharedNotebookPrivilegeLevel value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Privilege levels for accessing a shared note. All privilege levels convey "activity feed" access, + * which allows the recipient to access information about other recipients and the activity stream. + * + * READ_NOTE: Recipient has rights to read the shared note. + * + * MODIFY_NOTE: Recipient has all of the rights of READ_NOTE, plus rights to modify the shared + * note's content, title and resources. Other fields, including the notebook, tags and metadata, + * may not be modified. + * + * FULL_ACCESS: Recipient has all of the rights of MODIFY_NOTE, plus rights to share the note with + * other users via email, public note links, and note sharing. Recipient may also update and + * remove other recipient's note sharing rights. + */ +enum class SharedNotePrivilegeLevel +{ + READ_NOTE = 0, + MODIFY_NOTE = 1, + FULL_ACCESS = 2 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(SharedNotePrivilegeLevel) +#endif +#endif + +inline uint qHash(SharedNotePrivilegeLevel value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const SharedNotePrivilegeLevel value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const SharedNotePrivilegeLevel value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Enumeration of the roles that a User can have within a sponsored group. + * + * GROUP_MEMBER: The user is a member of the group with no special privileges. + * + * GROUP_ADMIN: The user is an administrator within the group. + * + * GROUP_OWNER: The user is the owner of the group. + */ +enum class SponsoredGroupRole +{ + GROUP_MEMBER = 1, + GROUP_ADMIN = 2, + GROUP_OWNER = 3 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(SponsoredGroupRole) +#endif +#endif + +inline uint qHash(SponsoredGroupRole value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const SponsoredGroupRole value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const SponsoredGroupRole value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Enumeration of the roles that a User can have within an Evernote Business account. + * + * ADMIN: The user is an administrator of the Evernote Business account. + * + * NORMAL: The user is a regular user within the Evernote Business account. + */ +enum class BusinessUserRole +{ + ADMIN = 1, + NORMAL = 2 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(BusinessUserRole) +#endif +#endif + +inline uint qHash(BusinessUserRole value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const BusinessUserRole value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const BusinessUserRole value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * The BusinessUserStatus indicates the status of the user in the business. + * + * A BusinessUser will typically start as ACTIVE. + * Only ACTIVE users can authenticate to the Business. + * + *
+ *
ACTIVE
+ *
The business user can authenticate to and access the business.
+ *
DEACTIVATED
+ *
The business user has been deactivated and cannot access the business
+ *
+ */ +enum class BusinessUserStatus +{ + ACTIVE = 1, + DEACTIVATED = 2 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(BusinessUserStatus) +#endif +#endif + +inline uint qHash(BusinessUserStatus value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const BusinessUserStatus value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const BusinessUserStatus value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * An enumeration describing restrictions on the domain of shared notebook + * instances that are valid for a given operation, as used, for example, in + * NotebookRestrictions. + * + * ASSIGNED: The domain consists of shared notebooks that belong, or are assigned, + * to the recipient. + * + * NO_SHARED_NOTEBOOKS: No shared notebooks are applicable to the operation. + */ +enum class SharedNotebookInstanceRestrictions +{ + ASSIGNED = 1, + NO_SHARED_NOTEBOOKS = 2 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(SharedNotebookInstanceRestrictions) +#endif +#endif + +inline uint qHash(SharedNotebookInstanceRestrictions value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const SharedNotebookInstanceRestrictions value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const SharedNotebookInstanceRestrictions value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * An enumeration describing the configuration state related to receiving + * reminder e-mails from the service. Reminder e-mails summarize notes + * based on their Note.attributes.reminderTime values. + * + * DO_NOT_SEND: The user has selected to not receive reminder e-mail. + * + * SEND_DAILY_EMAIL: The user has selected to receive reminder e-mail for those + * days when there is a reminder. + */ +enum class ReminderEmailConfig +{ + DO_NOT_SEND = 1, + SEND_DAILY_EMAIL = 2 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(ReminderEmailConfig) +#endif +#endif + +inline uint qHash(ReminderEmailConfig value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const ReminderEmailConfig value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const ReminderEmailConfig value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * An enumeration defining the possible states of a BusinessInvitation. + * + * APPROVED: The invitation was created or approved by a business admin and may be redeemed by the + * invited email. + * + * REQUESTED: The invitation was requested by a non-admin member of the business and must be + * approved by an admin before it may be redeemed. Invitations in this state do not count + * against a business' seat limit. + * + * REDEEMED: The invitation has already been redeemed. Invitations in this state do not count + * against a business' seat limit. + */ +enum class BusinessInvitationStatus +{ + APPROVED = 0, + REQUESTED = 1, + REDEEMED = 2 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(BusinessInvitationStatus) +#endif +#endif + +inline uint qHash(BusinessInvitationStatus value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const BusinessInvitationStatus value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const BusinessInvitationStatus value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * What kinds of Contacts does the Evernote service know about? + */ +enum class ContactType +{ + EVERNOTE = 1, + SMS = 2, + FACEBOOK = 3, + EMAIL = 4, + TWITTER = 5, + LINKEDIN = 6 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(ContactType) +#endif +#endif + +inline uint qHash(ContactType value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const ContactType value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const ContactType value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Entity types + */ +enum class EntityType +{ + NOTE = 1, + NOTEBOOK = 2, + WORKSPACE = 3 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(EntityType) +#endif +#endif + +inline uint qHash(EntityType value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const EntityType value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const EntityType value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * This enumeration defines the possible states that a notebook can be in for a recipient. + * It encompasses the "inMyList" boolean and default notebook status. + * + *
+ *
NOT_IN_MY_LIST
+ *
The notebook is not in the recipient's list (not "joined").
+ *
IN_MY_LIST
+ *
The notebook is in the recipient's notebook list (formerly, we would say + * that the recipient has "joined" the notebook)
+ *
IN_MY_LIST_AND_DEFAULT_NOTEBOOK
+ *
The same as IN_MY_LIST and this notebook is the user's default notebook.
+ *
+ */ +enum class RecipientStatus +{ + NOT_IN_MY_LIST = 1, + IN_MY_LIST = 2, + IN_MY_LIST_AND_DEFAULT_NOTEBOOK = 3 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(RecipientStatus) +#endif +#endif + +inline uint qHash(RecipientStatus value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const RecipientStatus value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const RecipientStatus value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * This enumeration defines the possible types of canMoveToContainer outcomes. + *

+ * An outdated client is expected to signal a "Cannot Move, Please Upgrade To Learn Why" + * like response to the user if an unknown enumeration value is received. + *

+ *
CAN_BE_MOVED
+ *
Can move Notebook to Workspace.
+ *
INSUFFICIENT_ENTITY_PRIVILEGE
+ *
Can not move Notebook to Workspace, because either: + * a) Notebook not in Workspace and insufficient privilege on Notebook + * or b) Notebook in Workspace and membership on Workspace with insufficient privilege + * for move
+ *
INSUFFICIENT_CONTAINER_PRIVILEGE
+ *
Notebook in Workspace and no membership on Workspace. + *
+ *
+ */ +enum class CanMoveToContainerStatus +{ + CAN_BE_MOVED = 1, + INSUFFICIENT_ENTITY_PRIVILEGE = 2, + INSUFFICIENT_CONTAINER_PRIVILEGE = 3 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(CanMoveToContainerStatus) +#endif +#endif + +inline uint qHash(CanMoveToContainerStatus value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const CanMoveToContainerStatus value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const CanMoveToContainerStatus value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * This enumeration defines the possible types of related content. + * + * NEWS_ARTICLE: This related content is a news article + * PROFILE_PERSON: This match refers to the profile of an individual person + * PROFILE_ORGANIZATION: This match refers to the profile of an organization + * REFERENCE_MATERIAL: This related content is material from reference works + */ +enum class RelatedContentType +{ + NEWS_ARTICLE = 1, + PROFILE_PERSON = 2, + PROFILE_ORGANIZATION = 3, + REFERENCE_MATERIAL = 4 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(RelatedContentType) +#endif +#endif + +inline uint qHash(RelatedContentType value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const RelatedContentType value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const RelatedContentType value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * This enumeration defines the possible ways to access related content. + * + * NOT_ACCESSIBLE: The content is not accessible given the user's privilege level, but + * still worth showing as a snippet. The content url may point to a webpage that + * explains why not, or explains how to access that content. + * + * DIRECT_LINK_ACCESS_OK: The content is accessible directly, and no additional login is + * required. + * + * DIRECT_LINK_LOGIN_REQUIRED: The content is accessible directly, but an additional login + * is required. + * + * DIRECT_LINK_EMBEDDED_VIEW: The content is accessible directly, and should be shown in + * an embedded web view. + * If the URL refers to a secured location under our control (for example, + * https://www.evernote.com/), the client may include user-specific authentication + * credentials with the request. + */ +enum class RelatedContentAccess +{ + NOT_ACCESSIBLE = 0, + DIRECT_LINK_ACCESS_OK = 1, + DIRECT_LINK_LOGIN_REQUIRED = 2, + DIRECT_LINK_EMBEDDED_VIEW = 3 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(RelatedContentAccess) +#endif +#endif + +inline uint qHash(RelatedContentAccess value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const RelatedContentAccess value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const RelatedContentAccess value); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * + */ +enum class UserIdentityType +{ + EVERNOTE_USERID = 1, + EMAIL = 2, + IDENTITYID = 3 +}; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) +#if QEVERCLOUD_USES_Q_NAMESPACE +Q_ENUM_NS(UserIdentityType) +#endif +#endif + +inline uint qHash(UserIdentityType value) +{ + return static_cast(value); +} + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QTextStream & operator<<( + QTextStream & out, const UserIdentityType value); + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT QDebug & operator<<( + QDebug & out, const UserIdentityType value); } // namespace qevercloud +Q_DECLARE_METATYPE(qevercloud::EDAMErrorCode) +Q_DECLARE_METATYPE(qevercloud::EDAMInvalidContactReason) +Q_DECLARE_METATYPE(qevercloud::ShareRelationshipPrivilegeLevel) +Q_DECLARE_METATYPE(qevercloud::PrivilegeLevel) +Q_DECLARE_METATYPE(qevercloud::ServiceLevel) +Q_DECLARE_METATYPE(qevercloud::QueryFormat) +Q_DECLARE_METATYPE(qevercloud::NoteSortOrder) +Q_DECLARE_METATYPE(qevercloud::PremiumOrderStatus) +Q_DECLARE_METATYPE(qevercloud::SharedNotebookPrivilegeLevel) +Q_DECLARE_METATYPE(qevercloud::SharedNotePrivilegeLevel) +Q_DECLARE_METATYPE(qevercloud::SponsoredGroupRole) +Q_DECLARE_METATYPE(qevercloud::BusinessUserRole) +Q_DECLARE_METATYPE(qevercloud::BusinessUserStatus) +Q_DECLARE_METATYPE(qevercloud::SharedNotebookInstanceRestrictions) +Q_DECLARE_METATYPE(qevercloud::ReminderEmailConfig) +Q_DECLARE_METATYPE(qevercloud::BusinessInvitationStatus) +Q_DECLARE_METATYPE(qevercloud::ContactType) +Q_DECLARE_METATYPE(qevercloud::EntityType) +Q_DECLARE_METATYPE(qevercloud::RecipientStatus) +Q_DECLARE_METATYPE(qevercloud::CanMoveToContainerStatus) +Q_DECLARE_METATYPE(qevercloud::RelatedContentType) +Q_DECLARE_METATYPE(qevercloud::RelatedContentAccess) +Q_DECLARE_METATYPE(qevercloud::UserIdentityType) + #endif // QEVERCLOUD_GENERATED_EDAMERRORCODE_H diff --git a/src/qevercloud/QEverCloud/headers/generated/Servers.h b/src/qevercloud/QEverCloud/headers/generated/Servers.h new file mode 100644 index 00000000..0ba6e8f9 --- /dev/null +++ b/src/qevercloud/QEverCloud/headers/generated/Servers.h @@ -0,0 +1,1088 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + * + * This file was generated from Evernote Thrift API + */ + +#ifndef QEVERCLOUD_GENERATED_SERVERS_H +#define QEVERCLOUD_GENERATED_SERVERS_H + +#include "../Export.h" + +#include "../Optional.h" +#include "../RequestContext.h" +#include "Constants.h" +#include "Types.h" +#include +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +/** + * @brief The NoteStoreServer class represents + * customizable server for NoteStore requests. + * It is primarily used for testing of QEverCloud + */ +class QEVERCLOUD_EXPORT NoteStoreServer: public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(NoteStoreServer) +public: + explicit NoteStoreServer(QObject * parent = nullptr); + +Q_SIGNALS: + // Signals notifying listeners about incoming requests + void getSyncStateRequest( + IRequestContextPtr ctx); + + void getFilteredSyncChunkRequest( + qint32 afterUSN, + qint32 maxEntries, + SyncChunkFilter filter, + IRequestContextPtr ctx); + + void getLinkedNotebookSyncStateRequest( + LinkedNotebook linkedNotebook, + IRequestContextPtr ctx); + + void getLinkedNotebookSyncChunkRequest( + LinkedNotebook linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly, + IRequestContextPtr ctx); + + void listNotebooksRequest( + IRequestContextPtr ctx); + + void listAccessibleBusinessNotebooksRequest( + IRequestContextPtr ctx); + + void getNotebookRequest( + Guid guid, + IRequestContextPtr ctx); + + void getDefaultNotebookRequest( + IRequestContextPtr ctx); + + void createNotebookRequest( + Notebook notebook, + IRequestContextPtr ctx); + + void updateNotebookRequest( + Notebook notebook, + IRequestContextPtr ctx); + + void expungeNotebookRequest( + Guid guid, + IRequestContextPtr ctx); + + void listTagsRequest( + IRequestContextPtr ctx); + + void listTagsByNotebookRequest( + Guid notebookGuid, + IRequestContextPtr ctx); + + void getTagRequest( + Guid guid, + IRequestContextPtr ctx); + + void createTagRequest( + Tag tag, + IRequestContextPtr ctx); + + void updateTagRequest( + Tag tag, + IRequestContextPtr ctx); + + void untagAllRequest( + Guid guid, + IRequestContextPtr ctx); + + void expungeTagRequest( + Guid guid, + IRequestContextPtr ctx); + + void listSearchesRequest( + IRequestContextPtr ctx); + + void getSearchRequest( + Guid guid, + IRequestContextPtr ctx); + + void createSearchRequest( + SavedSearch search, + IRequestContextPtr ctx); + + void updateSearchRequest( + SavedSearch search, + IRequestContextPtr ctx); + + void expungeSearchRequest( + Guid guid, + IRequestContextPtr ctx); + + void findNoteOffsetRequest( + NoteFilter filter, + Guid guid, + IRequestContextPtr ctx); + + void findNotesMetadataRequest( + NoteFilter filter, + qint32 offset, + qint32 maxNotes, + NotesMetadataResultSpec resultSpec, + IRequestContextPtr ctx); + + void findNoteCountsRequest( + NoteFilter filter, + bool withTrash, + IRequestContextPtr ctx); + + void getNoteWithResultSpecRequest( + Guid guid, + NoteResultSpec resultSpec, + IRequestContextPtr ctx); + + void getNoteRequest( + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx); + + void getNoteApplicationDataRequest( + Guid guid, + IRequestContextPtr ctx); + + void getNoteApplicationDataEntryRequest( + Guid guid, + QString key, + IRequestContextPtr ctx); + + void setNoteApplicationDataEntryRequest( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx); + + void unsetNoteApplicationDataEntryRequest( + Guid guid, + QString key, + IRequestContextPtr ctx); + + void getNoteContentRequest( + Guid guid, + IRequestContextPtr ctx); + + void getNoteSearchTextRequest( + Guid guid, + bool noteOnly, + bool tokenizeForIndexing, + IRequestContextPtr ctx); + + void getResourceSearchTextRequest( + Guid guid, + IRequestContextPtr ctx); + + void getNoteTagNamesRequest( + Guid guid, + IRequestContextPtr ctx); + + void createNoteRequest( + Note note, + IRequestContextPtr ctx); + + void updateNoteRequest( + Note note, + IRequestContextPtr ctx); + + void deleteNoteRequest( + Guid guid, + IRequestContextPtr ctx); + + void expungeNoteRequest( + Guid guid, + IRequestContextPtr ctx); + + void copyNoteRequest( + Guid noteGuid, + Guid toNotebookGuid, + IRequestContextPtr ctx); + + void listNoteVersionsRequest( + Guid noteGuid, + IRequestContextPtr ctx); + + void getNoteVersionRequest( + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx); + + void getResourceRequest( + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData, + IRequestContextPtr ctx); + + void getResourceApplicationDataRequest( + Guid guid, + IRequestContextPtr ctx); + + void getResourceApplicationDataEntryRequest( + Guid guid, + QString key, + IRequestContextPtr ctx); + + void setResourceApplicationDataEntryRequest( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx); + + void unsetResourceApplicationDataEntryRequest( + Guid guid, + QString key, + IRequestContextPtr ctx); + + void updateResourceRequest( + Resource resource, + IRequestContextPtr ctx); + + void getResourceDataRequest( + Guid guid, + IRequestContextPtr ctx); + + void getResourceByHashRequest( + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData, + IRequestContextPtr ctx); + + void getResourceRecognitionRequest( + Guid guid, + IRequestContextPtr ctx); + + void getResourceAlternateDataRequest( + Guid guid, + IRequestContextPtr ctx); + + void getResourceAttributesRequest( + Guid guid, + IRequestContextPtr ctx); + + void getPublicNotebookRequest( + UserID userId, + QString publicUri, + IRequestContextPtr ctx); + + void shareNotebookRequest( + SharedNotebook sharedNotebook, + QString message, + IRequestContextPtr ctx); + + void createOrUpdateNotebookSharesRequest( + NotebookShareTemplate shareTemplate, + IRequestContextPtr ctx); + + void updateSharedNotebookRequest( + SharedNotebook sharedNotebook, + IRequestContextPtr ctx); + + void setNotebookRecipientSettingsRequest( + QString notebookGuid, + NotebookRecipientSettings recipientSettings, + IRequestContextPtr ctx); + + void listSharedNotebooksRequest( + IRequestContextPtr ctx); + + void createLinkedNotebookRequest( + LinkedNotebook linkedNotebook, + IRequestContextPtr ctx); + + void updateLinkedNotebookRequest( + LinkedNotebook linkedNotebook, + IRequestContextPtr ctx); + + void listLinkedNotebooksRequest( + IRequestContextPtr ctx); + + void expungeLinkedNotebookRequest( + Guid guid, + IRequestContextPtr ctx); + + void authenticateToSharedNotebookRequest( + QString shareKeyOrGlobalId, + IRequestContextPtr ctx); + + void getSharedNotebookByAuthRequest( + IRequestContextPtr ctx); + + void emailNoteRequest( + NoteEmailParameters parameters, + IRequestContextPtr ctx); + + void shareNoteRequest( + Guid guid, + IRequestContextPtr ctx); + + void stopSharingNoteRequest( + Guid guid, + IRequestContextPtr ctx); + + void authenticateToSharedNoteRequest( + QString guid, + QString noteKey, + IRequestContextPtr ctx); + + void findRelatedRequest( + RelatedQuery query, + RelatedResultSpec resultSpec, + IRequestContextPtr ctx); + + void updateNoteIfUsnMatchesRequest( + Note note, + IRequestContextPtr ctx); + + void manageNotebookSharesRequest( + ManageNotebookSharesParameters parameters, + IRequestContextPtr ctx); + + void getNotebookSharesRequest( + QString notebookGuid, + IRequestContextPtr ctx); + + // Signals used to send encoded response data + void getSyncStateRequestReady( + QByteArray data); + + void getFilteredSyncChunkRequestReady( + QByteArray data); + + void getLinkedNotebookSyncStateRequestReady( + QByteArray data); + + void getLinkedNotebookSyncChunkRequestReady( + QByteArray data); + + void listNotebooksRequestReady( + QByteArray data); + + void listAccessibleBusinessNotebooksRequestReady( + QByteArray data); + + void getNotebookRequestReady( + QByteArray data); + + void getDefaultNotebookRequestReady( + QByteArray data); + + void createNotebookRequestReady( + QByteArray data); + + void updateNotebookRequestReady( + QByteArray data); + + void expungeNotebookRequestReady( + QByteArray data); + + void listTagsRequestReady( + QByteArray data); + + void listTagsByNotebookRequestReady( + QByteArray data); + + void getTagRequestReady( + QByteArray data); + + void createTagRequestReady( + QByteArray data); + + void updateTagRequestReady( + QByteArray data); + + void untagAllRequestReady( + QByteArray data); + + void expungeTagRequestReady( + QByteArray data); + + void listSearchesRequestReady( + QByteArray data); + + void getSearchRequestReady( + QByteArray data); + + void createSearchRequestReady( + QByteArray data); + + void updateSearchRequestReady( + QByteArray data); + + void expungeSearchRequestReady( + QByteArray data); + + void findNoteOffsetRequestReady( + QByteArray data); + + void findNotesMetadataRequestReady( + QByteArray data); + + void findNoteCountsRequestReady( + QByteArray data); + + void getNoteWithResultSpecRequestReady( + QByteArray data); + + void getNoteRequestReady( + QByteArray data); + + void getNoteApplicationDataRequestReady( + QByteArray data); + + void getNoteApplicationDataEntryRequestReady( + QByteArray data); + + void setNoteApplicationDataEntryRequestReady( + QByteArray data); + + void unsetNoteApplicationDataEntryRequestReady( + QByteArray data); + + void getNoteContentRequestReady( + QByteArray data); + + void getNoteSearchTextRequestReady( + QByteArray data); + + void getResourceSearchTextRequestReady( + QByteArray data); + + void getNoteTagNamesRequestReady( + QByteArray data); + + void createNoteRequestReady( + QByteArray data); + + void updateNoteRequestReady( + QByteArray data); + + void deleteNoteRequestReady( + QByteArray data); + + void expungeNoteRequestReady( + QByteArray data); + + void copyNoteRequestReady( + QByteArray data); + + void listNoteVersionsRequestReady( + QByteArray data); + + void getNoteVersionRequestReady( + QByteArray data); + + void getResourceRequestReady( + QByteArray data); + + void getResourceApplicationDataRequestReady( + QByteArray data); + + void getResourceApplicationDataEntryRequestReady( + QByteArray data); + + void setResourceApplicationDataEntryRequestReady( + QByteArray data); + + void unsetResourceApplicationDataEntryRequestReady( + QByteArray data); + + void updateResourceRequestReady( + QByteArray data); + + void getResourceDataRequestReady( + QByteArray data); + + void getResourceByHashRequestReady( + QByteArray data); + + void getResourceRecognitionRequestReady( + QByteArray data); + + void getResourceAlternateDataRequestReady( + QByteArray data); + + void getResourceAttributesRequestReady( + QByteArray data); + + void getPublicNotebookRequestReady( + QByteArray data); + + void shareNotebookRequestReady( + QByteArray data); + + void createOrUpdateNotebookSharesRequestReady( + QByteArray data); + + void updateSharedNotebookRequestReady( + QByteArray data); + + void setNotebookRecipientSettingsRequestReady( + QByteArray data); + + void listSharedNotebooksRequestReady( + QByteArray data); + + void createLinkedNotebookRequestReady( + QByteArray data); + + void updateLinkedNotebookRequestReady( + QByteArray data); + + void listLinkedNotebooksRequestReady( + QByteArray data); + + void expungeLinkedNotebookRequestReady( + QByteArray data); + + void authenticateToSharedNotebookRequestReady( + QByteArray data); + + void getSharedNotebookByAuthRequestReady( + QByteArray data); + + void emailNoteRequestReady( + QByteArray data); + + void shareNoteRequestReady( + QByteArray data); + + void stopSharingNoteRequestReady( + QByteArray data); + + void authenticateToSharedNoteRequestReady( + QByteArray data); + + void findRelatedRequestReady( + QByteArray data); + + void updateNoteIfUsnMatchesRequestReady( + QByteArray data); + + void manageNotebookSharesRequestReady( + QByteArray data); + + void getNotebookSharesRequestReady( + QByteArray data); + +public Q_SLOTS: + // Slot used to deliver requests to the server + void onRequest(QByteArray data); + + // Slots for replies to requests + void onGetSyncStateRequestReady( + SyncState value, + EverCloudExceptionDataPtr exceptionData); + + void onGetFilteredSyncChunkRequestReady( + SyncChunk value, + EverCloudExceptionDataPtr exceptionData); + + void onGetLinkedNotebookSyncStateRequestReady( + SyncState value, + EverCloudExceptionDataPtr exceptionData); + + void onGetLinkedNotebookSyncChunkRequestReady( + SyncChunk value, + EverCloudExceptionDataPtr exceptionData); + + void onListNotebooksRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + + void onListAccessibleBusinessNotebooksRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + + void onGetNotebookRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData); + + void onGetDefaultNotebookRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData); + + void onCreateNotebookRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData); + + void onUpdateNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onExpungeNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onListTagsRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + + void onListTagsByNotebookRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + + void onGetTagRequestReady( + Tag value, + EverCloudExceptionDataPtr exceptionData); + + void onCreateTagRequestReady( + Tag value, + EverCloudExceptionDataPtr exceptionData); + + void onUpdateTagRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onUntagAllRequestReady( + EverCloudExceptionDataPtr exceptionData); + + void onExpungeTagRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onListSearchesRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + + void onGetSearchRequestReady( + SavedSearch value, + EverCloudExceptionDataPtr exceptionData); + + void onCreateSearchRequestReady( + SavedSearch value, + EverCloudExceptionDataPtr exceptionData); + + void onUpdateSearchRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onExpungeSearchRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onFindNoteOffsetRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onFindNotesMetadataRequestReady( + NotesMetadataList value, + EverCloudExceptionDataPtr exceptionData); + + void onFindNoteCountsRequestReady( + NoteCollectionCounts value, + EverCloudExceptionDataPtr exceptionData); + + void onGetNoteWithResultSpecRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData); + + void onGetNoteRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData); + + void onGetNoteApplicationDataRequestReady( + LazyMap value, + EverCloudExceptionDataPtr exceptionData); + + void onGetNoteApplicationDataEntryRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData); + + void onSetNoteApplicationDataEntryRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onUnsetNoteApplicationDataEntryRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onGetNoteContentRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData); + + void onGetNoteSearchTextRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData); + + void onGetResourceSearchTextRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData); + + void onGetNoteTagNamesRequestReady( + QStringList value, + EverCloudExceptionDataPtr exceptionData); + + void onCreateNoteRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData); + + void onUpdateNoteRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData); + + void onDeleteNoteRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onExpungeNoteRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onCopyNoteRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData); + + void onListNoteVersionsRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + + void onGetNoteVersionRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData); + + void onGetResourceRequestReady( + Resource value, + EverCloudExceptionDataPtr exceptionData); + + void onGetResourceApplicationDataRequestReady( + LazyMap value, + EverCloudExceptionDataPtr exceptionData); + + void onGetResourceApplicationDataEntryRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData); + + void onSetResourceApplicationDataEntryRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onUnsetResourceApplicationDataEntryRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onUpdateResourceRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onGetResourceDataRequestReady( + QByteArray value, + EverCloudExceptionDataPtr exceptionData); + + void onGetResourceByHashRequestReady( + Resource value, + EverCloudExceptionDataPtr exceptionData); + + void onGetResourceRecognitionRequestReady( + QByteArray value, + EverCloudExceptionDataPtr exceptionData); + + void onGetResourceAlternateDataRequestReady( + QByteArray value, + EverCloudExceptionDataPtr exceptionData); + + void onGetResourceAttributesRequestReady( + ResourceAttributes value, + EverCloudExceptionDataPtr exceptionData); + + void onGetPublicNotebookRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData); + + void onShareNotebookRequestReady( + SharedNotebook value, + EverCloudExceptionDataPtr exceptionData); + + void onCreateOrUpdateNotebookSharesRequestReady( + CreateOrUpdateNotebookSharesResult value, + EverCloudExceptionDataPtr exceptionData); + + void onUpdateSharedNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onSetNotebookRecipientSettingsRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData); + + void onListSharedNotebooksRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + + void onCreateLinkedNotebookRequestReady( + LinkedNotebook value, + EverCloudExceptionDataPtr exceptionData); + + void onUpdateLinkedNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onListLinkedNotebooksRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + + void onExpungeLinkedNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + + void onAuthenticateToSharedNotebookRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData); + + void onGetSharedNotebookByAuthRequestReady( + SharedNotebook value, + EverCloudExceptionDataPtr exceptionData); + + void onEmailNoteRequestReady( + EverCloudExceptionDataPtr exceptionData); + + void onShareNoteRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData); + + void onStopSharingNoteRequestReady( + EverCloudExceptionDataPtr exceptionData); + + void onAuthenticateToSharedNoteRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData); + + void onFindRelatedRequestReady( + RelatedResult value, + EverCloudExceptionDataPtr exceptionData); + + void onUpdateNoteIfUsnMatchesRequestReady( + UpdateNoteIfUsnMatchesResult value, + EverCloudExceptionDataPtr exceptionData); + + void onManageNotebookSharesRequestReady( + ManageNotebookSharesResult value, + EverCloudExceptionDataPtr exceptionData); + + void onGetNotebookSharesRequestReady( + ShareRelationships value, + EverCloudExceptionDataPtr exceptionData); + +}; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * @brief The UserStoreServer class represents + * customizable server for UserStore requests. + * It is primarily used for testing of QEverCloud + */ +class QEVERCLOUD_EXPORT UserStoreServer: public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(UserStoreServer) +public: + explicit UserStoreServer(QObject * parent = nullptr); + +Q_SIGNALS: + // Signals notifying listeners about incoming requests + void checkVersionRequest( + QString clientName, + qint16 edamVersionMajor, + qint16 edamVersionMinor, + IRequestContextPtr ctx); + + void getBootstrapInfoRequest( + QString locale, + IRequestContextPtr ctx); + + void authenticateLongSessionRequest( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor, + IRequestContextPtr ctx); + + void completeTwoFactorAuthenticationRequest( + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription, + IRequestContextPtr ctx); + + void revokeLongSessionRequest( + IRequestContextPtr ctx); + + void authenticateToBusinessRequest( + IRequestContextPtr ctx); + + void getUserRequest( + IRequestContextPtr ctx); + + void getPublicUserInfoRequest( + QString username, + IRequestContextPtr ctx); + + void getUserUrlsRequest( + IRequestContextPtr ctx); + + void inviteToBusinessRequest( + QString emailAddress, + IRequestContextPtr ctx); + + void removeFromBusinessRequest( + QString emailAddress, + IRequestContextPtr ctx); + + void updateBusinessUserIdentifierRequest( + QString oldEmailAddress, + QString newEmailAddress, + IRequestContextPtr ctx); + + void listBusinessUsersRequest( + IRequestContextPtr ctx); + + void listBusinessInvitationsRequest( + bool includeRequestedInvitations, + IRequestContextPtr ctx); + + void getAccountLimitsRequest( + ServiceLevel serviceLevel, + IRequestContextPtr ctx); + + // Signals used to send encoded response data + void checkVersionRequestReady( + QByteArray data); + + void getBootstrapInfoRequestReady( + QByteArray data); + + void authenticateLongSessionRequestReady( + QByteArray data); + + void completeTwoFactorAuthenticationRequestReady( + QByteArray data); + + void revokeLongSessionRequestReady( + QByteArray data); + + void authenticateToBusinessRequestReady( + QByteArray data); + + void getUserRequestReady( + QByteArray data); + + void getPublicUserInfoRequestReady( + QByteArray data); + + void getUserUrlsRequestReady( + QByteArray data); + + void inviteToBusinessRequestReady( + QByteArray data); + + void removeFromBusinessRequestReady( + QByteArray data); + + void updateBusinessUserIdentifierRequestReady( + QByteArray data); + + void listBusinessUsersRequestReady( + QByteArray data); + + void listBusinessInvitationsRequestReady( + QByteArray data); + + void getAccountLimitsRequestReady( + QByteArray data); + +public Q_SLOTS: + // Slot used to deliver requests to the server + void onRequest(QByteArray data); + + // Slots for replies to requests + void onCheckVersionRequestReady( + bool value, + EverCloudExceptionDataPtr exceptionData); + + void onGetBootstrapInfoRequestReady( + BootstrapInfo value, + EverCloudExceptionDataPtr exceptionData); + + void onAuthenticateLongSessionRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData); + + void onCompleteTwoFactorAuthenticationRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData); + + void onRevokeLongSessionRequestReady( + EverCloudExceptionDataPtr exceptionData); + + void onAuthenticateToBusinessRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData); + + void onGetUserRequestReady( + User value, + EverCloudExceptionDataPtr exceptionData); + + void onGetPublicUserInfoRequestReady( + PublicUserInfo value, + EverCloudExceptionDataPtr exceptionData); + + void onGetUserUrlsRequestReady( + UserUrls value, + EverCloudExceptionDataPtr exceptionData); + + void onInviteToBusinessRequestReady( + EverCloudExceptionDataPtr exceptionData); + + void onRemoveFromBusinessRequestReady( + EverCloudExceptionDataPtr exceptionData); + + void onUpdateBusinessUserIdentifierRequestReady( + EverCloudExceptionDataPtr exceptionData); + + void onListBusinessUsersRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + + void onListBusinessInvitationsRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + + void onGetAccountLimitsRequestReady( + AccountLimits value, + EverCloudExceptionDataPtr exceptionData); + +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_GENERATED_SERVERS_H diff --git a/src/qevercloud/QEverCloud/headers/generated/services.h b/src/qevercloud/QEverCloud/headers/generated/Services.h similarity index 82% rename from src/qevercloud/QEverCloud/headers/generated/services.h rename to src/qevercloud/QEverCloud/headers/generated/Services.h index f4d09f44..96267ecc 100644 --- a/src/qevercloud/QEverCloud/headers/generated/services.h +++ b/src/qevercloud/QEverCloud/headers/generated/Services.h @@ -1,34 +1,31 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: * https://opensource.org/licenses/MIT * * This file was generated from Evernote Thrift API */ - #ifndef QEVERCLOUD_GENERATED_SERVICES_H #define QEVERCLOUD_GENERATED_SERVICES_H -#include "../Optional.h" -#include "../export.h" +#include "../Export.h" + #include "../AsyncResult.h" -#include "constants.h" -#include "types.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "../DurableService.h" +#include "../Optional.h" +#include "../RequestContext.h" +#include "Constants.h" +#include "Types.h" #include namespace qevercloud { +//////////////////////////////////////////////////////////////////////////////// + /** * Service: NoteStore *

@@ -55,28 +52,29 @@ namespace qevercloud { * content. * */ -class QEVERCLOUD_EXPORT NoteStore: public QObject +class QEVERCLOUD_EXPORT INoteStore: public QObject { Q_OBJECT - Q_DISABLE_COPY(NoteStore) -public: - explicit NoteStore(QString noteStoreUrl = QString(), QString authenticationToken = QString(), QObject * parent = 0); - explicit NoteStore(QObject * parent); - - void setNoteStoreUrl(QString noteStoreUrl) { m_url = noteStoreUrl; } - QString noteStoreUrl() { return m_url; } + Q_DISABLE_COPY(INoteStore) +protected: + INoteStore(QObject * parent) : + QObject(parent) + {} - void setAuthenticationToken(QString authenticationToken) { m_authenticationToken = authenticationToken; } - QString authenticationToken() { return m_authenticationToken; } +public: + virtual QString noteStoreUrl() const = 0; + virtual void setNoteStoreUrl(QString url) = 0; /** * Asks the NoteStore to provide information about the status of the user * account corresponding to the provided authentication token. */ - SyncState getSyncState(QString authenticationToken = QString()); + virtual SyncState getSyncState( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getSyncState @endlink */ - AsyncResult * getSyncStateAsync(QString authenticationToken = QString()); + virtual AsyncResult * getSyncStateAsync( + IRequestContextPtr ctx = {}) = 0; /** * Asks the NoteStore to provide the state of the account in order of @@ -111,10 +109,18 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - SyncChunk getFilteredSyncChunk(qint32 afterUSN, qint32 maxEntries, const SyncChunkFilter& filter, QString authenticationToken = QString()); + virtual SyncChunk getFilteredSyncChunk( + qint32 afterUSN, + qint32 maxEntries, + const SyncChunkFilter & filter, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getFilteredSyncChunk @endlink */ - AsyncResult * getFilteredSyncChunkAsync(qint32 afterUSN, qint32 maxEntries, const SyncChunkFilter& filter, QString authenticationToken = QString()); + virtual AsyncResult * getFilteredSyncChunkAsync( + qint32 afterUSN, + qint32 maxEntries, + const SyncChunkFilter & filter, + IRequestContextPtr ctx = {}) = 0; /** * Asks the NoteStore to provide information about the status of a linked @@ -157,10 +163,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - SyncState getLinkedNotebookSyncState(const LinkedNotebook& linkedNotebook, QString authenticationToken = QString()); + virtual SyncState getLinkedNotebookSyncState( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getLinkedNotebookSyncState @endlink */ - AsyncResult * getLinkedNotebookSyncStateAsync(const LinkedNotebook& linkedNotebook, QString authenticationToken = QString()); + virtual AsyncResult * getLinkedNotebookSyncStateAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) = 0; /** * Asks the NoteStore to provide information about the contents of a linked @@ -226,18 +236,30 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - SyncChunk getLinkedNotebookSyncChunk(const LinkedNotebook& linkedNotebook, qint32 afterUSN, qint32 maxEntries, bool fullSyncOnly, QString authenticationToken = QString()); + virtual SyncChunk getLinkedNotebookSyncChunk( + const LinkedNotebook & linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getLinkedNotebookSyncChunk @endlink */ - AsyncResult * getLinkedNotebookSyncChunkAsync(const LinkedNotebook& linkedNotebook, qint32 afterUSN, qint32 maxEntries, bool fullSyncOnly, QString authenticationToken = QString()); + virtual AsyncResult * getLinkedNotebookSyncChunkAsync( + const LinkedNotebook & linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly, + IRequestContextPtr ctx = {}) = 0; /** * Returns a list of all of the notebooks in the account. */ - QList< Notebook > listNotebooks(QString authenticationToken = QString()); + virtual QList listNotebooks( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link listNotebooks @endlink */ - AsyncResult * listNotebooksAsync(QString authenticationToken = QString()); + virtual AsyncResult * listNotebooksAsync( + IRequestContextPtr ctx = {}) = 0; /** * Returns a list of all the notebooks in a business that the user has permission to access, @@ -252,10 +274,12 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * business auth token. * */ - QList< Notebook > listAccessibleBusinessNotebooks(QString authenticationToken = QString()); + virtual QList listAccessibleBusinessNotebooks( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link listAccessibleBusinessNotebooks @endlink */ - AsyncResult * listAccessibleBusinessNotebooksAsync(QString authenticationToken = QString()); + virtual AsyncResult * listAccessibleBusinessNotebooksAsync( + IRequestContextPtr ctx = {}) = 0; /** * Returns the current state of the notebook with the provided GUID. @@ -276,19 +300,25 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - Notebook getNotebook(Guid guid, QString authenticationToken = QString()); + virtual Notebook getNotebook( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getNotebook @endlink */ - AsyncResult * getNotebookAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * getNotebookAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Returns the notebook that should be used to store new notes in the * user's account when no other notebooks are specified. */ - Notebook getDefaultNotebook(QString authenticationToken = QString()); + virtual Notebook getDefaultNotebook( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getDefaultNotebook @endlink */ - AsyncResult * getDefaultNotebookAsync(QString authenticationToken = QString()); + virtual AsyncResult * getDefaultNotebookAsync( + IRequestContextPtr ctx = {}) = 0; /** * Asks the service to make a notebook with the provided name. @@ -324,10 +354,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - Notebook createNotebook(const Notebook& notebook, QString authenticationToken = QString()); + virtual Notebook createNotebook( + const Notebook & notebook, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link createNotebook @endlink */ - AsyncResult * createNotebookAsync(const Notebook& notebook, QString authenticationToken = QString()); + virtual AsyncResult * createNotebookAsync( + const Notebook & notebook, + IRequestContextPtr ctx = {}) = 0; /** * Submits notebook changes to the service. The provided data must include the @@ -368,10 +402,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - qint32 updateNotebook(const Notebook& notebook, QString authenticationToken = QString()); + virtual qint32 updateNotebook( + const Notebook & notebook, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link updateNotebook @endlink */ - AsyncResult * updateNotebookAsync(const Notebook& notebook, QString authenticationToken = QString()); + virtual AsyncResult * updateNotebookAsync( + const Notebook & notebook, + IRequestContextPtr ctx = {}) = 0; /** * Permanently removes the notebook from the user's account. @@ -398,19 +436,25 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - qint32 expungeNotebook(Guid guid, QString authenticationToken = QString()); + virtual qint32 expungeNotebook( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link expungeNotebook @endlink */ - AsyncResult * expungeNotebookAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * expungeNotebookAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Returns a list of the tags in the account. Evernote does not support * the undeletion of tags, so this will only include active tags. */ - QList< Tag > listTags(QString authenticationToken = QString()); + virtual QList listTags( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link listTags @endlink */ - AsyncResult * listTagsAsync(QString authenticationToken = QString()); + virtual AsyncResult * listTagsAsync( + IRequestContextPtr ctx = {}) = 0; /** * Returns a list of the tags that are applied to at least one note within @@ -425,10 +469,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - QList< Tag > listTagsByNotebook(Guid notebookGuid, QString authenticationToken = QString()); + virtual QList listTagsByNotebook( + Guid notebookGuid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link listTagsByNotebook @endlink */ - AsyncResult * listTagsByNotebookAsync(Guid notebookGuid, QString authenticationToken = QString()); + virtual AsyncResult * listTagsByNotebookAsync( + Guid notebookGuid, + IRequestContextPtr ctx = {}) = 0; /** * Returns the current state of the Tag with the provided GUID. @@ -448,10 +496,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - Tag getTag(Guid guid, QString authenticationToken = QString()); + virtual Tag getTag( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getTag @endlink */ - AsyncResult * getTagAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * getTagAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Asks the service to make a tag with a set of information. @@ -481,10 +533,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - Tag createTag(const Tag& tag, QString authenticationToken = QString()); + virtual Tag createTag( + const Tag & tag, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link createTag @endlink */ - AsyncResult * createTagAsync(const Tag& tag, QString authenticationToken = QString()); + virtual AsyncResult * createTagAsync( + const Tag & tag, + IRequestContextPtr ctx = {}) = 0; /** * Submits tag changes to the service. The provided data must include @@ -517,10 +573,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - qint32 updateTag(const Tag& tag, QString authenticationToken = QString()); + virtual qint32 updateTag( + const Tag & tag, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link updateTag @endlink */ - AsyncResult * updateTagAsync(const Tag& tag, QString authenticationToken = QString()); + virtual AsyncResult * updateTagAsync( + const Tag & tag, + IRequestContextPtr ctx = {}) = 0; /** * Removes the provided tag from every note that is currently tagged with @@ -548,10 +608,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - void untagAll(Guid guid, QString authenticationToken = QString()); + virtual void untagAll( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link untagAll @endlink */ - AsyncResult * untagAllAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * untagAllAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Permanently deletes the tag with the provided GUID, if present. @@ -578,19 +642,25 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - qint32 expungeTag(Guid guid, QString authenticationToken = QString()); + virtual qint32 expungeTag( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link expungeTag @endlink */ - AsyncResult * expungeTagAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * expungeTagAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Returns a list of the searches in the account. Evernote does not support * the undeletion of searches, so this will only include active searches. */ - QList< SavedSearch > listSearches(QString authenticationToken = QString()); + virtual QList listSearches( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link listSearches @endlink */ - AsyncResult * listSearchesAsync(QString authenticationToken = QString()); + virtual AsyncResult * listSearchesAsync( + IRequestContextPtr ctx = {}) = 0; /** * Returns the current state of the search with the provided GUID. @@ -609,10 +679,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - SavedSearch getSearch(Guid guid, QString authenticationToken = QString()); + virtual SavedSearch getSearch( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getSearch @endlink */ - AsyncResult * getSearchAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * getSearchAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Asks the service to make a saved search with a set of information. @@ -638,10 +712,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - SavedSearch createSearch(const SavedSearch& search, QString authenticationToken = QString()); + virtual SavedSearch createSearch( + const SavedSearch & search, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link createSearch @endlink */ - AsyncResult * createSearchAsync(const SavedSearch& search, QString authenticationToken = QString()); + virtual AsyncResult * createSearchAsync( + const SavedSearch & search, + IRequestContextPtr ctx = {}) = 0; /** * Submits search changes to the service. The provided data must include @@ -670,10 +748,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - qint32 updateSearch(const SavedSearch& search, QString authenticationToken = QString()); + virtual qint32 updateSearch( + const SavedSearch & search, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link updateSearch @endlink */ - AsyncResult * updateSearchAsync(const SavedSearch& search, QString authenticationToken = QString()); + virtual AsyncResult * updateSearchAsync( + const SavedSearch & search, + IRequestContextPtr ctx = {}) = 0; /** * Permanently deletes the saved search with the provided GUID, if present. @@ -700,10 +782,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - qint32 expungeSearch(Guid guid, QString authenticationToken = QString()); + virtual qint32 expungeSearch( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link expungeSearch @endlink */ - AsyncResult * expungeSearchAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * expungeSearchAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Finds the position of a note within a sorted subset of all of the user's @@ -746,10 +832,16 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - qint32 findNoteOffset(const NoteFilter& filter, Guid guid, QString authenticationToken = QString()); + virtual qint32 findNoteOffset( + const NoteFilter & filter, + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link findNoteOffset @endlink */ - AsyncResult * findNoteOffsetAsync(const NoteFilter& filter, Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * findNoteOffsetAsync( + const NoteFilter & filter, + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Used to find the high-level information about a set of the notes from a @@ -808,10 +900,20 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - NotesMetadataList findNotesMetadata(const NoteFilter& filter, qint32 offset, qint32 maxNotes, const NotesMetadataResultSpec& resultSpec, QString authenticationToken = QString()); + virtual NotesMetadataList findNotesMetadata( + const NoteFilter & filter, + qint32 offset, + qint32 maxNotes, + const NotesMetadataResultSpec & resultSpec, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link findNotesMetadata @endlink */ - AsyncResult * findNotesMetadataAsync(const NoteFilter& filter, qint32 offset, qint32 maxNotes, const NotesMetadataResultSpec& resultSpec, QString authenticationToken = QString()); + virtual AsyncResult * findNotesMetadataAsync( + const NoteFilter & filter, + qint32 offset, + qint32 maxNotes, + const NotesMetadataResultSpec & resultSpec, + IRequestContextPtr ctx = {}) = 0; /** * This function is used to determine how many notes are found for each @@ -844,10 +946,16 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject *

  • "Notebook.guid" - not found, by GUID
  • * */ - NoteCollectionCounts findNoteCounts(const NoteFilter& filter, bool withTrash, QString authenticationToken = QString()); + virtual NoteCollectionCounts findNoteCounts( + const NoteFilter & filter, + bool withTrash, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link findNoteCounts @endlink */ - AsyncResult * findNoteCountsAsync(const NoteFilter& filter, bool withTrash, QString authenticationToken = QString()); + virtual AsyncResult * findNoteCountsAsync( + const NoteFilter & filter, + bool withTrash, + IRequestContextPtr ctx = {}) = 0; /** * Returns the current state of the note in the service with the provided @@ -880,10 +988,16 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - Note getNoteWithResultSpec(Guid guid, const NoteResultSpec& resultSpec, QString authenticationToken = QString()); + virtual Note getNoteWithResultSpec( + Guid guid, + const NoteResultSpec & resultSpec, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getNoteWithResultSpec @endlink */ - AsyncResult * getNoteWithResultSpecAsync(Guid guid, const NoteResultSpec& resultSpec, QString authenticationToken = QString()); + virtual AsyncResult * getNoteWithResultSpecAsync( + Guid guid, + const NoteResultSpec & resultSpec, + IRequestContextPtr ctx = {}) = 0; /** * DEPRECATED. See getNoteWithResultSpec. @@ -892,10 +1006,22 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * mapping to the equivalent field of a NoteResultSpec. The Note.sharedNotes field is never * populated on the returned note. To get a note with its shares, use getNoteWithResultSpec. */ - Note getNote(Guid guid, bool withContent, bool withResourcesData, bool withResourcesRecognition, bool withResourcesAlternateData, QString authenticationToken = QString()); + virtual Note getNote( + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getNote @endlink */ - AsyncResult * getNoteAsync(Guid guid, bool withContent, bool withResourcesData, bool withResourcesRecognition, bool withResourcesAlternateData, QString authenticationToken = QString()); + virtual AsyncResult * getNoteAsync( + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx = {}) = 0; /** * Get all of the application data for the note identified by GUID, @@ -905,10 +1031,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * only needs to fetch its own applicationData entry, use * getNoteApplicationDataEntry instead. */ - LazyMap getNoteApplicationData(Guid guid, QString authenticationToken = QString()); + virtual LazyMap getNoteApplicationData( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getNoteApplicationData @endlink */ - AsyncResult * getNoteApplicationDataAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * getNoteApplicationDataAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Get the value of a single entry in the applicationData map @@ -919,29 +1049,49 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject *
  • "NoteAttributes.applicationData.key" - note not found, by key
  • * */ - QString getNoteApplicationDataEntry(Guid guid, QString key, QString authenticationToken = QString()); + virtual QString getNoteApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getNoteApplicationDataEntry @endlink */ - AsyncResult * getNoteApplicationDataEntryAsync(Guid guid, QString key, QString authenticationToken = QString()); + virtual AsyncResult * getNoteApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) = 0; /** * Update, or create, an entry in the applicationData map for * the note identified by guid. */ - qint32 setNoteApplicationDataEntry(Guid guid, QString key, QString value, QString authenticationToken = QString()); + virtual qint32 setNoteApplicationDataEntry( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link setNoteApplicationDataEntry @endlink */ - AsyncResult * setNoteApplicationDataEntryAsync(Guid guid, QString key, QString value, QString authenticationToken = QString()); + virtual AsyncResult * setNoteApplicationDataEntryAsync( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx = {}) = 0; /** * Remove an entry identified by 'key' from the applicationData map for * the note identified by 'guid'. Silently ignores an unset of a * non-existing key. */ - qint32 unsetNoteApplicationDataEntry(Guid guid, QString key, QString authenticationToken = QString()); + virtual qint32 unsetNoteApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link unsetNoteApplicationDataEntry @endlink */ - AsyncResult * unsetNoteApplicationDataEntryAsync(Guid guid, QString key, QString authenticationToken = QString()); + virtual AsyncResult * unsetNoteApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) = 0; /** * Returns XHTML contents of the note with the provided GUID. @@ -963,10 +1113,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - QString getNoteContent(Guid guid, QString authenticationToken = QString()); + virtual QString getNoteContent( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getNoteContent @endlink */ - AsyncResult * getNoteContentAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * getNoteContentAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Returns a block of the extracted plain text contents of the note with the @@ -1002,10 +1156,18 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - QString getNoteSearchText(Guid guid, bool noteOnly, bool tokenizeForIndexing, QString authenticationToken = QString()); + virtual QString getNoteSearchText( + Guid guid, + bool noteOnly, + bool tokenizeForIndexing, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getNoteSearchText @endlink */ - AsyncResult * getNoteSearchTextAsync(Guid guid, bool noteOnly, bool tokenizeForIndexing, QString authenticationToken = QString()); + virtual AsyncResult * getNoteSearchTextAsync( + Guid guid, + bool noteOnly, + bool tokenizeForIndexing, + IRequestContextPtr ctx = {}) = 0; /** * Returns a block of the extracted plain text contents of the resource with @@ -1031,10 +1193,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - QString getResourceSearchText(Guid guid, QString authenticationToken = QString()); + virtual QString getResourceSearchText( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getResourceSearchText @endlink */ - AsyncResult * getResourceSearchTextAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * getResourceSearchTextAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Returns a list of the names of the tags for the note with the provided @@ -1054,10 +1220,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - QStringList getNoteTagNames(Guid guid, QString authenticationToken = QString()); + virtual QStringList getNoteTagNames( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getNoteTagNames @endlink */ - AsyncResult * getNoteTagNamesAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * getNoteTagNamesAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Asks the service to make a note with the provided set of information. @@ -1122,10 +1292,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - Note createNote(const Note& note, QString authenticationToken = QString()); + virtual Note createNote( + const Note & note, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link createNote @endlink */ - AsyncResult * createNoteAsync(const Note& note, QString authenticationToken = QString()); + virtual AsyncResult * createNoteAsync( + const Note & note, + IRequestContextPtr ctx = {}) = 0; /** * Submit a set of changes to a note to the service. The provided data @@ -1198,10 +1372,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - Note updateNote(const Note& note, QString authenticationToken = QString()); + virtual Note updateNote( + const Note & note, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link updateNote @endlink */ - AsyncResult * updateNoteAsync(const Note& note, QString authenticationToken = QString()); + virtual AsyncResult * updateNoteAsync( + const Note & note, + IRequestContextPtr ctx = {}) = 0; /** * Moves the note into the trash. The note may still be undeleted, unless it @@ -1229,10 +1407,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - qint32 deleteNote(Guid guid, QString authenticationToken = QString()); + virtual qint32 deleteNote( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link deleteNote @endlink */ - AsyncResult * deleteNoteAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * deleteNoteAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Permanently removes a Note, and all of its Resources, @@ -1258,10 +1440,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - qint32 expungeNote(Guid guid, QString authenticationToken = QString()); + virtual qint32 expungeNote( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link expungeNote @endlink */ - AsyncResult * expungeNoteAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * expungeNoteAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Performs a deep copy of the Note with the provided GUID 'noteGuid' into @@ -1305,10 +1491,16 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - Note copyNote(Guid noteGuid, Guid toNotebookGuid, QString authenticationToken = QString()); + virtual Note copyNote( + Guid noteGuid, + Guid toNotebookGuid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link copyNote @endlink */ - AsyncResult * copyNoteAsync(Guid noteGuid, Guid toNotebookGuid, QString authenticationToken = QString()); + virtual AsyncResult * copyNoteAsync( + Guid noteGuid, + Guid toNotebookGuid, + IRequestContextPtr ctx = {}) = 0; /** * Returns a list of the prior versions of a particular note that are @@ -1332,10 +1524,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - QList< NoteVersionId > listNoteVersions(Guid noteGuid, QString authenticationToken = QString()); + virtual QList listNoteVersions( + Guid noteGuid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link listNoteVersions @endlink */ - AsyncResult * listNoteVersionsAsync(Guid noteGuid, QString authenticationToken = QString()); + virtual AsyncResult * listNoteVersionsAsync( + Guid noteGuid, + IRequestContextPtr ctx = {}) = 0; /** * This can be used to retrieve a previous version of a Note after it has been @@ -1380,10 +1576,22 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - Note getNoteVersion(Guid noteGuid, qint32 updateSequenceNum, bool withResourcesData, bool withResourcesRecognition, bool withResourcesAlternateData, QString authenticationToken = QString()); + virtual Note getNoteVersion( + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getNoteVersion @endlink */ - AsyncResult * getNoteVersionAsync(Guid noteGuid, qint32 updateSequenceNum, bool withResourcesData, bool withResourcesRecognition, bool withResourcesAlternateData, QString authenticationToken = QString()); + virtual AsyncResult * getNoteVersionAsync( + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx = {}) = 0; /** * Returns the current state of the resource in the service with the @@ -1422,10 +1630,22 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - Resource getResource(Guid guid, bool withData, bool withRecognition, bool withAttributes, bool withAlternateData, QString authenticationToken = QString()); + virtual Resource getResource( + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getResource @endlink */ - AsyncResult * getResourceAsync(Guid guid, bool withData, bool withRecognition, bool withAttributes, bool withAlternateData, QString authenticationToken = QString()); + virtual AsyncResult * getResourceAsync( + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData, + IRequestContextPtr ctx = {}) = 0; /** * Get all of the application data for the Resource identified by GUID, @@ -1435,10 +1655,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * only needs to fetch its own applicationData entry, use * getResourceApplicationDataEntry instead. */ - LazyMap getResourceApplicationData(Guid guid, QString authenticationToken = QString()); + virtual LazyMap getResourceApplicationData( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getResourceApplicationData @endlink */ - AsyncResult * getResourceApplicationDataAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * getResourceApplicationDataAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Get the value of a single entry in the applicationData map @@ -1449,28 +1673,48 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject *
  • "ResourceAttributes.applicationData.key" - Resource not found, by key
  • * */ - QString getResourceApplicationDataEntry(Guid guid, QString key, QString authenticationToken = QString()); + virtual QString getResourceApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getResourceApplicationDataEntry @endlink */ - AsyncResult * getResourceApplicationDataEntryAsync(Guid guid, QString key, QString authenticationToken = QString()); + virtual AsyncResult * getResourceApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) = 0; /** * Update, or create, an entry in the applicationData map for * the Resource identified by guid. */ - qint32 setResourceApplicationDataEntry(Guid guid, QString key, QString value, QString authenticationToken = QString()); + virtual qint32 setResourceApplicationDataEntry( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link setResourceApplicationDataEntry @endlink */ - AsyncResult * setResourceApplicationDataEntryAsync(Guid guid, QString key, QString value, QString authenticationToken = QString()); + virtual AsyncResult * setResourceApplicationDataEntryAsync( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx = {}) = 0; /** * Remove an entry identified by 'key' from the applicationData map for * the Resource identified by 'guid'. */ - qint32 unsetResourceApplicationDataEntry(Guid guid, QString key, QString authenticationToken = QString()); + virtual qint32 unsetResourceApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link unsetResourceApplicationDataEntry @endlink */ - AsyncResult * unsetResourceApplicationDataEntryAsync(Guid guid, QString key, QString authenticationToken = QString()); + virtual AsyncResult * unsetResourceApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) = 0; /** * Submit a set of changes to a resource to the service. This can be used @@ -1521,10 +1765,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - qint32 updateResource(const Resource& resource, QString authenticationToken = QString()); + virtual qint32 updateResource( + const Resource & resource, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link updateResource @endlink */ - AsyncResult * updateResourceAsync(const Resource& resource, QString authenticationToken = QString()); + virtual AsyncResult * updateResourceAsync( + const Resource & resource, + IRequestContextPtr ctx = {}) = 0; /** * Returns binary data of the resource with the provided GUID. For @@ -1548,10 +1796,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - QByteArray getResourceData(Guid guid, QString authenticationToken = QString()); + virtual QByteArray getResourceData( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getResourceData @endlink */ - AsyncResult * getResourceDataAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * getResourceDataAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Returns the current state of a resource, referenced by containing @@ -1594,10 +1846,22 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - Resource getResourceByHash(Guid noteGuid, QByteArray contentHash, bool withData, bool withRecognition, bool withAlternateData, QString authenticationToken = QString()); + virtual Resource getResourceByHash( + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getResourceByHash @endlink */ - AsyncResult * getResourceByHashAsync(Guid noteGuid, QByteArray contentHash, bool withData, bool withRecognition, bool withAlternateData, QString authenticationToken = QString()); + virtual AsyncResult * getResourceByHashAsync( + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData, + IRequestContextPtr ctx = {}) = 0; /** * Returns the binary contents of the recognition index for the resource @@ -1623,10 +1887,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - QByteArray getResourceRecognition(Guid guid, QString authenticationToken = QString()); + virtual QByteArray getResourceRecognition( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getResourceRecognition @endlink */ - AsyncResult * getResourceRecognitionAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * getResourceRecognitionAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * If the Resource with the provided GUID has an alternate data representation @@ -1652,10 +1920,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - QByteArray getResourceAlternateData(Guid guid, QString authenticationToken = QString()); + virtual QByteArray getResourceAlternateData( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getResourceAlternateData @endlink */ - AsyncResult * getResourceAlternateDataAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * getResourceAlternateDataAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Returns the set of attributes for the Resource with the provided GUID. @@ -1677,10 +1949,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - ResourceAttributes getResourceAttributes(Guid guid, QString authenticationToken = QString()); + virtual ResourceAttributes getResourceAttributes( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getResourceAttributes @endlink */ - AsyncResult * getResourceAttributesAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * getResourceAttributesAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** *

    @@ -1716,10 +1992,16 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * down for the requester because of an IP-based country lookup. * */ - Notebook getPublicNotebook(UserID userId, QString publicUri); + virtual Notebook getPublicNotebook( + UserID userId, + QString publicUri, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getPublicNotebook @endlink */ - AsyncResult * getPublicNotebookAsync(UserID userId, QString publicUri); + virtual AsyncResult * getPublicNotebookAsync( + UserID userId, + QString publicUri, + IRequestContextPtr ctx = {}) = 0; /** * @Deprecated for first-party clients. See createOrUpdateNotebookShares. @@ -1798,10 +2080,16 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - SharedNotebook shareNotebook(const SharedNotebook& sharedNotebook, QString message, QString authenticationToken = QString()); + virtual SharedNotebook shareNotebook( + const SharedNotebook & sharedNotebook, + QString message, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link shareNotebook @endlink */ - AsyncResult * shareNotebookAsync(const SharedNotebook& sharedNotebook, QString message, QString authenticationToken = QString()); + virtual AsyncResult * shareNotebookAsync( + const SharedNotebook & sharedNotebook, + QString message, + IRequestContextPtr ctx = {}) = 0; /** * Share a notebook by a messaging thread ID or a list of contacts. This function is @@ -1857,18 +2145,26 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * specified, but no thread with that ID exists * */ - CreateOrUpdateNotebookSharesResult createOrUpdateNotebookShares(const NotebookShareTemplate& shareTemplate, QString authenticationToken = QString()); + virtual CreateOrUpdateNotebookSharesResult createOrUpdateNotebookShares( + const NotebookShareTemplate & shareTemplate, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link createOrUpdateNotebookShares @endlink */ - AsyncResult * createOrUpdateNotebookSharesAsync(const NotebookShareTemplate& shareTemplate, QString authenticationToken = QString()); + virtual AsyncResult * createOrUpdateNotebookSharesAsync( + const NotebookShareTemplate & shareTemplate, + IRequestContextPtr ctx = {}) = 0; /** * @Deprecated See createOrUpdateNotebookShares and manageNotebookShares. */ - qint32 updateSharedNotebook(const SharedNotebook& sharedNotebook, QString authenticationToken = QString()); + virtual qint32 updateSharedNotebook( + const SharedNotebook & sharedNotebook, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link updateSharedNotebook @endlink */ - AsyncResult * updateSharedNotebookAsync(const SharedNotebook& sharedNotebook, QString authenticationToken = QString()); + virtual AsyncResult * updateSharedNotebookAsync( + const SharedNotebook & sharedNotebook, + IRequestContextPtr ctx = {}) = 0; /** * Set values for the recipient settings associated with a notebook share. Only the @@ -1906,10 +2202,16 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * to false and any of reminder* settings to true. * */ - Notebook setNotebookRecipientSettings(QString notebookGuid, const NotebookRecipientSettings& recipientSettings, QString authenticationToken = QString()); + virtual Notebook setNotebookRecipientSettings( + QString notebookGuid, + const NotebookRecipientSettings & recipientSettings, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link setNotebookRecipientSettings @endlink */ - AsyncResult * setNotebookRecipientSettingsAsync(QString notebookGuid, const NotebookRecipientSettings& recipientSettings, QString authenticationToken = QString()); + virtual AsyncResult * setNotebookRecipientSettingsAsync( + QString notebookGuid, + const NotebookRecipientSettings & recipientSettings, + IRequestContextPtr ctx = {}) = 0; /** * Lists the collection of shared notebooks for all notebooks in the @@ -1918,10 +2220,12 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * @return * The list of all SharedNotebooks for the user */ - QList< SharedNotebook > listSharedNotebooks(QString authenticationToken = QString()); + virtual QList listSharedNotebooks( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link listSharedNotebooks @endlink */ - AsyncResult * listSharedNotebooksAsync(QString authenticationToken = QString()); + virtual AsyncResult * listSharedNotebooksAsync( + IRequestContextPtr ctx = {}) = 0; /** * Asks the service to make a linked notebook with the provided name, username @@ -1960,10 +2264,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - LinkedNotebook createLinkedNotebook(const LinkedNotebook& linkedNotebook, QString authenticationToken = QString()); + virtual LinkedNotebook createLinkedNotebook( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link createLinkedNotebook @endlink */ - AsyncResult * createLinkedNotebookAsync(const LinkedNotebook& linkedNotebook, QString authenticationToken = QString()); + virtual AsyncResult * createLinkedNotebookAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) = 0; /** * @param linkedNotebook @@ -1981,18 +2289,24 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - qint32 updateLinkedNotebook(const LinkedNotebook& linkedNotebook, QString authenticationToken = QString()); + virtual qint32 updateLinkedNotebook( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link updateLinkedNotebook @endlink */ - AsyncResult * updateLinkedNotebookAsync(const LinkedNotebook& linkedNotebook, QString authenticationToken = QString()); + virtual AsyncResult * updateLinkedNotebookAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) = 0; /** * Returns a list of linked notebooks */ - QList< LinkedNotebook > listLinkedNotebooks(QString authenticationToken = QString()); + virtual QList listLinkedNotebooks( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link listLinkedNotebooks @endlink */ - AsyncResult * listLinkedNotebooksAsync(QString authenticationToken = QString()); + virtual AsyncResult * listLinkedNotebooksAsync( + IRequestContextPtr ctx = {}) = 0; /** * Permanently expunges the linked notebook from the account. @@ -2005,10 +2319,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * The LinkedNotebook.guid field of the LinkedNotebook to permanently remove * from the account. */ - qint32 expungeLinkedNotebook(Guid guid, QString authenticationToken = QString()); + virtual qint32 expungeLinkedNotebook( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link expungeLinkedNotebook @endlink */ - AsyncResult * expungeLinkedNotebookAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * expungeLinkedNotebookAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Asks the service to produce an authentication token that can be used to @@ -2060,10 +2378,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - AuthenticationResult authenticateToSharedNotebook(QString shareKeyOrGlobalId, QString authenticationToken = QString()); + virtual AuthenticationResult authenticateToSharedNotebook( + QString shareKeyOrGlobalId, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link authenticateToSharedNotebook @endlink */ - AsyncResult * authenticateToSharedNotebookAsync(QString shareKeyOrGlobalId, QString authenticationToken = QString()); + virtual AsyncResult * authenticateToSharedNotebookAsync( + QString shareKeyOrGlobalId, + IRequestContextPtr ctx = {}) = 0; /** * This function is used to retrieve extended information about a shared @@ -2090,10 +2412,12 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - SharedNotebook getSharedNotebookByAuth(QString authenticationToken = QString()); + virtual SharedNotebook getSharedNotebookByAuth( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getSharedNotebookByAuth @endlink */ - AsyncResult * getSharedNotebookByAuthAsync(QString authenticationToken = QString()); + virtual AsyncResult * getSharedNotebookByAuthAsync( + IRequestContextPtr ctx = {}) = 0; /** * Attempts to send a single note to one or more email recipients. @@ -2144,10 +2468,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - void emailNote(const NoteEmailParameters& parameters, QString authenticationToken = QString()); + virtual void emailNote( + const NoteEmailParameters & parameters, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link emailNote @endlink */ - AsyncResult * emailNoteAsync(const NoteEmailParameters& parameters, QString authenticationToken = QString()); + virtual AsyncResult * emailNoteAsync( + const NoteEmailParameters & parameters, + IRequestContextPtr ctx = {}) = 0; /** * If this note is not already shared publicly (via its own direct URL), then this @@ -2172,10 +2500,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject *

  • "Note.guid" - not found, by GUID
  • * */ - QString shareNote(Guid guid, QString authenticationToken = QString()); + virtual QString shareNote( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link shareNote @endlink */ - AsyncResult * shareNoteAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * shareNoteAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * If this note is shared publicly then this will stop sharing that note @@ -2184,7 +2516,7 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * If the Note is not shared, then this function will do nothing. * - * This function does not remove invididual shares for the note. To remove + * This function does not remove individual shares for the note. To remove * individual shares, see stopSharingNoteWithRecipients. * * @param guid @@ -2199,10 +2531,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject *
  • "Note.guid" - not found, by GUID
  • * */ - void stopSharingNote(Guid guid, QString authenticationToken = QString()); + virtual void stopSharingNote( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link stopSharingNote @endlink */ - AsyncResult * stopSharingNoteAsync(Guid guid, QString authenticationToken = QString()); + virtual AsyncResult * stopSharingNoteAsync( + Guid guid, + IRequestContextPtr ctx = {}) = 0; /** * Asks the service to produce an authentication token that can be used to @@ -2246,10 +2582,16 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - AuthenticationResult authenticateToSharedNote(QString guid, QString noteKey, QString authenticationToken = QString()); + virtual AuthenticationResult authenticateToSharedNote( + QString guid, + QString noteKey, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link authenticateToSharedNote @endlink */ - AsyncResult * authenticateToSharedNoteAsync(QString guid, QString noteKey, QString authenticationToken = QString()); + virtual AsyncResult * authenticateToSharedNoteAsync( + QString guid, + QString noteKey, + IRequestContextPtr ctx = {}) = 0; /** * Identify related entities on the service, such as notes, @@ -2300,10 +2642,16 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * * */ - RelatedResult findRelated(const RelatedQuery& query, const RelatedResultSpec& resultSpec, QString authenticationToken = QString()); + virtual RelatedResult findRelated( + const RelatedQuery & query, + const RelatedResultSpec & resultSpec, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link findRelated @endlink */ - AsyncResult * findRelatedAsync(const RelatedQuery& query, const RelatedResultSpec& resultSpec, QString authenticationToken = QString()); + virtual AsyncResult * findRelatedAsync( + const RelatedQuery & query, + const RelatedResultSpec & resultSpec, + IRequestContextPtr ctx = {}) = 0; /** * Perform the same operation as updateNote() would provided that the update @@ -2332,10 +2680,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * not happen if your client is working correctly. * */ - UpdateNoteIfUsnMatchesResult updateNoteIfUsnMatches(const Note& note, QString authenticationToken = QString()); + virtual UpdateNoteIfUsnMatchesResult updateNoteIfUsnMatches( + const Note & note, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link updateNoteIfUsnMatches @endlink */ - AsyncResult * updateNoteIfUsnMatchesAsync(const Note& note, QString authenticationToken = QString()); + virtual AsyncResult * updateNoteIfUsnMatchesAsync( + const Note & note, + IRequestContextPtr ctx = {}) = 0; /** * Manage invitations and memberships associated with a given notebook. @@ -2353,10 +2705,14 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * shares. * */ - ManageNotebookSharesResult manageNotebookShares(const ManageNotebookSharesParameters& parameters, QString authenticationToken = QString()); + virtual ManageNotebookSharesResult manageNotebookShares( + const ManageNotebookSharesParameters & parameters, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link manageNotebookShares @endlink */ - AsyncResult * manageNotebookSharesAsync(const ManageNotebookSharesParameters& parameters, QString authenticationToken = QString()); + virtual AsyncResult * manageNotebookSharesAsync( + const ManageNotebookSharesParameters & parameters, + IRequestContextPtr ctx = {}) = 0; /** * Return the share relationships for the given notebook, including @@ -2366,16 +2722,21 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * limited use by Evernote clients that have discussed using this * routine with the platform team. */ - ShareRelationships getNotebookShares(QString notebookGuid, QString authenticationToken = QString()); + virtual ShareRelationships getNotebookShares( + QString notebookGuid, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getNotebookShares @endlink */ - AsyncResult * getNotebookSharesAsync(QString notebookGuid, QString authenticationToken = QString()); + virtual AsyncResult * getNotebookSharesAsync( + QString notebookGuid, + IRequestContextPtr ctx = {}) = 0; -private: - QString m_url; - QString m_authenticationToken; }; +using INoteStorePtr = std::shared_ptr; + +//////////////////////////////////////////////////////////////////////////////// + /** * Service: UserStore *

    @@ -2395,15 +2756,18 @@ class QEVERCLOUD_EXPORT NoteStore: public QObject * privileges * */ -class QEVERCLOUD_EXPORT UserStore: public QObject +class QEVERCLOUD_EXPORT IUserStore: public QObject { Q_OBJECT - Q_DISABLE_COPY(UserStore) -public: - explicit UserStore(QString host, QString authenticationToken = QString(), QObject * parent = 0); + Q_DISABLE_COPY(IUserStore) +protected: + IUserStore(QObject * parent) : + QObject(parent) + {} - void setAuthenticationToken(QString authenticationToken) { m_authenticationToken = authenticationToken; } - QString authenticationToken() { return m_authenticationToken; } +public: + virtual QString userStoreUrl() const = 0; + virtual void setUserStoreUrl(QString url) = 0; /** * This should be the first call made by a client to the EDAM service. It @@ -2431,10 +2795,18 @@ class QEVERCLOUD_EXPORT UserStore: public QObject * client. This should be the current value of the EDAM_VERSION_MINOR * constant for the client. */ - bool checkVersion(QString clientName, qint16 edamVersionMajor = EDAM_VERSION_MAJOR, qint16 edamVersionMinor = EDAM_VERSION_MINOR); + virtual bool checkVersion( + QString clientName, + qint16 edamVersionMajor = EDAM_VERSION_MAJOR, + qint16 edamVersionMinor = EDAM_VERSION_MINOR, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link checkVersion @endlink */ - AsyncResult * checkVersionAsync(QString clientName, qint16 edamVersionMajor = EDAM_VERSION_MAJOR, qint16 edamVersionMinor = EDAM_VERSION_MINOR); + virtual AsyncResult * checkVersionAsync( + QString clientName, + qint16 edamVersionMajor = EDAM_VERSION_MAJOR, + qint16 edamVersionMinor = EDAM_VERSION_MINOR, + IRequestContextPtr ctx = {}) = 0; /** * This provides bootstrap information to the client. Various bootstrap @@ -2448,10 +2820,14 @@ class QEVERCLOUD_EXPORT UserStore: public QObject * @return * The bootstrap information suitable for this client. */ - BootstrapInfo getBootstrapInfo(QString locale); + virtual BootstrapInfo getBootstrapInfo( + QString locale, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getBootstrapInfo @endlink */ - AsyncResult * getBootstrapInfoAsync(QString locale); + virtual AsyncResult * getBootstrapInfoAsync( + QString locale, + IRequestContextPtr ctx = {}) = 0; /** * This is used to check a username and password in order to create a @@ -2539,10 +2915,26 @@ class QEVERCLOUD_EXPORT UserStore: public QObject *

  • AUTH_EXPIRED "password" - user password is expired * */ - AuthenticationResult authenticateLongSession(QString username, QString password, QString consumerKey, QString consumerSecret, QString deviceIdentifier, QString deviceDescription, bool supportsTwoFactor); + virtual AuthenticationResult authenticateLongSession( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link authenticateLongSession @endlink */ - AsyncResult * authenticateLongSessionAsync(QString username, QString password, QString consumerKey, QString consumerSecret, QString deviceIdentifier, QString deviceDescription, bool supportsTwoFactor); + virtual AsyncResult * authenticateLongSessionAsync( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor, + IRequestContextPtr ctx = {}) = 0; /** * Complete the authentication process when a second factor is required. This @@ -2582,10 +2974,18 @@ class QEVERCLOUD_EXPORT UserStore: public QObject * two-factor authentication.
  • * */ - AuthenticationResult completeTwoFactorAuthentication(QString oneTimeCode, QString deviceIdentifier, QString deviceDescription, QString authenticationToken = QString()); + virtual AuthenticationResult completeTwoFactorAuthentication( + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link completeTwoFactorAuthentication @endlink */ - AsyncResult * completeTwoFactorAuthenticationAsync(QString oneTimeCode, QString deviceIdentifier, QString deviceDescription, QString authenticationToken = QString()); + virtual AsyncResult * completeTwoFactorAuthenticationAsync( + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription, + IRequestContextPtr ctx = {}) = 0; /** * Revoke an existing long lived authentication token. This can be used to @@ -2605,10 +3005,12 @@ class QEVERCLOUD_EXPORT UserStore: public QObject * is already revoked. * */ - void revokeLongSession(QString authenticationToken = QString()); + virtual void revokeLongSession( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link revokeLongSession @endlink */ - AsyncResult * revokeLongSessionAsync(QString authenticationToken = QString()); + virtual AsyncResult * revokeLongSessionAsync( + IRequestContextPtr ctx = {}) = 0; /** * This is used to take an existing authentication token that grants access @@ -2643,10 +3045,12 @@ class QEVERCLOUD_EXPORT UserStore: public QObject * sign-on before authenticating to the business. * */ - AuthenticationResult authenticateToBusiness(QString authenticationToken = QString()); + virtual AuthenticationResult authenticateToBusiness( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link authenticateToBusiness @endlink */ - AsyncResult * authenticateToBusinessAsync(QString authenticationToken = QString()); + virtual AsyncResult * authenticateToBusinessAsync( + IRequestContextPtr ctx = {}) = 0; /** * Returns the User corresponding to the provided authentication token, @@ -2655,10 +3059,12 @@ class QEVERCLOUD_EXPORT UserStore: public QObject * the access level granted by the token, so a web service client may receive * fewer fields than an integrated desktop client. */ - User getUser(QString authenticationToken = QString()); + virtual User getUser( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getUser @endlink */ - AsyncResult * getUserAsync(QString authenticationToken = QString()); + virtual AsyncResult * getUserAsync( + IRequestContextPtr ctx = {}) = 0; /** * Asks the UserStore about the publicly available location information for @@ -2668,24 +3074,30 @@ class QEVERCLOUD_EXPORT UserStore: public QObject *
  • DATA_REQUIRED "username" - username is empty * */ - PublicUserInfo getPublicUserInfo(QString username); + virtual PublicUserInfo getPublicUserInfo( + QString username, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getPublicUserInfo @endlink */ - AsyncResult * getPublicUserInfoAsync(QString username); + virtual AsyncResult * getPublicUserInfoAsync( + QString username, + IRequestContextPtr ctx = {}) = 0; /** *

    Returns the URLs that should be used when sending requests to the service on * behalf of the account represented by the provided authenticationToken.

    * - *

    This method isn't needed by most clients, who can retreive the correct set of + *

    This method isn't needed by most clients, who can retrieve the correct set of * UserUrls from the AuthenticationResult returned from * UserStore#authenticateLongSession(). This method is typically only needed to look up * the correct URLs for an existing long-lived authentication token.

    */ - UserUrls getUserUrls(QString authenticationToken = QString()); + virtual UserUrls getUserUrls( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getUserUrls @endlink */ - AsyncResult * getUserUrlsAsync(QString authenticationToken = QString()); + virtual AsyncResult * getUserUrlsAsync( + IRequestContextPtr ctx = {}) = 0; /** * Invite a user to join an Evernote Business account. @@ -2730,10 +3142,14 @@ class QEVERCLOUD_EXPORT UserStore: public QObject * user limit.
  • * */ - void inviteToBusiness(QString emailAddress, QString authenticationToken = QString()); + virtual void inviteToBusiness( + QString emailAddress, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link inviteToBusiness @endlink */ - AsyncResult * inviteToBusinessAsync(QString emailAddress, QString authenticationToken = QString()); + virtual AsyncResult * inviteToBusinessAsync( + QString emailAddress, + IRequestContextPtr ctx = {}) = 0; /** * Remove a user from an Evernote Business account. Once removed, the user will no @@ -2759,10 +3175,14 @@ class QEVERCLOUD_EXPORT UserStore: public QObject * business or that user was not invited via external provisioning. * */ - void removeFromBusiness(QString emailAddress, QString authenticationToken = QString()); + virtual void removeFromBusiness( + QString emailAddress, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link removeFromBusiness @endlink */ - AsyncResult * removeFromBusinessAsync(QString emailAddress, QString authenticationToken = QString()); + virtual AsyncResult * removeFromBusinessAsync( + QString emailAddress, + IRequestContextPtr ctx = {}) = 0; /** * Update the email address used to uniquely identify an Evernote Business user. @@ -2806,10 +3226,16 @@ class QEVERCLOUD_EXPORT UserStore: public QObject * in the business. * */ - void updateBusinessUserIdentifier(QString oldEmailAddress, QString newEmailAddress, QString authenticationToken = QString()); + virtual void updateBusinessUserIdentifier( + QString oldEmailAddress, + QString newEmailAddress, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link updateBusinessUserIdentifier @endlink */ - AsyncResult * updateBusinessUserIdentifierAsync(QString oldEmailAddress, QString newEmailAddress, QString authenticationToken = QString()); + virtual AsyncResult * updateBusinessUserIdentifierAsync( + QString oldEmailAddress, + QString newEmailAddress, + IRequestContextPtr ctx = {}) = 0; /** * Returns a list of active business users in a given business. @@ -2829,10 +3255,12 @@ class QEVERCLOUD_EXPORT UserStore: public QObject * A business authentication token returned by authenticateToBusiness or with sufficient * privileges to manage Evernote Business membership. */ - QList< UserProfile > listBusinessUsers(QString authenticationToken = QString()); + virtual QList listBusinessUsers( + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link listBusinessUsers @endlink */ - AsyncResult * listBusinessUsersAsync(QString authenticationToken = QString()); + virtual AsyncResult * listBusinessUsersAsync( + IRequestContextPtr ctx = {}) = 0; /** * Returns a list of outstanding invitations to join an Evernote Business account. @@ -2848,10 +3276,14 @@ class QEVERCLOUD_EXPORT UserStore: public QObject * in the returned list. If false, only invitations with a status of * BusinessInvitationStatus.APPROVED will be included. */ - QList< BusinessInvitation > listBusinessInvitations(bool includeRequestedInvitations, QString authenticationToken = QString()); + virtual QList listBusinessInvitations( + bool includeRequestedInvitations, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link listBusinessInvitations @endlink */ - AsyncResult * listBusinessInvitationsAsync(bool includeRequestedInvitations, QString authenticationToken = QString()); + virtual AsyncResult * listBusinessInvitationsAsync( + bool includeRequestedInvitations, + IRequestContextPtr ctx = {}) = 0; /** * Retrieve the standard account limits for a given service level. This should only be @@ -2863,24 +3295,42 @@ class QEVERCLOUD_EXPORT UserStore: public QObject *
  • DATA_REQUIRED "serviceLevel" - serviceLevel is null
  • * */ - AccountLimits getAccountLimits(ServiceLevel::type serviceLevel); + virtual AccountLimits getAccountLimits( + ServiceLevel serviceLevel, + IRequestContextPtr ctx = {}) = 0; /** Asynchronous version of @link getAccountLimits @endlink */ - AsyncResult * getAccountLimitsAsync(ServiceLevel::type serviceLevel); + virtual AsyncResult * getAccountLimitsAsync( + ServiceLevel serviceLevel, + IRequestContextPtr ctx = {}) = 0; -private: - QString m_url; - QString m_authenticationToken; }; +using IUserStorePtr = std::shared_ptr; + +//////////////////////////////////////////////////////////////////////////////// + +QEVERCLOUD_EXPORT INoteStore * newNoteStore( + QString noteStoreUrl = {}, + IRequestContextPtr ctx = {}, + QObject * parent = nullptr, + IRetryPolicyPtr retryPolicy = {}); + +QEVERCLOUD_EXPORT IUserStore * newUserStore( + QString userStoreUrl = {}, + IRequestContextPtr ctx = {}, + QObject * parent = nullptr, + IRetryPolicyPtr retryPolicy = {}); + } // namespace qevercloud -Q_DECLARE_METATYPE(QList< qevercloud::Notebook >) -Q_DECLARE_METATYPE(QList< qevercloud::Tag >) -Q_DECLARE_METATYPE(QList< qevercloud::SavedSearch >) -Q_DECLARE_METATYPE(QList< qevercloud::NoteVersionId >) -Q_DECLARE_METATYPE(QList< qevercloud::SharedNotebook >) -Q_DECLARE_METATYPE(QList< qevercloud::LinkedNotebook >) -Q_DECLARE_METATYPE(QList< qevercloud::BusinessInvitation >) -Q_DECLARE_METATYPE(QList< qevercloud::UserProfile >) + +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) #endif // QEVERCLOUD_GENERATED_SERVICES_H diff --git a/src/qevercloud/QEverCloud/headers/generated/types.h b/src/qevercloud/QEverCloud/headers/generated/Types.h similarity index 67% rename from src/qevercloud/QEverCloud/headers/generated/types.h rename to src/qevercloud/QEverCloud/headers/generated/Types.h index ffd5f93a..9d6d52be 100644 --- a/src/qevercloud/QEverCloud/headers/generated/types.h +++ b/src/qevercloud/QEverCloud/headers/generated/Types.h @@ -1,504 +1,45 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: * https://opensource.org/licenses/MIT * * This file was generated from Evernote Thrift API */ - #ifndef QEVERCLOUD_GENERATED_TYPES_H #define QEVERCLOUD_GENERATED_TYPES_H +#include "../Export.h" + #include "../Optional.h" -#include "../export.h" +#include "../Printable.h" #include "EDAMErrorCode.h" -#include -#include -#include -#include -#include #include #include +#include +#include +#include #include -#include #include +#include +#include +#include namespace qevercloud { -/** - * An enumeration that provides a reason for why a given contact was invalid, for example, - * as thrown via an EDAMInvalidContactsException. - * - *
    - *
    BAD_ADDRESS
    - *
    The contact information does not represent a valid address for a recipient. - * Clients should be validating and normalizing contacts, so receiving this - * error code commonly represents a client error. - *
    - *
    DUPLICATE_CONTACT
    - *
    If the method throwing this exception accepts a list of contacts, this error - * code indicates that the given contact is a duplicate of another contact in - * the list. Note that the server may clean up contacts, and that this cleanup - * occurs before checking for duplication. Receiving this error is commonly - * an indication of a client issue, since client should be normalizing contacts - * and removing duplicates. All instances that are duplicates are returned. For - * example, if a list of 5 contacts has the same e-mail address twice, the two - * conflicting e-mail address contacts will be returned. - *
    - *
    NO_CONNECTION
    - *
    Indicates that the given contact, an Evernote type contact, is not connected - * to the user for which the call is being made. It is possible that clients are - * out of sync with the server and should re-synchronize their identities and - * business user state. See Identity.userConnected for more information on user - * connections. - *
    - *
    - * - * Note that if multiple reasons may apply, only one is returned. The precedence order - * is BAD_ADDRESS, DUPLICATE_CONTACT, NO_CONNECTION, meaning that if a contact has a bad - * address and is also duplicated, it will be returned as a BAD_ADDRESS. - */ -struct QEVERCLOUD_EXPORT EDAMInvalidContactReason { - enum type { - BAD_ADDRESS, - DUPLICATE_CONTACT, - NO_CONNECTION - }; -}; - -/** - * Privilege levels for accessing shared notebooks. - * - * READ_NOTEBOOK: Recipient is able to read the contents of the shared notebook - * but does not have access to information about other recipients of the - * notebook or the activity stream information. - * - * READ_NOTEBOOK_PLUS_ACTIVITY: Recipient has READ_NOTEBOOK rights and can also - * access information about other recipients and the activity stream. - * - * MODIFY_NOTEBOOK_PLUS_ACTIVITY: Recipient has rights to read and modify the contents - * of the shared notebook, including the right to move notes to the trash and to create - * notes in the notebook. The recipient can also access information about other - * recipients and the activity stream. - * - * FULL_ACCESS: Recipient has full rights to the shared notebook and recipient lists, - * including privilege to revoke and create invitations and to change privilege - * levels on invitations for individuals. If the user is a member of the same group, - * (e.g. the same business) as the shared notebook, they will additionally be granted - * permissions to update the publishing status of the notebook. - */ -struct QEVERCLOUD_EXPORT ShareRelationshipPrivilegeLevel { - enum type { - READ_NOTEBOOK = 0, - READ_NOTEBOOK_PLUS_ACTIVITY = 10, - MODIFY_NOTEBOOK_PLUS_ACTIVITY = 20, - FULL_ACCESS = 30 - }; -}; - -/** - * This enumeration defines the possible permission levels for a user. - * Free accounts will have a level of NORMAL and paid Premium accounts - * will have a level of PREMIUM. - */ -struct QEVERCLOUD_EXPORT PrivilegeLevel { - enum type { - NORMAL = 1, - PREMIUM = 3, - VIP = 5, - MANAGER = 7, - SUPPORT = 8, - ADMIN = 9 - }; -}; - -/** - * This enumeration defines the possible tiers of service that a user may have. A - * ServiceLevel of BUSINESS signifies a business-only account, which can never be any - * other ServiceLevel. - */ -struct QEVERCLOUD_EXPORT ServiceLevel { - enum type { - BASIC = 1, - PLUS = 2, - PREMIUM = 3, - BUSINESS = 4 - }; -}; - -/** - * Every search query is specified as a sequence of characters. - * Currently, only the USER query format is supported. - */ -struct QEVERCLOUD_EXPORT QueryFormat { - enum type { - USER = 1, - SEXP = 2 - }; -}; - -/** - * This enumeration defines the possible sort ordering for notes when - * they are returned from a search result. - */ -struct QEVERCLOUD_EXPORT NoteSortOrder { - enum type { - CREATED = 1, - UPDATED = 2, - RELEVANCE = 3, - UPDATE_SEQUENCE_NUMBER = 4, - TITLE = 5 - }; -}; - -/** - * This enumeration defines the possible states of a premium account - * - * NONE: the user has never attempted to become a premium subscriber - * - * PENDING: the user has requested a premium account but their charge has not - * been confirmed - * - * ACTIVE: the user has been charged and their premium account is in good - * standing - * - * FAILED: the system attempted to charge the was denied. We will periodically attempt to - * re-validate their order. - * - * CANCELLATION_PENDING: the user has requested that no further charges be made - * but the current account is still active. - * - * CANCELED: the premium account was canceled either because of failure to pay - * or user cancelation. No more attempts will be made to activate the account. - */ -struct QEVERCLOUD_EXPORT PremiumOrderStatus { - enum type { - NONE = 0, - PENDING = 1, - ACTIVE = 2, - FAILED = 3, - CANCELLATION_PENDING = 4, - CANCELED = 5 - }; -}; - -/** - * Privilege levels for accessing shared notebooks. - * - * Note that as of 2014-04, FULL_ACCESS is synonymous with BUSINESS_FULL_ACCESS. If a - * user is a member of a business and has FULL_ACCESS privileges, then they will - * automatically be granted BUSINESS_FULL_ACCESS for notebooks in their business. This - * will happen implicitly when they attempt to access the corresponding notebooks of - * the business. BUSINESS_FULL_ACCESS is therefore deprecated. - * - * READ_NOTEBOOK: Recipient is able to read the contents of the shared notebook - * but does not have access to information about other recipients of the - * notebook or the activity stream information. - * - * MODIFY_NOTEBOOK_PLUS_ACTIVITY: Recipient has rights to read and modify the contents - * of the shared notebook, including the right to move notes to the trash and to create - * notes in the notebook. The recipient can also access information about other - * recipients and the activity stream. - * - * READ_NOTEBOOK_PLUS_ACTIVITY: Recipient has READ_NOTEBOOK rights and can also - * access information about other recipients and the activity stream. - * - * GROUP: If the user belongs to a group, such as a Business, that has a defined - * privilege level, use the privilege level of the group as the privilege for - * the individual. - * - * FULL_ACCESS: Recipient has full rights to the shared notebook and recipient lists, - * including privilege to revoke and create invitations and to change privilege - * levels on invitations for individuals. For members of a business, FULL_ACCESS - * privilege on business notebooks also grants the ability to change how the notebook - * will appear when shared with the business, including the rights to share and - * unshare the notebook with the business. - * - * BUSINESS_FULL_ACCESS: Deprecated. See the note above about BUSINESS_FULL_ACCESS and - * FULL_ACCESS being synonymous. - */ -struct QEVERCLOUD_EXPORT SharedNotebookPrivilegeLevel { - enum type { - READ_NOTEBOOK = 0, - MODIFY_NOTEBOOK_PLUS_ACTIVITY = 1, - READ_NOTEBOOK_PLUS_ACTIVITY = 2, - GROUP = 3, - FULL_ACCESS = 4, - BUSINESS_FULL_ACCESS = 5 - }; -}; - -/** - * Privilege levels for accessing a shared note. All privilege levels convey "activity feed" access, - * which allows the recipient to access information about other recipients and the activity stream. - * - * READ_NOTE: Recipient has rights to read the shared note. - * - * MODIFY_NOTE: Recipient has all of the rights of READ_NOTE, plus rights to modify the shared - * note's content, title and resources. Other fields, including the notebook, tags and metadata, - * may not be modified. - * - * FULL_ACCESS: Recipient has all of the rights of MODIFY_NOTE, plus rights to share the note with - * other users via email, public note links, and note sharing. Recipient may also update and - * remove other recipient's note sharing rights. - */ -struct QEVERCLOUD_EXPORT SharedNotePrivilegeLevel { - enum type { - READ_NOTE = 0, - MODIFY_NOTE = 1, - FULL_ACCESS = 2 - }; -}; - -/** - * Enumeration of the roles that a User can have within a sponsored group. - * - * GROUP_MEMBER: The user is a member of the group with no special privileges. - * - * GROUP_ADMIN: The user is an administrator within the group. - * - * GROUP_OWNER: The user is the owner of the group. - */ -struct QEVERCLOUD_EXPORT SponsoredGroupRole { - enum type { - GROUP_MEMBER = 1, - GROUP_ADMIN = 2, - GROUP_OWNER = 3 - }; -}; - -/** - * Enumeration of the roles that a User can have within an Evernote Business account. - * - * ADMIN: The user is an administrator of the Evernote Business account. - * - * NORMAL: The user is a regular user within the Evernote Business account. - */ -struct QEVERCLOUD_EXPORT BusinessUserRole { - enum type { - ADMIN = 1, - NORMAL = 2 - }; -}; - -/** - * The BusinessUserStatus indicates the status of the user in the business. - * - * A BusinessUser will typically start as ACTIVE. - * Only ACTIVE users can authenticate to the Business. - * - *
    - *
    ACTIVE
    - *
    The business user can authenticate to and access the business.
    - *
    DEACTIVATED
    - *
    The business user has been deactivated and cannot access the business
    - *
    - */ -struct QEVERCLOUD_EXPORT BusinessUserStatus { - enum type { - ACTIVE = 1, - DEACTIVATED = 2 - }; -}; - -/** - * An enumeration describing restrictions on the domain of shared notebook - * instances that are valid for a given operation, as used, for example, in - * NotebookRestrictions. - * - * ASSIGNED: The domain consists of shared notebooks that belong, or are assigned, - * to the recipient. - * - * NO_SHARED_NOTEBOOKS: No shared notebooks are applicable to the operation. - */ -struct QEVERCLOUD_EXPORT SharedNotebookInstanceRestrictions { - enum type { - ASSIGNED = 1, - NO_SHARED_NOTEBOOKS = 2 - }; -}; - -/** - * An enumeration describing the configuration state related to receiving - * reminder e-mails from the service. Reminder e-mails summarize notes - * based on their Note.attributes.reminderTime values. - * - * DO_NOT_SEND: The user has selected to not receive reminder e-mail. - * - * SEND_DAILY_EMAIL: The user has selected to receive reminder e-mail for those - * days when there is a reminder. - */ -struct QEVERCLOUD_EXPORT ReminderEmailConfig { - enum type { - DO_NOT_SEND = 1, - SEND_DAILY_EMAIL = 2 - }; -}; - -/** - * An enumeration defining the possible states of a BusinessInvitation. - * - * APPROVED: The invitation was created or approved by a business admin and may be redeemed by the - * invited email. - * - * REQUESTED: The invitation was requested by a non-admin member of the business and must be - * approved by an admin before it may be redeemed. Invitations in this state do not count - * against a business' seat limit. - * - * REDEEMED: The invitation has already been redeemed. Invitations in this state do not count - * against a business' seat limit. - */ -struct QEVERCLOUD_EXPORT BusinessInvitationStatus { - enum type { - APPROVED = 0, - REQUESTED = 1, - REDEEMED = 2 - }; -}; - -/** - * What kinds of Contacts does the Evernote service know about? - */ -struct QEVERCLOUD_EXPORT ContactType { - enum type { - EVERNOTE = 1, - SMS = 2, - FACEBOOK = 3, - EMAIL = 4, - TWITTER = 5, - LINKEDIN = 6 - }; -}; - -/** - * Entity types - */ -struct QEVERCLOUD_EXPORT EntityType { - enum type { - NOTE = 1, - NOTEBOOK = 2, - WORKSPACE = 3 - }; -}; - -/** - * This enumeration defines the possible states that a notebook can be in for a recipient. - * It encompasses the "inMyList" boolean and default notebook status. - * - *
    - *
    NOT_IN_MY_LIST
    - *
    The notebook is not in the recipient's list (not "joined").
    - *
    IN_MY_LIST
    - *
    The notebook is in the recipient's notebook list (formerly, we would say - * that the recipient has "joined" the notebook)
    - *
    IN_MY_LIST_AND_DEFAULT_NOTEBOOK
    - *
    The same as IN_MY_LIST and this notebook is the user's default notebook.
    - *
    - */ -struct QEVERCLOUD_EXPORT RecipientStatus { - enum type { - NOT_IN_MY_LIST = 1, - IN_MY_LIST = 2, - IN_MY_LIST_AND_DEFAULT_NOTEBOOK = 3 - }; -}; - -/** - * This enumeration defines the possible types of canMoveToContainer outcomes. - *

    - * An outdated client is expected to signal a "Cannot Move, Please Upgrade To Learn Why" - * like response to the user if an unknown enumeration value is received. - *

    - *
    CAN_BE_MOVED
    - *
    Can move Notebook to Workspace.
    - *
    INSUFFICIENT_ENTITY_PRIVILEGE
    - *
    Can not move Notebook to Workspace, because either: - * a) Notebook not in Workspace and insufficient privilege on Notebook - * or b) Notebook in Workspace and membership on Workspace with insufficient privilege - * for move
    - *
    INSUFFICIENT_CONTAINER_PRIVILEGE
    - *
    Notebook in Workspace and no membership on Workspace. - *
    - *
    - */ -struct QEVERCLOUD_EXPORT CanMoveToContainerStatus { - enum type { - CAN_BE_MOVED = 1, - INSUFFICIENT_ENTITY_PRIVILEGE = 2, - INSUFFICIENT_CONTAINER_PRIVILEGE = 3 - }; -}; - -/** - * This enumeration defines the possible types of related content. - * - * NEWS_ARTICLE: This related content is a news article - * PROFILE_PERSON: This match refers to the profile of an individual person - * PROFILE_ORGANIZATION: This match refers to the profile of an organization - * REFERENCE_MATERIAL: This related content is material from reference works - */ -struct QEVERCLOUD_EXPORT RelatedContentType { - enum type { - NEWS_ARTICLE = 1, - PROFILE_PERSON = 2, - PROFILE_ORGANIZATION = 3, - REFERENCE_MATERIAL = 4 - }; -}; - -/** - * This enumeration defines the possible ways to access related content. - * - * NOT_ACCESSIBLE: The content is not accessible given the user's privilege level, but - * still worth showing as a snippet. The content url may point to a webpage that - * explains why not, or explains how to access that content. - * - * DIRECT_LINK_ACCESS_OK: The content is accessible directly, and no additional login is - * required. - * - * DIRECT_LINK_LOGIN_REQUIRED: The content is accessible directly, but an additional login - * is required. - * - * DIRECT_LINK_EMBEDDED_VIEW: The content is accessible directly, and should be shown in - * an embedded web view. - * If the URL refers to a secured location under our control (for example, - * https://www.evernote.com/), the client may include user-specific authentication - * credentials with the request. - */ -struct QEVERCLOUD_EXPORT RelatedContentAccess { - enum type { - NOT_ACCESSIBLE = 0, - DIRECT_LINK_ACCESS_OK = 1, - DIRECT_LINK_LOGIN_REQUIRED = 2, - DIRECT_LINK_EMBEDDED_VIEW = 3 - }; -}; - -/** - * - */ -struct QEVERCLOUD_EXPORT UserIdentityType { - enum type { - EVERNOTE_USERID = 1, - EMAIL = 2, - IDENTITYID = 3 - }; -}; - - /** * A monotonically incrementing number on each shard that identifies a cross shard * cache invalidation event. */ -typedef qint64 InvalidationSequenceNumber; +using InvalidationSequenceNumber = qint64; /** * A type alias for the primary identifiers for Identity objects. */ -typedef qint64 IdentityID; +using IdentityID = qint64; /** * Every Evernote account is assigned a unique numeric identifier which @@ -506,7 +47,7 @@ typedef qint64 IdentityID; * the (string-based) "username" which is known by the user for login * purposes. The user should have no reason to know their UserID. */ -typedef qint32 UserID; +using UserID = qint32; /** * Most data elements within a user's account (e.g. notebooks, notes, tags, @@ -518,7 +59,7 @@ typedef qint32 UserID; * The internal components of the GUID are not given any particular meaning: * only the entire string is relevant as a unique identifier. */ -typedef QString Guid; +using Guid = QString; /** * An Evernote Timestamp is the date and time of an event in UTC time. @@ -537,28 +78,104 @@ typedef QString Guid; * The service will accept timestamp values (e.g. for Note created and update * times) between 1000-01-01 and 9999-12-31 */ -typedef qint64 Timestamp; +using Timestamp = qint64; /** * A sequence number for the MessageStore subsystem. */ -typedef qint64 MessageEventID; +using MessageEventID = qint64; /** * A type alias for the primary identifiers for MessageThread objects. */ -typedef qint64 MessageThreadID; +using MessageThreadID = qint64; +/** + * @brief The EverCloudLocalData class contains several + * data elements which are not synchronized with Evernote service + * but which are nevertheless useful in applications using + * QEverCloud to implement feature rich full sync Evernote clients. + * Values of this class' types are contained within QEverCloud + * types corresponding to actual Evernote API types + */ +class QEVERCLOUD_EXPORT EverCloudLocalData: public Printable +{ + Q_GADGET +public: + EverCloudLocalData(); + virtual ~EverCloudLocalData() noexcept override; + + virtual void print(QTextStream & strm) const override; + + bool operator==(const EverCloudLocalData & other) const; + bool operator!=(const EverCloudLocalData & other) const; + /** + * @brief id property can be used as a local unique identifier + * for any data item before it has been synchronized with + * Evernote and thus before it can be identified using its guid. + * + * id property is generated automatically on EverCloudLocalData + * construction for convenience but can be overridden manually + */ + QString id; + + /** + * @brief dirty property can be used to keep track which + * objects have been modified locally and thus need to be synchronized + * with Evernote service + */ + bool dirty = false; + + /** + * @brief local property can be used to keep track which + * data items are meant to be local only and thus never be synchronized + * with Evernote service + */ + bool local = false; + + /** + * @brief favorited property can be used to keep track which + * data items were favorited in the client. Unfortunately, + * Evernote has never provided a way to synchronize such + * property between different clients + */ + bool favorited = false; + + /** + * @brief dict can be used for storage of any other auxiliary + * values associated with objects of QEverCloud types + */ + QHash dict; + + // Properties declaration for meta-object system + Q_PROPERTY(QString id MEMBER id USER true) + Q_PROPERTY(bool dirty MEMBER dirty) + Q_PROPERTY(bool local MEMBER local) + Q_PROPERTY(bool favorited MEMBER favorited) + + using Dict = QHash; + Q_PROPERTY(Dict dict MEMBER dict) +}; + /** * This structure encapsulates the information about the state of the * user's account for the purpose of "state based" synchronization. * */ -struct QEVERCLOUD_EXPORT SyncState { +struct QEVERCLOUD_EXPORT SyncState: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The server's current date and time. */ - Timestamp currentTime; + Timestamp currentTime = 0; /** The cutoff date and time for client caches to be updated via incremental synchronization. Any clients that were last @@ -566,7 +183,7 @@ struct QEVERCLOUD_EXPORT SyncState { objects. This cutoff point will change over time as archival data is deleted or special circumstances on the service require resynchronization. */ - Timestamp fullSyncBefore; + Timestamp fullSyncBefore = 0; /** Indicates the total number of transactions that have been committed within the account. This reflects (for example) the @@ -575,7 +192,7 @@ struct QEVERCLOUD_EXPORT SyncState { This number is the "high water mark" for Update Sequence Numbers (USN) within the account. */ - qint32 updateCount; + qint32 updateCount = 0; /** The total number of bytes that have been uploaded to this account in the current monthly period. This can be compared against @@ -584,7 +201,7 @@ struct QEVERCLOUD_EXPORT SyncState { This value may not be present if the SyncState has been retrieved by a caller that only has read access to the account. */ - Optional< qint64 > uploaded; + Optional uploaded; /** The last time when a user's account level information was changed. This value is the latest time when a modification was made to any of the following: @@ -604,7 +221,7 @@ struct QEVERCLOUD_EXPORT SyncState {
  • Update previousValue = SyncState.userLastUpdated
  • */ - Optional< Timestamp > userLastUpdated; + Optional userLastUpdated; /** The greatest MessageEventID for this user's account. Clients that do a full sync should store this value locally and compare their local copy to the @@ -612,7 +229,9 @@ struct QEVERCLOUD_EXPORT SyncState { MessageStore. This value will be omitted if the user has never sent or received a message. */ - Optional< MessageEventID > userMaxMessageEventId; + Optional userMaxMessageEventId; + + virtual void print(QTextStream & strm) const override; bool operator==(const SyncState & other) const { @@ -630,6 +249,13 @@ struct QEVERCLOUD_EXPORT SyncState { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Timestamp currentTime MEMBER currentTime) + Q_PROPERTY(Timestamp fullSyncBefore MEMBER fullSyncBefore) + Q_PROPERTY(qint32 updateCount MEMBER updateCount) + Q_PROPERTY(Optional uploaded MEMBER uploaded) + Q_PROPERTY(Optional userLastUpdated MEMBER userLastUpdated) + Q_PROPERTY(Optional userMaxMessageEventId MEMBER userMaxMessageEventId) }; /** @@ -639,35 +265,44 @@ struct QEVERCLOUD_EXPORT SyncState { * whether to include one class of data in the results of that call. * **/ -struct QEVERCLOUD_EXPORT SyncChunkFilter { +struct QEVERCLOUD_EXPORT SyncChunkFilter: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** If true, then the server will include the SyncChunks.notes field */ - Optional< bool > includeNotes; + Optional includeNotes; /** If true, then the server will include the 'resources' field on all of the Notes that are in SyncChunk.notes. If 'includeNotes' is false, then this will have no effect. */ - Optional< bool > includeNoteResources; + Optional includeNoteResources; /** If true, then the server will include the 'attributes' field on all of the Notes that are in SyncChunks.notes. If 'includeNotes' is false, then this will have no effect. */ - Optional< bool > includeNoteAttributes; + Optional includeNoteAttributes; /** If true, then the server will include the SyncChunks.notebooks field */ - Optional< bool > includeNotebooks; + Optional includeNotebooks; /** If true, then the server will include the SyncChunks.tags field */ - Optional< bool > includeTags; + Optional includeTags; /** If true, then the server will include the SyncChunks.searches field */ - Optional< bool > includeSearches; + Optional includeSearches; /** If true, then the server will include the SyncChunks.resources field. Since the Resources are also provided with their Note @@ -675,52 +310,52 @@ struct QEVERCLOUD_EXPORT SyncChunkFilter { want to watch for changes to individual Resources due to recognition data being added. */ - Optional< bool > includeResources; + Optional includeResources; /** If true, then the server will include the SyncChunks.linkedNotebooks field. */ - Optional< bool > includeLinkedNotebooks; + Optional includeLinkedNotebooks; /** If true, then the server will include the 'expunged' data for any type of included data. For example, if 'includeTags' and 'includeExpunged' are both true, then the SyncChunks.expungedTags field will be set with the GUIDs of tags that have been expunged from the server. */ - Optional< bool > includeExpunged; + Optional includeExpunged; /** If true, then the values for the applicationData map will be filled in, assuming notes and note attributes are being returned. Otherwise, only the keysOnly field will be filled in. */ - Optional< bool > includeNoteApplicationDataFullMap; + Optional includeNoteApplicationDataFullMap; /** If true, then the fullMap values for the applicationData map will be filled in, assuming resources and resource attributes are being returned (includeResources is true). Otherwise, only the keysOnly field will be filled in. */ - Optional< bool > includeResourceApplicationDataFullMap; + Optional includeResourceApplicationDataFullMap; /** If true, then the fullMap values for the applicationData map will be filled in for resources found inside of notes, assuming resources are being returned in notes (includeNoteResources is true). Otherwise, only the keysOnly field will be filled in. */ - Optional< bool > includeNoteResourceApplicationDataFullMap; + Optional includeNoteResourceApplicationDataFullMap; /** If true, then the service will include the sharedNotes field on all notes that are in SyncChunk.notes. If 'includeNotes' is false, then this will have no effect. */ - Optional< bool > includeSharedNotes; + Optional includeSharedNotes; /** NOT DOCUMENTED */ - Optional< bool > omitSharedNotebooks; + Optional omitSharedNotebooks; /** If set, then only send notes whose content class matches this value. The value can be a literal match or, if the last character is an asterisk, a prefix match. */ - Optional< QString > requireNoteContentClass; + Optional requireNoteContentClass; /** If set, then restrict the returned notebooks, notes, and resources to those associated with one of the notebooks whose @@ -738,7 +373,9 @@ struct QEVERCLOUD_EXPORT SyncChunkFilter { includeNotebooks, includeNoteAttributes, includeNoteResources, and maybe some of the "FullMap" fields. */ - Optional< QSet< QString > > notebookGuids; + Optional> notebookGuids; + + virtual void print(QTextStream & strm) const override; bool operator==(const SyncChunkFilter & other) const { @@ -766,6 +403,23 @@ struct QEVERCLOUD_EXPORT SyncChunkFilter { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional includeNotes MEMBER includeNotes) + Q_PROPERTY(Optional includeNoteResources MEMBER includeNoteResources) + Q_PROPERTY(Optional includeNoteAttributes MEMBER includeNoteAttributes) + Q_PROPERTY(Optional includeNotebooks MEMBER includeNotebooks) + Q_PROPERTY(Optional includeTags MEMBER includeTags) + Q_PROPERTY(Optional includeSearches MEMBER includeSearches) + Q_PROPERTY(Optional includeResources MEMBER includeResources) + Q_PROPERTY(Optional includeLinkedNotebooks MEMBER includeLinkedNotebooks) + Q_PROPERTY(Optional includeExpunged MEMBER includeExpunged) + Q_PROPERTY(Optional includeNoteApplicationDataFullMap MEMBER includeNoteApplicationDataFullMap) + Q_PROPERTY(Optional includeResourceApplicationDataFullMap MEMBER includeResourceApplicationDataFullMap) + Q_PROPERTY(Optional includeNoteResourceApplicationDataFullMap MEMBER includeNoteResourceApplicationDataFullMap) + Q_PROPERTY(Optional includeSharedNotes MEMBER includeSharedNotes) + Q_PROPERTY(Optional omitSharedNotebooks MEMBER omitSharedNotebooks) + Q_PROPERTY(Optional requireNoteContentClass MEMBER requireNoteContentClass) + Q_PROPERTY(Optional> notebookGuids MEMBER notebookGuids) }; /** @@ -774,32 +428,41 @@ struct QEVERCLOUD_EXPORT SyncChunkFilter { * which notes should be retrieved. * **/ -struct QEVERCLOUD_EXPORT NoteFilter { +struct QEVERCLOUD_EXPORT NoteFilter: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The NoteSortOrder value indicating what criterion should be used to sort the results of the filter. */ - Optional< qint32 > order; + Optional order; /** If true, the results will be ascending in the requested sort order. If false, the results will be descending. */ - Optional< bool > ascending; + Optional ascending; /** If present, a search query string that will filter the set of notes to be returned. Accepts the full search grammar documented in the Evernote API Overview. */ - Optional< QString > words; + Optional words; /** If present, the Guid of the notebook that must contain the notes. */ - Optional< Guid > notebookGuid; + Optional notebookGuid; /** If present, the list of tags (by GUID) that must be present on the notes. */ - Optional< QList< Guid > > tagGuids; + Optional> tagGuids; /** The zone ID for the user, which will be used to interpret any dates or times in the queries that do not include their desired zone @@ -809,50 +472,52 @@ struct QEVERCLOUD_EXPORT NoteFilter { The format must be encoded as a standard zone ID such as "America/Los_Angeles". */ - Optional< QString > timeZone; + Optional timeZone; /** If true, then only notes that are not active (i.e. notes in the Trash) will be returned. Otherwise, only active notes will be returned. There is no way to find both active and inactive notes in a single query. */ - Optional< bool > inactive; + Optional inactive; /** If present, a search query string that may or may not influence the notes to be returned, both in terms of coverage as well as of order. Think of it as a wish list, not a requirement. Accepts the full search grammar documented in the Evernote API Overview. */ - Optional< QString > emphasized; + Optional emphasized; /** If true, then the search will include all business notebooks that are readable by the user. A business authentication token must be supplied for this option to take effect when calling search APIs. */ - Optional< bool > includeAllReadableNotebooks; + Optional includeAllReadableNotebooks; /** If true, then the search will include all workspaces that are readable by the user. A business authentication token must be supplied for this option to take effect when calling search APIs. */ - Optional< bool > includeAllReadableWorkspaces; + Optional includeAllReadableWorkspaces; /** Specifies the context to consider when determining result ranking. Clients must leave this value unset unless they wish to explicitly specify a known non-default context. */ - Optional< QString > context; + Optional context; /** If present, the raw user query input. Accepts the full search grammar documented in the Evernote API Overview. */ - Optional< QString > rawWords; + Optional rawWords; /** Specifies the correlating information about the current search session, in byte array. If this request is not for the first page of search results, the client should populate this field with the value of searchContextBytes from the NotesMetadataList of the original search response. */ - Optional< QByteArray > searchContextBytes; + Optional searchContextBytes; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteFilter & other) const { @@ -877,6 +542,20 @@ struct QEVERCLOUD_EXPORT NoteFilter { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional order MEMBER order) + Q_PROPERTY(Optional ascending MEMBER ascending) + Q_PROPERTY(Optional words MEMBER words) + Q_PROPERTY(Optional notebookGuid MEMBER notebookGuid) + Q_PROPERTY(Optional> tagGuids MEMBER tagGuids) + Q_PROPERTY(Optional timeZone MEMBER timeZone) + Q_PROPERTY(Optional inactive MEMBER inactive) + Q_PROPERTY(Optional emphasized MEMBER emphasized) + Q_PROPERTY(Optional includeAllReadableNotebooks MEMBER includeAllReadableNotebooks) + Q_PROPERTY(Optional includeAllReadableWorkspaces MEMBER includeAllReadableWorkspaces) + Q_PROPERTY(Optional context MEMBER context) + Q_PROPERTY(Optional rawWords MEMBER rawWords) + Q_PROPERTY(Optional searchContextBytes MEMBER searchContextBytes) }; /** @@ -892,29 +571,40 @@ struct QEVERCLOUD_EXPORT NoteFilter { * 'false' by the server, so the default behavior is to include nothing in * replies (but the mandatory GUID) */ -struct QEVERCLOUD_EXPORT NotesMetadataResultSpec { +struct QEVERCLOUD_EXPORT NotesMetadataResultSpec: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** NOT DOCUMENTED */ - Optional< bool > includeTitle; + Optional includeTitle; /** NOT DOCUMENTED */ - Optional< bool > includeContentLength; + Optional includeContentLength; /** NOT DOCUMENTED */ - Optional< bool > includeCreated; + Optional includeCreated; /** NOT DOCUMENTED */ - Optional< bool > includeUpdated; + Optional includeUpdated; /** NOT DOCUMENTED */ - Optional< bool > includeDeleted; + Optional includeDeleted; /** NOT DOCUMENTED */ - Optional< bool > includeUpdateSequenceNum; + Optional includeUpdateSequenceNum; /** NOT DOCUMENTED */ - Optional< bool > includeNotebookGuid; + Optional includeNotebookGuid; /** NOT DOCUMENTED */ - Optional< bool > includeTagGuids; + Optional includeTagGuids; /** NOT DOCUMENTED */ - Optional< bool > includeAttributes; + Optional includeAttributes; /** NOT DOCUMENTED */ - Optional< bool > includeLargestResourceMime; + Optional includeLargestResourceMime; /** NOT DOCUMENTED */ - Optional< bool > includeLargestResourceSize; + Optional includeLargestResourceSize; + + virtual void print(QTextStream & strm) const override; bool operator==(const NotesMetadataResultSpec & other) const { @@ -937,6 +627,18 @@ struct QEVERCLOUD_EXPORT NotesMetadataResultSpec { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional includeTitle MEMBER includeTitle) + Q_PROPERTY(Optional includeContentLength MEMBER includeContentLength) + Q_PROPERTY(Optional includeCreated MEMBER includeCreated) + Q_PROPERTY(Optional includeUpdated MEMBER includeUpdated) + Q_PROPERTY(Optional includeDeleted MEMBER includeDeleted) + Q_PROPERTY(Optional includeUpdateSequenceNum MEMBER includeUpdateSequenceNum) + Q_PROPERTY(Optional includeNotebookGuid MEMBER includeNotebookGuid) + Q_PROPERTY(Optional includeTagGuids MEMBER includeTagGuids) + Q_PROPERTY(Optional includeAttributes MEMBER includeAttributes) + Q_PROPERTY(Optional includeLargestResourceMime MEMBER includeLargestResourceMime) + Q_PROPERTY(Optional includeLargestResourceSize MEMBER includeLargestResourceSize) }; /** @@ -944,24 +646,35 @@ struct QEVERCLOUD_EXPORT NotesMetadataResultSpec { * and tag with a non-zero set of applicable notes. * **/ -struct QEVERCLOUD_EXPORT NoteCollectionCounts { +struct QEVERCLOUD_EXPORT NoteCollectionCounts: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** A mapping from the Notebook GUID to the number of notes (from some selection) that are in the corresponding notebook. */ - Optional< QMap< Guid, qint32 > > notebookCounts; + Optional> notebookCounts; /** A mapping from the Tag GUID to the number of notes (from some selection) that have the corresponding tag. */ - Optional< QMap< Guid, qint32 > > tagCounts; + Optional> tagCounts; /** If this is set, then this is the number of notes that are in the trash. If this is not set, then the number of notes in the trash hasn't been reported. (I.e. if there are no notes in the trash, this will be set to 0.) */ - Optional< qint32 > trashCount; + Optional trashCount; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteCollectionCounts & other) const { @@ -976,6 +689,12 @@ struct QEVERCLOUD_EXPORT NoteCollectionCounts { return !(*this == other); } + using TagCounts = QMap; + + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional notebookCounts MEMBER notebookCounts) + Q_PROPERTY(Optional tagCounts MEMBER tagCounts) + Q_PROPERTY(Optional trashCount MEMBER trashCount) }; /** @@ -988,42 +707,53 @@ struct QEVERCLOUD_EXPORT NoteCollectionCounts { * so that the default behavior is to include none of the fields below in the Note. * * */ -struct QEVERCLOUD_EXPORT NoteResultSpec { +struct QEVERCLOUD_EXPORT NoteResultSpec: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** If true, the Note.content field will be populated with the note's ENML contents. */ - Optional< bool > includeContent; + Optional includeContent; /** If true, any Resource elements will include the binary contents of their 'data' field's body. */ - Optional< bool > includeResourcesData; + Optional includeResourcesData; /** If true, any Resource elements will include the binary contents of their 'recognition' field's body if recognition data is available. */ - Optional< bool > includeResourcesRecognition; + Optional includeResourcesRecognition; /** If true, any Resource elements will include the binary contents of their 'alternateData' field's body, if an alternate form is available. */ - Optional< bool > includeResourcesAlternateData; + Optional includeResourcesAlternateData; /** If true, the Note.sharedNotes field will be populated with the note's shares. */ - Optional< bool > includeSharedNotes; + Optional includeSharedNotes; /** If true, the Note.attributes.applicationData.fullMap field will be populated. */ - Optional< bool > includeNoteAppDataValues; + Optional includeNoteAppDataValues; /** If true, the Note.resource.attributes.applicationData.fullMap field will be populated. */ - Optional< bool > includeResourceAppDataValues; + Optional includeResourceAppDataValues; /** If true, the Note.limits field will be populated with the note owner's account limits. */ - Optional< bool > includeAccountLimits; + Optional includeAccountLimits; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteResultSpec & other) const { @@ -1043,6 +773,15 @@ struct QEVERCLOUD_EXPORT NoteResultSpec { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional includeContent MEMBER includeContent) + Q_PROPERTY(Optional includeResourcesData MEMBER includeResourcesData) + Q_PROPERTY(Optional includeResourcesRecognition MEMBER includeResourcesRecognition) + Q_PROPERTY(Optional includeResourcesAlternateData MEMBER includeResourcesAlternateData) + Q_PROPERTY(Optional includeSharedNotes MEMBER includeSharedNotes) + Q_PROPERTY(Optional includeNoteAppDataValues MEMBER includeNoteAppDataValues) + Q_PROPERTY(Optional includeResourceAppDataValues MEMBER includeResourceAppDataValues) + Q_PROPERTY(Optional includeAccountLimits MEMBER includeAccountLimits) }; /** @@ -1051,13 +790,22 @@ struct QEVERCLOUD_EXPORT NoteResultSpec { * call. * * */ -struct QEVERCLOUD_EXPORT NoteVersionId { +struct QEVERCLOUD_EXPORT NoteVersionId: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The update sequence number for the Note when it last had this content. This serves to uniquely identify each version of the note, since USN values are unique within an account for each update. */ - qint32 updateSequenceNum; + qint32 updateSequenceNum = 0; /** The 'updated' time that was set on the Note when it had this version of the content. This is the user-modifiable modification time on the @@ -1065,12 +813,12 @@ struct QEVERCLOUD_EXPORT NoteVersionId { versions. (E.g. if someone modifies the note, then changes this time manually into the past and then updates the note again.) */ - Timestamp updated; + Timestamp updated = 0; /** A timestamp that holds the date and time when this version of the note was backed up by Evernote's servers. */ - Timestamp saved; + Timestamp saved = 0; /** The title of the note when this particular version was saved. (The current title of the note may differ from this value.) @@ -1080,7 +828,9 @@ struct QEVERCLOUD_EXPORT NoteVersionId { The ID of the user who made the change to this version of the note. This will be unset if the note version was edited by the owner of the account. */ - Optional< UserID > lastEditorId; + Optional lastEditorId; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteVersionId & other) const { @@ -1097,6 +847,12 @@ struct QEVERCLOUD_EXPORT NoteVersionId { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(qint32 updateSequenceNum MEMBER updateSequenceNum) + Q_PROPERTY(Timestamp updated MEMBER updated) + Q_PROPERTY(Timestamp saved MEMBER saved) + Q_PROPERTY(QString title MEMBER title) + Q_PROPERTY(Optional lastEditorId MEMBER lastEditorId) }; /** @@ -1107,36 +863,45 @@ struct QEVERCLOUD_EXPORT NoteVersionId { * not both. filter and referenceUri are optional. * * */ -struct QEVERCLOUD_EXPORT RelatedQuery { +struct QEVERCLOUD_EXPORT RelatedQuery: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The GUID of an existing note in your account for which related entities will be found. */ - Optional< QString > noteGuid; + Optional noteGuid; /** A string of plain text for which to find related entities. You should provide a text block with a number of characters between EDAM_RELATED_PLAINTEXT_LEN_MIN and EDAM_RELATED_PLAINTEXT_LEN_MAX. */ - Optional< QString > plainText; + Optional plainText; /** The list of criteria that will constrain the notes being considered related. Please note that some of the parameters may be ignored, such as order and ascending. */ - Optional< NoteFilter > filter; + Optional filter; /** A URI string specifying a reference entity, around which "relatedness" should be based. This can be an URL pointing to a web page, for example. */ - Optional< QString > referenceUri; + Optional referenceUri; /** Specifies the context to consider when determining related results. Clients must leave this value unset unless they wish to explicitly specify a known non-default context. */ - Optional< QString > context; + Optional context; /** If set and non-empty, this is an indicator for the server whether it is actually necessary to perform a new findRelated call at all. Cache Keys are opaque strings @@ -1148,7 +913,9 @@ struct QEVERCLOUD_EXPORT RelatedQuery { If not set, the server will not attempt to generate a cache key at all. */ - Optional< QString > cacheKey; + Optional cacheKey; + + virtual void print(QTextStream & strm) const override; bool operator==(const RelatedQuery & other) const { @@ -1166,6 +933,13 @@ struct QEVERCLOUD_EXPORT RelatedQuery { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional noteGuid MEMBER noteGuid) + Q_PROPERTY(Optional plainText MEMBER plainText) + Q_PROPERTY(Optional filter MEMBER filter) + Q_PROPERTY(Optional referenceUri MEMBER referenceUri) + Q_PROPERTY(Optional context MEMBER context) + Q_PROPERTY(Optional cacheKey MEMBER cacheKey) }; /** @@ -1175,64 +949,75 @@ struct QEVERCLOUD_EXPORT RelatedQuery { * RelatedResult. * * */ -struct QEVERCLOUD_EXPORT RelatedResultSpec { +struct QEVERCLOUD_EXPORT RelatedResultSpec: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** Return notes that are related to the query, but no more than this many. Any value greater than EDAM_RELATED_MAX_NOTES will be silently capped. If you do not set this field, then no notes will be returned. */ - Optional< qint32 > maxNotes; + Optional maxNotes; /** Return notebooks that are related to the query, but no more than this many. Any value greater than EDAM_RELATED_MAX_NOTEBOOKS will be silently capped. If you do not set this field, then no notebooks will be returned. */ - Optional< qint32 > maxNotebooks; + Optional maxNotebooks; /** Return tags that are related to the query, but no more than this many. Any value greater than EDAM_RELATED_MAX_TAGS will be silently capped. If you do not set this field, then no tags will be returned. */ - Optional< qint32 > maxTags; + Optional maxTags; /** Require that all returned related notebooks are writable. The user will be able to create notes in all returned notebooks. However, individual notes returned may still belong to notebooks in which the user lacks the ability to create notes. */ - Optional< bool > writableNotebooksOnly; + Optional writableNotebooksOnly; /** If set to true, return the containingNotebooks field in the RelatedResult, which will contain the list of notebooks to to which the returned related notes belong. */ - Optional< bool > includeContainingNotebooks; + Optional includeContainingNotebooks; /** If set to true, indicate that debug information should be returned in the 'debugInfo' field of RelatedResult. Note that the call may be slower if this flag is set. */ - Optional< bool > includeDebugInfo; + Optional includeDebugInfo; /** This can only be used when making a findRelated call against a business. Find users within your business who have knowledge about the specified query. No more than this many users will be returned. Any value greater than EDAM_RELATED_MAX_EXPERTS will be silently capped. */ - Optional< qint32 > maxExperts; + Optional maxExperts; /** Return snippets of related content that is related to the query, but no more than this many. Any value greater than EDAM_RELATED_MAX_RELATED_CONTENT will be silently capped. If you do not set this field, then no related content will be returned. */ - Optional< qint32 > maxRelatedContent; + Optional maxRelatedContent; /** Specifies the types of Related Content that should be returned. */ - Optional< QSet< RelatedContentType::type > > relatedContentTypes; + Optional> relatedContentTypes; + + virtual void print(QTextStream & strm) const override; bool operator==(const RelatedResultSpec & other) const { @@ -1253,18 +1038,39 @@ struct QEVERCLOUD_EXPORT RelatedResultSpec { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional maxNotes MEMBER maxNotes) + Q_PROPERTY(Optional maxNotebooks MEMBER maxNotebooks) + Q_PROPERTY(Optional maxTags MEMBER maxTags) + Q_PROPERTY(Optional writableNotebooksOnly MEMBER writableNotebooksOnly) + Q_PROPERTY(Optional includeContainingNotebooks MEMBER includeContainingNotebooks) + Q_PROPERTY(Optional includeDebugInfo MEMBER includeDebugInfo) + Q_PROPERTY(Optional maxExperts MEMBER maxExperts) + Q_PROPERTY(Optional maxRelatedContent MEMBER maxRelatedContent) + Q_PROPERTY(Optional> relatedContentTypes MEMBER relatedContentTypes) }; /** NO DOC COMMENT ID FOUND */ -struct QEVERCLOUD_EXPORT ShareRelationshipRestrictions { +struct QEVERCLOUD_EXPORT ShareRelationshipRestrictions: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** NOT DOCUMENTED */ - Optional< bool > noSetReadOnly; + Optional noSetReadOnly; /** NOT DOCUMENTED */ - Optional< bool > noSetReadPlusActivity; + Optional noSetReadPlusActivity; /** NOT DOCUMENTED */ - Optional< bool > noSetModify; + Optional noSetModify; /** NOT DOCUMENTED */ - Optional< bool > noSetFullAccess; + Optional noSetFullAccess; + + virtual void print(QTextStream & strm) const override; bool operator==(const ShareRelationshipRestrictions & other) const { @@ -1280,6 +1086,11 @@ struct QEVERCLOUD_EXPORT ShareRelationshipRestrictions { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional noSetReadOnly MEMBER noSetReadOnly) + Q_PROPERTY(Optional noSetReadPlusActivity MEMBER noSetReadPlusActivity) + Q_PROPERTY(Optional noSetModify MEMBER noSetModify) + Q_PROPERTY(Optional noSetFullAccess MEMBER noSetFullAccess) }; /** @@ -1287,16 +1098,25 @@ struct QEVERCLOUD_EXPORT ShareRelationshipRestrictions { * a member of that notebook. * * */ -struct QEVERCLOUD_EXPORT MemberShareRelationship { +struct QEVERCLOUD_EXPORT MemberShareRelationship: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The string that clients should show to users to represent this member. */ - Optional< QString > displayName; + Optional displayName; /** The Evernote User ID of the recipient of this notebook share. */ - Optional< UserID > recipientUserId; + Optional recipientUserId; /** The privilege at which the member can access the notebook, which is the best privilege granted either individually or to a @@ -1304,7 +1124,7 @@ struct QEVERCLOUD_EXPORT MemberShareRelationship { used by the service to convey information to the user, so clients should treat it as read-only. */ - Optional< ShareRelationshipPrivilegeLevel::type > bestPrivilege; + Optional bestPrivilege; /** The individually granted privilege for the member, which does not take GROUP privileges into account. This value may be unset if @@ -1314,12 +1134,12 @@ struct QEVERCLOUD_EXPORT MemberShareRelationship { should present to users for selection are given via the the 'restrictions' field. */ - Optional< ShareRelationshipPrivilegeLevel::type > individualPrivilege; + Optional individualPrivilege; /** The restrictions on which privileges may be individually assigned to the recipient of this share relationship. */ - Optional< ShareRelationshipRestrictions > restrictions; + Optional restrictions; /** The user id of the user who most recently shared the notebook to this user. This field is currently unset for a MemberShareRelationship @@ -1328,7 +1148,9 @@ struct QEVERCLOUD_EXPORT MemberShareRelationship { This field is used by the service to convey information to the user, so clients should treat it as read-only. */ - Optional< UserID > sharerUserId; + Optional sharerUserId; + + virtual void print(QTextStream & strm) const override; bool operator==(const MemberShareRelationship & other) const { @@ -1346,6 +1168,13 @@ struct QEVERCLOUD_EXPORT MemberShareRelationship { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional displayName MEMBER displayName) + Q_PROPERTY(Optional recipientUserId MEMBER recipientUserId) + Q_PROPERTY(Optional bestPrivilege MEMBER bestPrivilege) + Q_PROPERTY(Optional individualPrivilege MEMBER individualPrivilege) + Q_PROPERTY(Optional restrictions MEMBER restrictions) + Q_PROPERTY(Optional sharerUserId MEMBER sharerUserId) }; /** @@ -1354,22 +1183,33 @@ struct QEVERCLOUD_EXPORT MemberShareRelationship { * target of a note share relationship. * * */ -struct QEVERCLOUD_EXPORT NoteShareRelationshipRestrictions { +struct QEVERCLOUD_EXPORT NoteShareRelationshipRestrictions: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** This value is true if the user is not allowed to set the privilege level to SharedNotePrivilegeLevel.READ_NOTE. */ - Optional< bool > noSetReadNote; + Optional noSetReadNote; /** This value is true if the user is not allowed to set the privilege level to SharedNotePrivilegeLevel.MODIFY_NOTE. */ - Optional< bool > noSetModifyNote; + Optional noSetModifyNote; /** This value is true if the user is not allowed to set the privilege level to SharedNotePrivilegeLevel.FULL_ACCESS. */ - Optional< bool > noSetFullAccess; + Optional noSetFullAccess; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteShareRelationshipRestrictions & other) const { @@ -1384,6 +1224,10 @@ struct QEVERCLOUD_EXPORT NoteShareRelationshipRestrictions { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional noSetReadNote MEMBER noSetReadNote) + Q_PROPERTY(Optional noSetModifyNote MEMBER noSetModifyNote) + Q_PROPERTY(Optional noSetFullAccess MEMBER noSetFullAccess) }; /** @@ -1391,16 +1235,25 @@ struct QEVERCLOUD_EXPORT NoteShareRelationshipRestrictions { * a member of that note. * * */ -struct QEVERCLOUD_EXPORT NoteMemberShareRelationship { +struct QEVERCLOUD_EXPORT NoteMemberShareRelationship: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The string that clients should show to users to represent this member. */ - Optional< QString > displayName; + Optional displayName; /** The Evernote UserID of the user who is a member to the note. */ - Optional< UserID > recipientUserId; + Optional recipientUserId; /** The privilege at which the member can access the note, which is the best privilege granted to the user across all of their @@ -1408,20 +1261,22 @@ struct QEVERCLOUD_EXPORT NoteMemberShareRelationship { to convey information to the user, so clients should treat it as read-only. */ - Optional< SharedNotePrivilegeLevel::type > privilege; + Optional privilege; /** The restrictions on which privileges may be individually assigned to the recipient of this share relationship. This field is used by the service to convey information to the user, so clients should treat it as read-only. */ - Optional< NoteShareRelationshipRestrictions > restrictions; + Optional restrictions; /** The user id of the user who most recently shared the note with this user. This field is used by the service to convey information to the user, so clients should treat it as read-only. */ - Optional< UserID > sharerUserId; + Optional sharerUserId; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteMemberShareRelationship & other) const { @@ -1438,6 +1293,12 @@ struct QEVERCLOUD_EXPORT NoteMemberShareRelationship { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional displayName MEMBER displayName) + Q_PROPERTY(Optional recipientUserId MEMBER recipientUserId) + Q_PROPERTY(Optional privilege MEMBER privilege) + Q_PROPERTY(Optional restrictions MEMBER restrictions) + Q_PROPERTY(Optional sharerUserId MEMBER sharerUserId) }; /** @@ -1445,12 +1306,21 @@ struct QEVERCLOUD_EXPORT NoteMemberShareRelationship { * to gain access to a note belonging to another user. * * */ -struct QEVERCLOUD_EXPORT NoteInvitationShareRelationship { +struct QEVERCLOUD_EXPORT NoteInvitationShareRelationship: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The string that clients should show to users to represent this invitation. */ - Optional< QString > displayName; + Optional displayName; /** Identifies the identity of the invitation recipient. Once the identity has been claimed by an Evernote user and they have accessed @@ -1458,19 +1328,21 @@ struct QEVERCLOUD_EXPORT NoteInvitationShareRelationship { longer be returned by the service to clients. Instead, that recipient will be included in the list of NoteMemberShareRelationships. */ - Optional< IdentityID > recipientIdentityId; + Optional recipientIdentityId; /** The privilege level that the recipient will be granted when they accept this invitation. If the user already has a higher privilege to access this note then this will not affect the recipient's privileges. */ - Optional< SharedNotePrivilegeLevel::type > privilege; + Optional privilege; /** The user id of the user who most recently shared this note to this recipient. This field is used by the service to convey information to the user, so clients should treat it as read-only. */ - Optional< UserID > sharerUserId; + Optional sharerUserId; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteInvitationShareRelationship & other) const { @@ -1486,6 +1358,11 @@ struct QEVERCLOUD_EXPORT NoteInvitationShareRelationship { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional displayName MEMBER displayName) + Q_PROPERTY(Optional recipientIdentityId MEMBER recipientIdentityId) + Q_PROPERTY(Optional privilege MEMBER privilege) + Q_PROPERTY(Optional sharerUserId MEMBER sharerUserId) }; /** @@ -1495,20 +1372,31 @@ struct QEVERCLOUD_EXPORT NoteInvitationShareRelationship { * invitations that can be used to become members. * * */ -struct QEVERCLOUD_EXPORT NoteShareRelationships { +struct QEVERCLOUD_EXPORT NoteShareRelationships: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** A list of open invitations that can be redeemed into memberships to the note. */ - Optional< QList< NoteInvitationShareRelationship > > invitations; + Optional> invitations; /** A list of memberships of the noteb. A member is identified by their Evernote UserID and has rights to access the note. */ - Optional< QList< NoteMemberShareRelationship > > memberships; + Optional> memberships; /** NOT DOCUMENTED */ - Optional< NoteShareRelationshipRestrictions > invitationRestrictions; + Optional invitationRestrictions; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteShareRelationships & other) const { @@ -1523,6 +1411,10 @@ struct QEVERCLOUD_EXPORT NoteShareRelationships { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional> invitations MEMBER invitations) + Q_PROPERTY(Optional> memberships MEMBER memberships) + Q_PROPERTY(Optional invitationRestrictions MEMBER invitationRestrictions) }; /** @@ -1535,11 +1427,20 @@ struct QEVERCLOUD_EXPORT NoteShareRelationships { * updated by this function is the share privilege. * * */ -struct QEVERCLOUD_EXPORT ManageNoteSharesParameters { +struct QEVERCLOUD_EXPORT ManageNoteSharesParameters: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The GUID of the note whose shares are being managed. */ - Optional< QString > noteGuid; + Optional noteGuid; /** A list of existing memberships to update. This field is not meant to be the full set of memberships for the note. Clients @@ -1547,7 +1448,7 @@ struct QEVERCLOUD_EXPORT ManageNoteSharesParameters { to modify. To remove an existing membership, see the unshares field. */ - Optional< QList< NoteMemberShareRelationship > > membershipsToUpdate; + Optional> membershipsToUpdate; /** The list of outstanding invitations to update, as matched by the identity field of the NoteInvitationShareRelatioship instances. @@ -1555,15 +1456,17 @@ struct QEVERCLOUD_EXPORT ManageNoteSharesParameters { note. Clients should only include those existing invitations that they wish to modify. */ - Optional< QList< NoteInvitationShareRelationship > > invitationsToUpdate; + Optional> invitationsToUpdate; /** A list of existing memberships to expunge from the service. */ - Optional< QList< UserID > > membershipsToUnshare; + Optional> membershipsToUnshare; /** A list of outstanding invitations to expunge from the service. */ - Optional< QList< IdentityID > > invitationsToUnshare; + Optional> invitationsToUnshare; + + virtual void print(QTextStream & strm) const override; bool operator==(const ManageNoteSharesParameters & other) const { @@ -1580,6 +1483,12 @@ struct QEVERCLOUD_EXPORT ManageNoteSharesParameters { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional noteGuid MEMBER noteGuid) + Q_PROPERTY(Optional> membershipsToUpdate MEMBER membershipsToUpdate) + Q_PROPERTY(Optional> invitationsToUpdate MEMBER invitationsToUpdate) + Q_PROPERTY(Optional> membershipsToUnshare MEMBER membershipsToUnshare) + Q_PROPERTY(Optional> invitationsToUnshare MEMBER invitationsToUnshare) }; /** @@ -1591,17 +1500,26 @@ struct QEVERCLOUD_EXPORT ManageNoteSharesParameters { * they are only referenced their metadata. * **/ -struct QEVERCLOUD_EXPORT Data { +struct QEVERCLOUD_EXPORT Data: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** This field carries a one-way hash of the contents of the data body, in binary form. The hash function is MD5
    Length: EDAM_HASH_LEN (exactly) */ - Optional< QByteArray > bodyHash; + Optional bodyHash; /** The length, in bytes, of the data body. */ - Optional< qint32 > size; + Optional size; /** This field is set to contain the binary contents of the data whenever the resource is being transferred. If only metadata is @@ -1609,7 +1527,9 @@ struct QEVERCLOUD_EXPORT Data { notify the service about the change to an attribute for a resource without transmitting the binary resource contents. */ - Optional< QByteArray > body; + Optional body; + + virtual void print(QTextStream & strm) const override; bool operator==(const Data & other) const { @@ -1624,6 +1544,10 @@ struct QEVERCLOUD_EXPORT Data { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional bodyHash MEMBER bodyHash) + Q_PROPERTY(Optional size MEMBER size) + Q_PROPERTY(Optional body MEMBER body) }; /** @@ -1631,37 +1555,46 @@ struct QEVERCLOUD_EXPORT Data { * on a User. These are generally less critical than the core User fields. * **/ -struct QEVERCLOUD_EXPORT UserAttributes { +struct QEVERCLOUD_EXPORT UserAttributes: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** the location string that should be associated with the user in order to determine where notes are taken if not otherwise specified.
    Length: EDAM_ATTRIBUTE_LEN_MIN - EDAM_ATTRIBUTE_LEN_MAX */ - Optional< QString > defaultLocationName; + Optional defaultLocationName; /** if set, this is the latitude that should be assigned to any notes that have no other latitude information. */ - Optional< double > defaultLatitude; + Optional defaultLatitude; /** if set, this is the longitude that should be assigned to any notes that have no other longitude information. */ - Optional< double > defaultLongitude; + Optional defaultLongitude; /** if set, the user account is not yet confirmed for login. I.e. the account has been created, but we are still waiting for the user to complete the activation step. */ - Optional< bool > preactivation; + Optional preactivation; /** a list of promotions the user has seen. This list may occasionally be modified by the system when promotions are no longer available.
    Length: EDAM_ATTRIBUTE_LEN_MIN - EDAM_ATTRIBUTE_LEN_MAX */ - Optional< QStringList > viewedPromotions; + Optional viewedPromotions; /** if set, this is the email address that the user may send email to in order to add an email note directly into the @@ -1670,7 +1603,7 @@ struct QEVERCLOUD_EXPORT UserAttributes { If this is not set, the user may not add notes via the gateway.
    Length: EDAM_ATTRIBUTE_LEN_MIN - EDAM_ATTRIBUTE_LEN_MAX */ - Optional< QString > incomingEmailAddress; + Optional incomingEmailAddress; /** if set, this will contain a list of email addresses that have recently been used as recipients @@ -1680,97 +1613,97 @@ struct QEVERCLOUD_EXPORT UserAttributes { Length: EDAM_ATTRIBUTE_LEN_MIN - EDAM_ATTRIBUTE_LEN_MAX each
    Max: EDAM_USER_RECENT_MAILED_ADDRESSES_MAX entries */ - Optional< QStringList > recentMailedAddresses; + Optional recentMailedAddresses; /** Free-form text field that may hold general support information, etc.
    Length: EDAM_ATTRIBUTE_LEN_MIN - EDAM_ATTRIBUTE_LEN_MAX */ - Optional< QString > comments; + Optional comments; /** The date/time when the user agreed to the terms of service. This can be used as the effective "start date" for the account. */ - Optional< Timestamp > dateAgreedToTermsOfService; + Optional dateAgreedToTermsOfService; /** The number of referrals that the user is permitted to make. */ - Optional< qint32 > maxReferrals; + Optional maxReferrals; /** The number of referrals sent from this account. */ - Optional< qint32 > referralCount; + Optional referralCount; /** A code indicating where the user was sent from. AKA promotion code */ - Optional< QString > refererCode; + Optional refererCode; /** The most recent date when the user sent outbound emails from the service. Used with sentEmailCount to limit the number of emails that can be sent per day. */ - Optional< Timestamp > sentEmailDate; + Optional sentEmailDate; /** The number of emails that were sent from the user via the service on sentEmailDate. Used to enforce a limit on the number of emails per user per day to prevent spamming. */ - Optional< qint32 > sentEmailCount; + Optional sentEmailCount; /** If set, this is the maximum number of emails that may be sent in a given day from this account. If unset, the server will use the configured default limit. */ - Optional< qint32 > dailyEmailLimit; + Optional dailyEmailLimit; /** If set, this is the date when the user asked to be excluded from offers and promotions sent by Evernote. If not set, then the user currently agrees to receive these messages. */ - Optional< Timestamp > emailOptOutDate; + Optional emailOptOutDate; /** If set, this is the date when the user asked to be included in offers and promotions sent by Evernote's partners. If not sent, then the user currently does not agree to receive these emails. */ - Optional< Timestamp > partnerEmailOptInDate; + Optional partnerEmailOptInDate; /** a 2 character language codes based on: http://ftp.ics.uci.edu/pub/ietf/http/related/iso639.txt used for localization purposes to determine what language to use for the web interface and for other direct communication (e.g. emails). */ - Optional< QString > preferredLanguage; + Optional preferredLanguage; /** Preferred country code based on ISO 3166-1-alpha-2 indicating the users preferred country */ - Optional< QString > preferredCountry; + Optional preferredCountry; /** Boolean flag set to true if the user wants to clip full pages by default when they use the web clipper without a selection. */ - Optional< bool > clipFullPage; + Optional clipFullPage; /** The username of the account of someone who has chosen to enable Twittering into Evernote. This value is subject to change, since users may change their Twitter user name. */ - Optional< QString > twitterUserName; + Optional twitterUserName; /** The unique identifier of the user's Twitter account if that user has chosen to enable Twittering into Evernote. */ - Optional< QString > twitterId; + Optional twitterId; /** A name identifier used to identify a particular set of branding and light customization. */ - Optional< QString > groupName; + Optional groupName; /** a 2 character language codes based on: http://ftp.ics.uci.edu/pub/ietf/http/related/iso639.txt @@ -1778,25 +1711,25 @@ struct QEVERCLOUD_EXPORT UserAttributes { when processing images and PDF files to find text. If not set, then the 'preferredLanguage' will be used. */ - Optional< QString > recognitionLanguage; + Optional recognitionLanguage; /** NOT DOCUMENTED */ - Optional< QString > referralProof; + Optional referralProof; /** NOT DOCUMENTED */ - Optional< bool > educationalDiscount; + Optional educationalDiscount; /** A string recording the business address of a Sponsored Account user who has requested invoicing. */ - Optional< QString > businessAddress; + Optional businessAddress; /** A flag indicating whether to hide the billing information on a sponsored account owner's settings page */ - Optional< bool > hideSponsorBilling; + Optional hideSponsorBilling; /** A flag indicating whether the user chooses to allow Evernote to automatically file and tag emailed notes */ - Optional< bool > useEmailAutoFiling; + Optional useEmailAutoFiling; /** Configuration state for whether or not the user wishes to receive reminder e-mail. This setting applies to both the reminder e-mail sent @@ -1804,31 +1737,33 @@ struct QEVERCLOUD_EXPORT UserAttributes { notes in the user's business notebooks that the user has configured for e-mail notifications. */ - Optional< ReminderEmailConfig::type > reminderEmailConfig; + Optional reminderEmailConfig; /** If set, this contains the time at which the user last confirmed that the configured email address for this account is correct and up-to-date. If this is unset that indicates that the user's email address is unverified. */ - Optional< Timestamp > emailAddressLastConfirmed; + Optional emailAddressLastConfirmed; /** If set, this contains the time at which the user's password last changed. This will be unset for users created before the addition of this field who have not changed their passwords since the addition of this field. */ - Optional< Timestamp > passwordUpdated; + Optional passwordUpdated; /** NOT DOCUMENTED */ - Optional< bool > salesforcePushEnabled; + Optional salesforcePushEnabled; /** If set to True, the server will record LogRequest send from clients of this user as ClientEventLog. */ - Optional< bool > shouldLogClientEvent; + Optional shouldLogClientEvent; /** If set to True, no Machine Learning nor human review will be done to this user's note contents. */ - Optional< bool > optOutMachineLearning; + Optional optOutMachineLearning; + + virtual void print(QTextStream & strm) const override; bool operator==(const UserAttributes & other) const { @@ -1875,6 +1810,42 @@ struct QEVERCLOUD_EXPORT UserAttributes { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional defaultLocationName MEMBER defaultLocationName) + Q_PROPERTY(Optional defaultLatitude MEMBER defaultLatitude) + Q_PROPERTY(Optional defaultLongitude MEMBER defaultLongitude) + Q_PROPERTY(Optional preactivation MEMBER preactivation) + Q_PROPERTY(Optional viewedPromotions MEMBER viewedPromotions) + Q_PROPERTY(Optional incomingEmailAddress MEMBER incomingEmailAddress) + Q_PROPERTY(Optional recentMailedAddresses MEMBER recentMailedAddresses) + Q_PROPERTY(Optional comments MEMBER comments) + Q_PROPERTY(Optional dateAgreedToTermsOfService MEMBER dateAgreedToTermsOfService) + Q_PROPERTY(Optional maxReferrals MEMBER maxReferrals) + Q_PROPERTY(Optional referralCount MEMBER referralCount) + Q_PROPERTY(Optional refererCode MEMBER refererCode) + Q_PROPERTY(Optional sentEmailDate MEMBER sentEmailDate) + Q_PROPERTY(Optional sentEmailCount MEMBER sentEmailCount) + Q_PROPERTY(Optional dailyEmailLimit MEMBER dailyEmailLimit) + Q_PROPERTY(Optional emailOptOutDate MEMBER emailOptOutDate) + Q_PROPERTY(Optional partnerEmailOptInDate MEMBER partnerEmailOptInDate) + Q_PROPERTY(Optional preferredLanguage MEMBER preferredLanguage) + Q_PROPERTY(Optional preferredCountry MEMBER preferredCountry) + Q_PROPERTY(Optional clipFullPage MEMBER clipFullPage) + Q_PROPERTY(Optional twitterUserName MEMBER twitterUserName) + Q_PROPERTY(Optional twitterId MEMBER twitterId) + Q_PROPERTY(Optional groupName MEMBER groupName) + Q_PROPERTY(Optional recognitionLanguage MEMBER recognitionLanguage) + Q_PROPERTY(Optional referralProof MEMBER referralProof) + Q_PROPERTY(Optional educationalDiscount MEMBER educationalDiscount) + Q_PROPERTY(Optional businessAddress MEMBER businessAddress) + Q_PROPERTY(Optional hideSponsorBilling MEMBER hideSponsorBilling) + Q_PROPERTY(Optional useEmailAutoFiling MEMBER useEmailAutoFiling) + Q_PROPERTY(Optional reminderEmailConfig MEMBER reminderEmailConfig) + Q_PROPERTY(Optional emailAddressLastConfirmed MEMBER emailAddressLastConfirmed) + Q_PROPERTY(Optional passwordUpdated MEMBER passwordUpdated) + Q_PROPERTY(Optional salesforcePushEnabled MEMBER salesforcePushEnabled) + Q_PROPERTY(Optional shouldLogClientEvent MEMBER shouldLogClientEvent) + Q_PROPERTY(Optional optOutMachineLearning MEMBER optOutMachineLearning) }; /** @@ -1882,36 +1853,47 @@ struct QEVERCLOUD_EXPORT UserAttributes { * in a business. * * */ -struct QEVERCLOUD_EXPORT BusinessUserAttributes { +struct QEVERCLOUD_EXPORT BusinessUserAttributes: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** Free form text of this user's title in the business */ - Optional< QString > title; + Optional title; /** City, State (for US) or City / Province for other countries */ - Optional< QString > location; + Optional location; /** Free form text of the department this user belongs to. */ - Optional< QString > department; + Optional department; /** User's mobile phone number. Stored as plain text without any formatting. */ - Optional< QString > mobilePhone; + Optional mobilePhone; /** URL to user's public LinkedIn profile page. This should only contain the portion relative to the base LinkedIn URL. For example: "/pub/john-smith/". */ - Optional< QString > linkedInProfileUrl; + Optional linkedInProfileUrl; /** User's work phone number. Stored as plain text without any formatting. */ - Optional< QString > workPhone; + Optional workPhone; /** The date on which the user started working at their company. */ - Optional< Timestamp > companyStartDate; + Optional companyStartDate; + + virtual void print(QTextStream & strm) const override; bool operator==(const BusinessUserAttributes & other) const { @@ -1930,121 +1912,140 @@ struct QEVERCLOUD_EXPORT BusinessUserAttributes { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional title MEMBER title) + Q_PROPERTY(Optional location MEMBER location) + Q_PROPERTY(Optional department MEMBER department) + Q_PROPERTY(Optional mobilePhone MEMBER mobilePhone) + Q_PROPERTY(Optional linkedInProfileUrl MEMBER linkedInProfileUrl) + Q_PROPERTY(Optional workPhone MEMBER workPhone) + Q_PROPERTY(Optional companyStartDate MEMBER companyStartDate) }; /** * This represents the bookkeeping information for the user's subscription. * **/ -struct QEVERCLOUD_EXPORT Accounting { +struct QEVERCLOUD_EXPORT Accounting: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The date and time when the current upload limit expires. At this time, the monthly upload count reverts to 0 and a new limit is imposed. This date and time is exclusive, so this is effectively the start of the new month. */ - Optional< Timestamp > uploadLimitEnd; + Optional uploadLimitEnd; /** When uploadLimitEnd is reached, the service will change uploadLimit to uploadLimitNextMonth. If a premium account is canceled, this mechanism will reset the quota appropriately. */ - Optional< qint64 > uploadLimitNextMonth; + Optional uploadLimitNextMonth; /** Indicates the phases of a premium account during the billing process. */ - Optional< PremiumOrderStatus::type > premiumServiceStatus; + Optional premiumServiceStatus; /** The order number used by the commerce system to process recurring payments */ - Optional< QString > premiumOrderNumber; + Optional premiumOrderNumber; /** The commerce system used (paypal, Google checkout, etc) */ - Optional< QString > premiumCommerceService; + Optional premiumCommerceService; /** The start date when this premium promotion began (this number will get overwritten if a premium service is canceled and then re-activated). */ - Optional< Timestamp > premiumServiceStart; + Optional premiumServiceStart; /** The code associated with the purchase eg. monthly or annual purchase. Clients should interpret this value and localize it. */ - Optional< QString > premiumServiceSKU; + Optional premiumServiceSKU; /** Date the last time the user was charged. Null if never charged. */ - Optional< Timestamp > lastSuccessfulCharge; + Optional lastSuccessfulCharge; /** Date the last time a charge was attempted and failed. */ - Optional< Timestamp > lastFailedCharge; + Optional lastFailedCharge; /** Reason provided for the charge failure */ - Optional< QString > lastFailedChargeReason; + Optional lastFailedChargeReason; /** The end of the billing cycle. This could be in the past if there are failed charges. */ - Optional< Timestamp > nextPaymentDue; + Optional nextPaymentDue; /** An internal variable to manage locking operations on the commerce variables. */ - Optional< Timestamp > premiumLockUntil; + Optional premiumLockUntil; /** The date any modification where made to this record. */ - Optional< Timestamp > updated; + Optional updated; /** The number number identifying the recurring subscription used to make the recurring charges. */ - Optional< QString > premiumSubscriptionNumber; + Optional premiumSubscriptionNumber; /** Date charge last attempted */ - Optional< Timestamp > lastRequestedCharge; + Optional lastRequestedCharge; /** ISO 4217 currency code */ - Optional< QString > currency; + Optional currency; /** charge in the smallest unit of the currency (e.g. cents for USD) */ - Optional< qint32 > unitPrice; + Optional unitPrice; /** DEPRECATED:See BusinessUserInfo. */ - Optional< qint32 > businessId; + Optional businessId; /** DEPRECATED:See BusinessUserInfo. */ - Optional< QString > businessName; + Optional businessName; /** DEPRECATED:See BusinessUserInfo. */ - Optional< BusinessUserRole::type > businessRole; + Optional businessRole; /** discount per seat in negative amount and smallest unit of the currency (e.g. cents for USD) */ - Optional< qint32 > unitDiscount; + Optional unitDiscount; /** The next time the user will be charged, may or may not be the same as nextPaymentDue */ - Optional< Timestamp > nextChargeDate; + Optional nextChargeDate; /** NOT DOCUMENTED */ - Optional< qint32 > availablePoints; + Optional availablePoints; + + virtual void print(QTextStream & strm) const override; bool operator==(const Accounting & other) const { @@ -2079,6 +2080,30 @@ struct QEVERCLOUD_EXPORT Accounting { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional uploadLimitEnd MEMBER uploadLimitEnd) + Q_PROPERTY(Optional uploadLimitNextMonth MEMBER uploadLimitNextMonth) + Q_PROPERTY(Optional premiumServiceStatus MEMBER premiumServiceStatus) + Q_PROPERTY(Optional premiumOrderNumber MEMBER premiumOrderNumber) + Q_PROPERTY(Optional premiumCommerceService MEMBER premiumCommerceService) + Q_PROPERTY(Optional premiumServiceStart MEMBER premiumServiceStart) + Q_PROPERTY(Optional premiumServiceSKU MEMBER premiumServiceSKU) + Q_PROPERTY(Optional lastSuccessfulCharge MEMBER lastSuccessfulCharge) + Q_PROPERTY(Optional lastFailedCharge MEMBER lastFailedCharge) + Q_PROPERTY(Optional lastFailedChargeReason MEMBER lastFailedChargeReason) + Q_PROPERTY(Optional nextPaymentDue MEMBER nextPaymentDue) + Q_PROPERTY(Optional premiumLockUntil MEMBER premiumLockUntil) + Q_PROPERTY(Optional updated MEMBER updated) + Q_PROPERTY(Optional premiumSubscriptionNumber MEMBER premiumSubscriptionNumber) + Q_PROPERTY(Optional lastRequestedCharge MEMBER lastRequestedCharge) + Q_PROPERTY(Optional currency MEMBER currency) + Q_PROPERTY(Optional unitPrice MEMBER unitPrice) + Q_PROPERTY(Optional businessId MEMBER businessId) + Q_PROPERTY(Optional businessName MEMBER businessName) + Q_PROPERTY(Optional businessRole MEMBER businessRole) + Q_PROPERTY(Optional unitDiscount MEMBER unitDiscount) + Q_PROPERTY(Optional nextChargeDate MEMBER nextChargeDate) + Q_PROPERTY(Optional availablePoints MEMBER availablePoints) }; /** @@ -2086,21 +2111,30 @@ struct QEVERCLOUD_EXPORT Accounting { * membership, for members who are part of a business. * * */ -struct QEVERCLOUD_EXPORT BusinessUserInfo { +struct QEVERCLOUD_EXPORT BusinessUserInfo: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The ID of the Evernote Business account that the user is a member of.
    businessName The human-readable name of the Evernote Business account that the user is a member of. */ - Optional< qint32 > businessId; + Optional businessId; /** NOT DOCUMENTED */ - Optional< QString > businessName; + Optional businessName; /** The role of the user within the Evernote Business account that they are a member of. */ - Optional< BusinessUserRole::type > role; + Optional role; /** An e-mail address that will be used by the service in the context of your Evernote Business activities. For example, this e-mail address will be used @@ -2108,11 +2142,13 @@ struct QEVERCLOUD_EXPORT BusinessUserInfo { your business, etc. The business e-mail cannot be used for identification purposes such as for logging into the service. */ - Optional< QString > email; + Optional email; /** Last time the business user or business user attributes were updated. */ - Optional< Timestamp > updated; + Optional updated; + + virtual void print(QTextStream & strm) const override; bool operator==(const BusinessUserInfo & other) const { @@ -2129,33 +2165,48 @@ struct QEVERCLOUD_EXPORT BusinessUserInfo { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional businessId MEMBER businessId) + Q_PROPERTY(Optional businessName MEMBER businessName) + Q_PROPERTY(Optional role MEMBER role) + Q_PROPERTY(Optional email MEMBER email) + Q_PROPERTY(Optional updated MEMBER updated) }; /** * This structure is used to provide account limits that are in effect for this user. **/ -struct QEVERCLOUD_EXPORT AccountLimits { +struct QEVERCLOUD_EXPORT AccountLimits: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The number of emails of any type that can be sent by a user from the service per day. If an email is sent to two different recipients, this counts as two emails. */ - Optional< qint32 > userMailLimitDaily; + Optional userMailLimitDaily; /** Maximum total size of a Note that can be added. The size of a note is calculated as: ENML content length (in Unicode characters) plus the sum of all resource sizes (in bytes). */ - Optional< qint64 > noteSizeMax; + Optional noteSizeMax; /** Maximum size of a resource, in bytes */ - Optional< qint64 > resourceSizeMax; + Optional resourceSizeMax; /** Maximum number of linked notebooks per account. */ - Optional< qint32 > userLinkedNotebookMax; + Optional userLinkedNotebookMax; /** The number of bytes that can be uploaded to the account in the current month. For new notes that are created, this is the length @@ -2164,31 +2215,33 @@ struct QEVERCLOUD_EXPORT AccountLimits { length and the new length (if this is greater than 0) plus the size of each new resource. */ - Optional< qint64 > uploadLimit; + Optional uploadLimit; /** Maximum number of Notes per user */ - Optional< qint32 > userNoteCountMax; + Optional userNoteCountMax; /** Maximum number of Notebooks per user */ - Optional< qint32 > userNotebookCountMax; + Optional userNotebookCountMax; /** Maximum number of Tags per account */ - Optional< qint32 > userTagCountMax; + Optional userTagCountMax; /** Maximum number of Tags per Note */ - Optional< qint32 > noteTagCountMax; + Optional noteTagCountMax; /** Maximum number of SavedSearches per account */ - Optional< qint32 > userSavedSearchesMax; + Optional userSavedSearchesMax; /** The maximum number of Resources per Note */ - Optional< qint32 > noteResourceCountMax; + Optional noteResourceCountMax; + + virtual void print(QTextStream & strm) const override; bool operator==(const AccountLimits & other) const { @@ -2211,17 +2264,38 @@ struct QEVERCLOUD_EXPORT AccountLimits { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional userMailLimitDaily MEMBER userMailLimitDaily) + Q_PROPERTY(Optional noteSizeMax MEMBER noteSizeMax) + Q_PROPERTY(Optional resourceSizeMax MEMBER resourceSizeMax) + Q_PROPERTY(Optional userLinkedNotebookMax MEMBER userLinkedNotebookMax) + Q_PROPERTY(Optional uploadLimit MEMBER uploadLimit) + Q_PROPERTY(Optional userNoteCountMax MEMBER userNoteCountMax) + Q_PROPERTY(Optional userNotebookCountMax MEMBER userNotebookCountMax) + Q_PROPERTY(Optional userTagCountMax MEMBER userTagCountMax) + Q_PROPERTY(Optional noteTagCountMax MEMBER noteTagCountMax) + Q_PROPERTY(Optional userSavedSearchesMax MEMBER userSavedSearchesMax) + Q_PROPERTY(Optional noteResourceCountMax MEMBER noteResourceCountMax) }; /** * This represents the information about a single user account. **/ -struct QEVERCLOUD_EXPORT User { +struct QEVERCLOUD_EXPORT User: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The unique numeric identifier for the account, which will not change for the lifetime of the account. */ - Optional< UserID > id; + Optional id; /** The name that uniquely identifies a single user account. This name may be presented by the user, along with their password, to log into @@ -2232,7 +2306,7 @@ struct QEVERCLOUD_EXPORT User {
    Regex: EDAM_USER_USERNAME_REGEX */ - Optional< QString > username; + Optional username; /** The email address registered for the user. Must comply with RFC 2821 and RFC 2822.
    @@ -2242,7 +2316,7 @@ struct QEVERCLOUD_EXPORT User {
    Regex: EDAM_EMAIL_REGEX */ - Optional< QString > email; + Optional email; /** The printable name of the user, which may be a combination of given and family names. This is used instead of separate "first" @@ -2254,7 +2328,7 @@ struct QEVERCLOUD_EXPORT User {
    Regex: EDAM_USER_NAME_REGEX */ - Optional< QString > name; + Optional name; /** The zone ID for the user's default location. If present, this may be used to localize the display of any timestamp for which no @@ -2266,71 +2340,73 @@ struct QEVERCLOUD_EXPORT User {
    Regex: EDAM_TIMEZONE_REGEX */ - Optional< QString > timezone; + Optional timezone; /** NOT DOCUMENTED */ - Optional< PrivilegeLevel::type > privilege; + Optional privilege; /** The level of service the user currently receives. This will always be populated for users retrieved from the Evernote service. */ - Optional< ServiceLevel::type > serviceLevel; + Optional serviceLevel; /** The date and time when this user account was created in the service. */ - Optional< Timestamp > created; + Optional created; /** The date and time when this user account was last modified in the service. */ - Optional< Timestamp > updated; + Optional updated; /** If the account has been deleted from the system (e.g. as the result of a legal request by the user), the date and time of the deletion will be represented here. If not, this value will not be set. */ - Optional< Timestamp > deleted; + Optional deleted; /** If the user account is available for login and synchronization, this flag will be set to true. */ - Optional< bool > active; + Optional active; /** DEPRECATED - Client applications should have no need to use this field. */ - Optional< QString > shardId; + Optional shardId; /** If present, this will contain a list of the attributes for this user account. */ - Optional< UserAttributes > attributes; + Optional attributes; /** Bookkeeping information for the user's subscription. */ - Optional< Accounting > accounting; + Optional accounting; /** If present, this will contain a set of business information relating to the user's business membership. If not present, the user is not currently part of a business. */ - Optional< BusinessUserInfo > businessUserInfo; + Optional businessUserInfo; /** The URL of the photo that represents this User. This field is filled in by the service and is read-only to clients. If photoLastUpdated is not set, this url will point to a placeholder user photo generated by the service. */ - Optional< QString > photoUrl; + Optional photoUrl; /** The time at which the photo at 'photoUrl' was last updated by this User. This field will be null if the User never set a profile photo. This field is filled in by the service and is read-only to clients. */ - Optional< Timestamp > photoLastUpdated; + Optional photoLastUpdated; /** Account limits applicable for this user. */ - Optional< AccountLimits > accountLimits; + Optional accountLimits; + + virtual void print(QTextStream & strm) const override; bool operator==(const User & other) const { @@ -2360,6 +2436,25 @@ struct QEVERCLOUD_EXPORT User { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional id MEMBER id) + Q_PROPERTY(Optional username MEMBER username) + Q_PROPERTY(Optional email MEMBER email) + Q_PROPERTY(Optional name MEMBER name) + Q_PROPERTY(Optional timezone MEMBER timezone) + Q_PROPERTY(Optional privilege MEMBER privilege) + Q_PROPERTY(Optional serviceLevel MEMBER serviceLevel) + Q_PROPERTY(Optional created MEMBER created) + Q_PROPERTY(Optional updated MEMBER updated) + Q_PROPERTY(Optional deleted MEMBER deleted) + Q_PROPERTY(Optional active MEMBER active) + Q_PROPERTY(Optional shardId MEMBER shardId) + Q_PROPERTY(Optional attributes MEMBER attributes) + Q_PROPERTY(Optional accounting MEMBER accounting) + Q_PROPERTY(Optional businessUserInfo MEMBER businessUserInfo) + Q_PROPERTY(Optional photoUrl MEMBER photoUrl) + Q_PROPERTY(Optional photoLastUpdated MEMBER photoLastUpdated) + Q_PROPERTY(Optional accountLimits MEMBER accountLimits) }; /** @@ -2367,31 +2462,40 @@ struct QEVERCLOUD_EXPORT User { * an Evernote user. * * */ -struct QEVERCLOUD_EXPORT Contact { +struct QEVERCLOUD_EXPORT Contact: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The displayable name of this contact. This field is filled in by the service and is read-only to clients. */ - Optional< QString > name; + Optional name; /** A unique identifier for this ContactType. */ - Optional< QString > id; + Optional id; /** What service does this contact come from? */ - Optional< ContactType::type > type; + Optional type; /** A URL of a profile photo representing this Contact. This field is filled in by the service and is read-only to clients. */ - Optional< QString > photoUrl; + Optional photoUrl; /** timestamp when the profile photo at 'photoUrl' was last updated. This field will be null if the user has never set a profile photo. This field is filled in by the service and is read-only to clients. */ - Optional< Timestamp > photoLastUpdated; + Optional photoLastUpdated; /** This field will only be filled by the service when it is giving a Contact record to a client, and that client does not normally have enough permission to send a @@ -2399,14 +2503,16 @@ struct QEVERCLOUD_EXPORT Contact { whole Contact record could be used to send a new Message to the Contact, and the service will inspect this permit to confirm that operation was allowed. */ - Optional< QByteArray > messagingPermit; + Optional messagingPermit; /** If this field is set, then this (whole) Contact record may be used in calls to sendMessage until this time. After that time, those calls may be rejected by the service if the caller does not have direct permission to initiate a message with the represented Evernote user. */ - Optional< Timestamp > messagingPermitExpires; + Optional messagingPermitExpires; + + virtual void print(QTextStream & strm) const override; bool operator==(const Contact & other) const { @@ -2425,6 +2531,14 @@ struct QEVERCLOUD_EXPORT Contact { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional name MEMBER name) + Q_PROPERTY(Optional id MEMBER id) + Q_PROPERTY(Optional type MEMBER type) + Q_PROPERTY(Optional photoUrl MEMBER photoUrl) + Q_PROPERTY(Optional photoLastUpdated MEMBER photoLastUpdated) + Q_PROPERTY(Optional messagingPermit MEMBER messagingPermit) + Q_PROPERTY(Optional messagingPermitExpires MEMBER messagingPermitExpires) }; /** @@ -2432,19 +2546,28 @@ struct QEVERCLOUD_EXPORT Contact { * belongs to an Evernote User. * * */ -struct QEVERCLOUD_EXPORT Identity { +struct QEVERCLOUD_EXPORT Identity: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The unique identifier for this mapping. */ - IdentityID id; + IdentityID id = 0; /** NOT DOCUMENTED */ - Optional< Contact > contact; + Optional contact; /** The Evernote User id that is connected to the Contact. May be unset if this identity has not yet been claimed, or the caller is not connected to this identity. */ - Optional< UserID > userId; + Optional userId; /** Indicates that the contact for this identity is no longer active and should not be used when creating new threads using Destination.recipients, @@ -2452,16 +2575,16 @@ struct QEVERCLOUD_EXPORT Identity { that is active. If you are connected to the user (see userConnected), you can still create threads using their Evernote-type contact. */ - Optional< bool > deactivated; + Optional deactivated; /** Does this Identity belong to someone who is in the same business as the caller? */ - Optional< bool > sameBusiness; + Optional sameBusiness; /** Has the caller blocked the Evernote user this Identity represents? */ - Optional< bool > blocked; + Optional blocked; /** Indicates that the caller is "connected" to the user of this identity via this identity. When you have a connection via an @@ -2478,12 +2601,14 @@ struct QEVERCLOUD_EXPORT Identity { sending messages to yourself, but you will obviously see your own profile information. */ - Optional< bool > userConnected; + Optional userConnected; /** A server-assigned sequence number for the events in the messages subsystem. */ - Optional< MessageEventID > eventId; + Optional eventId; + + virtual void print(QTextStream & strm) const override; bool operator==(const Identity & other) const { @@ -2503,13 +2628,31 @@ struct QEVERCLOUD_EXPORT Identity { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(IdentityID id MEMBER id) + Q_PROPERTY(Optional contact MEMBER contact) + Q_PROPERTY(Optional userId MEMBER userId) + Q_PROPERTY(Optional deactivated MEMBER deactivated) + Q_PROPERTY(Optional sameBusiness MEMBER sameBusiness) + Q_PROPERTY(Optional blocked MEMBER blocked) + Q_PROPERTY(Optional userConnected MEMBER userConnected) + Q_PROPERTY(Optional eventId MEMBER eventId) }; /** * A tag within a user's account is a unique name which may be organized * a simple hierarchy. **/ -struct QEVERCLOUD_EXPORT Tag { +struct QEVERCLOUD_EXPORT Tag: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The unique identifier of this tag. Will be set by the service, so may be omitted by the client when creating the Tag. @@ -2518,7 +2661,7 @@ struct QEVERCLOUD_EXPORT Tag {
    Regex: EDAM_GUID_REGEX */ - Optional< Guid > guid; + Optional guid; /** A sequence of characters representing the tag's identifier. Case is preserved, but is ignored for comparisons. @@ -2531,7 +2674,7 @@ struct QEVERCLOUD_EXPORT Tag {
    Regex: EDAM_TAG_NAME_REGEX */ - Optional< QString > name; + Optional name; /** If this is set, then this is the GUID of the tag that holds this tag within the tag organizational hierarchy. If this is @@ -2543,14 +2686,16 @@ struct QEVERCLOUD_EXPORT Tag {
    Regex: EDAM_GUID_REGEX */ - Optional< Guid > parentGuid; + Optional parentGuid; /** A number identifying the last transaction to modify the state of this object. The USN values are sequential within an account, and can be used to compare the order of modifications within the service. */ - Optional< qint32 > updateSequenceNum; + Optional updateSequenceNum; + + virtual void print(QTextStream & strm) const override; bool operator==(const Tag & other) const { @@ -2566,6 +2711,11 @@ struct QEVERCLOUD_EXPORT Tag { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional guid MEMBER guid) + Q_PROPERTY(Optional name MEMBER name) + Q_PROPERTY(Optional parentGuid MEMBER parentGuid) + Q_PROPERTY(Optional updateSequenceNum MEMBER updateSequenceNum) }; /** @@ -2587,16 +2737,27 @@ struct QEVERCLOUD_EXPORT Tag { * map. * * */ -struct QEVERCLOUD_EXPORT LazyMap { +struct QEVERCLOUD_EXPORT LazyMap: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The set of keys for the map. This field is ignored by the server when set. */ - Optional< QSet< QString > > keysOnly; + Optional> keysOnly; /** The complete map, including all keys and values. */ - Optional< QMap< QString, QString > > fullMap; + Optional> fullMap; + + virtual void print(QTextStream & strm) const override; bool operator==(const LazyMap & other) const { @@ -2610,71 +2771,85 @@ struct QEVERCLOUD_EXPORT LazyMap { return !(*this == other); } + using FullMap = QMap; + + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional> keysOnly MEMBER keysOnly) + Q_PROPERTY(Optional fullMap MEMBER fullMap) }; /** * Structure holding the optional attributes of a Resource * */ -struct QEVERCLOUD_EXPORT ResourceAttributes { +struct QEVERCLOUD_EXPORT ResourceAttributes: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** the original location where the resource was hosted
    Length: EDAM_ATTRIBUTE_LEN_MIN - EDAM_ATTRIBUTE_LEN_MAX */ - Optional< QString > sourceURL; + Optional sourceURL; /** the date and time that is associated with this resource (e.g. the time embedded in an image from a digital camera with a clock) */ - Optional< Timestamp > timestamp; + Optional timestamp; /** the latitude where the resource was captured */ - Optional< double > latitude; + Optional latitude; /** the longitude where the resource was captured */ - Optional< double > longitude; + Optional longitude; /** the altitude where the resource was captured */ - Optional< double > altitude; + Optional altitude; /** information about an image's camera, e.g. as embedded in the image's EXIF data
    Length: EDAM_ATTRIBUTE_LEN_MIN - EDAM_ATTRIBUTE_LEN_MAX */ - Optional< QString > cameraMake; + Optional cameraMake; /** information about an image's camera, e.g. as embedded in the image's EXIF data
    Length: EDAM_ATTRIBUTE_LEN_MIN - EDAM_ATTRIBUTE_LEN_MAX */ - Optional< QString > cameraModel; + Optional cameraModel; /** if true, then the original client that submitted the resource plans to submit the recognition index for this resource at a later time. */ - Optional< bool > clientWillIndex; + Optional clientWillIndex; /** DEPRECATED - this field is no longer set by the service, so should be ignored. */ - Optional< QString > recoType; + Optional recoType; /** if the resource came from a source that provided an explicit file name, the original name will be stored here. Many resources come from unnamed sources, so this will not always be set. */ - Optional< QString > fileName; + Optional fileName; /** this will be true if the resource should be displayed as an attachment, or false if the resource should be displayed inline (if possible). */ - Optional< bool > attachment; + Optional attachment; /** Provides a location for applications to store a relatively small (4kb) blob of data associated with a Resource that is not visible to the user @@ -2691,7 +2866,9 @@ struct QEVERCLOUD_EXPORT ResourceAttributes {
    Syntax regex for name (key): EDAM_APPLICATIONDATA_NAME_REGEX */ - Optional< LazyMap > applicationData; + Optional applicationData; + + virtual void print(QTextStream & strm) const override; bool operator==(const ResourceAttributes & other) const { @@ -2715,13 +2892,35 @@ struct QEVERCLOUD_EXPORT ResourceAttributes { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional sourceURL MEMBER sourceURL) + Q_PROPERTY(Optional timestamp MEMBER timestamp) + Q_PROPERTY(Optional latitude MEMBER latitude) + Q_PROPERTY(Optional longitude MEMBER longitude) + Q_PROPERTY(Optional altitude MEMBER altitude) + Q_PROPERTY(Optional cameraMake MEMBER cameraMake) + Q_PROPERTY(Optional cameraModel MEMBER cameraModel) + Q_PROPERTY(Optional clientWillIndex MEMBER clientWillIndex) + Q_PROPERTY(Optional recoType MEMBER recoType) + Q_PROPERTY(Optional fileName MEMBER fileName) + Q_PROPERTY(Optional attachment MEMBER attachment) + Q_PROPERTY(Optional applicationData MEMBER applicationData) }; /** * Every media file that is embedded or attached to a note is represented * through a Resource entry. * */ -struct QEVERCLOUD_EXPORT Resource { +struct QEVERCLOUD_EXPORT Resource: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The unique identifier of this resource. Will be set whenever a resource is retrieved from the service, but may be null when a client @@ -2731,7 +2930,7 @@ struct QEVERCLOUD_EXPORT Resource {
    Regex: EDAM_GUID_REGEX */ - Optional< Guid > guid; + Optional guid; /** The unique identifier of the Note that holds this Resource. Will be set whenever the resource is retrieved from the service, @@ -2741,13 +2940,13 @@ struct QEVERCLOUD_EXPORT Resource {
    Regex: EDAM_GUID_REGEX */ - Optional< Guid > noteGuid; + Optional noteGuid; /** The contents of the resource. Maximum length: The data.body is limited to EDAM_RESOURCE_SIZE_MAX_FREE for free accounts and EDAM_RESOURCE_SIZE_MAX_PREMIUM for premium accounts. */ - Optional< Data > data; + Optional data; /** The MIME type for the embedded resource. E.g. "image/gif"
    @@ -2755,41 +2954,41 @@ struct QEVERCLOUD_EXPORT Resource {
    Regex: EDAM_MIME_REGEX */ - Optional< QString > mime; + Optional mime; /** If set, this contains the display width of this resource, in pixels. */ - Optional< qint16 > width; + Optional width; /** If set, this contains the display height of this resource, in pixels. */ - Optional< qint16 > height; + Optional height; /** DEPRECATED: ignored. */ - Optional< qint16 > duration; + Optional duration; /** If the resource is active or not. */ - Optional< bool > active; + Optional active; /** If set, this will hold the encoded data that provides information on search and recognition within this resource. */ - Optional< Data > recognition; + Optional recognition; /** A list of the attributes for this resource. */ - Optional< ResourceAttributes > attributes; + Optional attributes; /** A number identifying the last transaction to modify the state of this object. The USN values are sequential within an account, and can be used to compare the order of modifications within the service. */ - Optional< qint32 > updateSequenceNum; + Optional updateSequenceNum; /** Some Resources may be assigned an alternate data format by the service which may be more appropriate for indexing or rendering than the original @@ -2797,7 +2996,9 @@ struct QEVERCLOUD_EXPORT Resource { be available via this Data element. If a Resource has no alternate form, this field will be unset. */ - Optional< Data > alternateData; + Optional alternateData; + + virtual void print(QTextStream & strm) const override; bool operator==(const Resource & other) const { @@ -2821,48 +3022,70 @@ struct QEVERCLOUD_EXPORT Resource { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional guid MEMBER guid) + Q_PROPERTY(Optional noteGuid MEMBER noteGuid) + Q_PROPERTY(Optional data MEMBER data) + Q_PROPERTY(Optional mime MEMBER mime) + Q_PROPERTY(Optional width MEMBER width) + Q_PROPERTY(Optional height MEMBER height) + Q_PROPERTY(Optional duration MEMBER duration) + Q_PROPERTY(Optional active MEMBER active) + Q_PROPERTY(Optional recognition MEMBER recognition) + Q_PROPERTY(Optional attributes MEMBER attributes) + Q_PROPERTY(Optional updateSequenceNum MEMBER updateSequenceNum) + Q_PROPERTY(Optional alternateData MEMBER alternateData) }; /** * The list of optional attributes that can be stored on a note. * */ -struct QEVERCLOUD_EXPORT NoteAttributes { +struct QEVERCLOUD_EXPORT NoteAttributes: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** time that the note refers to */ - Optional< Timestamp > subjectDate; + Optional subjectDate; /** the latitude where the note was taken */ - Optional< double > latitude; + Optional latitude; /** the longitude where the note was taken */ - Optional< double > longitude; + Optional longitude; /** the altitude where the note was taken */ - Optional< double > altitude; + Optional altitude; /** the author of the content of the note
    Length: EDAM_ATTRIBUTE_LEN_MIN - EDAM_ATTRIBUTE_LEN_MAX */ - Optional< QString > author; + Optional author; /** the method that the note was added to the account, if the note wasn't directly authored in an Evernote desktop client.
    Length: EDAM_ATTRIBUTE_LEN_MIN - EDAM_ATTRIBUTE_LEN_MAX */ - Optional< QString > source; + Optional source; /** the original location where the resource was hosted. For web clips, this will be the URL of the page that was clipped.
    Length: EDAM_ATTRIBUTE_LEN_MIN - EDAM_ATTRIBUTE_LEN_MAX */ - Optional< QString > sourceURL; + Optional sourceURL; /** an identifying string for the application that created this note. This string does not have a guaranteed syntax or @@ -2870,7 +3093,7 @@ struct QEVERCLOUD_EXPORT NoteAttributes {
    Length: EDAM_ATTRIBUTE_LEN_MIN - EDAM_ATTRIBUTE_LEN_MAX */ - Optional< QString > sourceApplication; + Optional sourceApplication; /** The date and time when this note was directly shared via its own URL. This is only set on notes that were individually shared - it is independent @@ -2878,7 +3101,7 @@ struct QEVERCLOUD_EXPORT NoteAttributes { is treated as "read-only" for clients; the server will ignore changes to this field from an external client. */ - Optional< Timestamp > shareDate; + Optional shareDate; /** The set of notes with this parameter set are considered "reminders" and are to be treated specially by clients to give them @@ -2905,14 +3128,14 @@ struct QEVERCLOUD_EXPORT NoteAttributes { reminderOrder is not set, the server will fill in the current server time for the reminderOrder field. */ - Optional< qint64 > reminderOrder; + Optional reminderOrder; /** The date and time when a user dismissed/"marked done" the reminder on the note. Users typically do not manually set this value directly as it is set to the time when the user dismissed/"marked done" the reminder. */ - Optional< Timestamp > reminderDoneTime; + Optional reminderDoneTime; /** The date and time a user has selected to be reminded of the note. A note with this value set is known as a "reminder" and the user can @@ -2923,7 +3146,7 @@ struct QEVERCLOUD_EXPORT NoteAttributes { cleared. This should happen regardless of any existing reminder time that may have previously existed on the note. */ - Optional< Timestamp > reminderTime; + Optional reminderTime; /** Allows the user to assign a human-readable location name associated with a note. Users may assign values like 'Home' and 'Work'. Place @@ -2935,7 +3158,7 @@ struct QEVERCLOUD_EXPORT NoteAttributes { more useful than a simple automated lookup based on the note's latitude and longitude. */ - Optional< QString > placeName; + Optional placeName; /** The class (or type) of note. This field is used to indicate to clients that special structured information is represented within @@ -2958,7 +3181,7 @@ struct QEVERCLOUD_EXPORT NoteAttributes {
    Regex: EDAM_NOTE_CONTENT_CLASS_REGEX */ - Optional< QString > contentClass; + Optional contentClass; /** Provides a location for applications to store a relatively small (4kb) blob of data that is not meant to be visible to the user and @@ -2975,7 +3198,7 @@ struct QEVERCLOUD_EXPORT NoteAttributes {
    Syntax regex for name (key): EDAM_APPLICATIONDATA_NAME_REGEX */ - Optional< LazyMap > applicationData; + Optional applicationData; /** An indication of who made the last change to the note. If you are accessing the note via a shared notebook to which you have modification @@ -2987,21 +3210,21 @@ struct QEVERCLOUD_EXPORT NoteAttributes { it will be left unset. This field is read-only by clients. The server will ignore all values set by clients into this field. */ - Optional< QString > lastEditedBy; + Optional lastEditedBy; /** A map of classifications applied to the note by clients or by the Evernote service. The key is the string name of the classification type, and the value is a constant that begins with CLASSIFICATION_. */ - Optional< QMap< QString, QString > > classifications; + Optional> classifications; /** The numeric user ID of the user who originally created the note. */ - Optional< UserID > creatorId; + Optional creatorId; /** The numeric user ID of the user described in lastEditedBy. */ - Optional< UserID > lastEditorId; + Optional lastEditorId; /** When this flag is set on a business note, any user in that business may view the note if they request it by GUID. This field is read-only by @@ -3010,7 +3233,7 @@ struct QEVERCLOUD_EXPORT NoteAttributes { To share a note with the business, use NoteStore.shareNoteWithBusiness and to stop sharing a note with the business, use NoteStore.stopSharingNoteWithBusiness. */ - Optional< bool > sharedWithBusiness; + Optional sharedWithBusiness; /** If set, this specifies the GUID of a note that caused a sync conflict resulting in the creation of a duplicate note. The duplicated note contains @@ -3019,7 +3242,7 @@ struct QEVERCLOUD_EXPORT NoteAttributes { conflict. This allows clients to provide a customized user experience for note conflicts. */ - Optional< Guid > conflictSourceNoteGuid; + Optional conflictSourceNoteGuid; /** If set, this specifies that the note's title was automatically generated and indicates the likelihood that the generated title is useful for display to @@ -3032,7 +3255,9 @@ struct QEVERCLOUD_EXPORT NoteAttributes { When a user edits a note's title, clients MUST unset this value. */ - Optional< qint32 > noteTitleQuality; + Optional noteTitleQuality; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteAttributes & other) const { @@ -3066,6 +3291,31 @@ struct QEVERCLOUD_EXPORT NoteAttributes { return !(*this == other); } + using Classifications = QMap; + + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional subjectDate MEMBER subjectDate) + Q_PROPERTY(Optional latitude MEMBER latitude) + Q_PROPERTY(Optional longitude MEMBER longitude) + Q_PROPERTY(Optional altitude MEMBER altitude) + Q_PROPERTY(Optional author MEMBER author) + Q_PROPERTY(Optional source MEMBER source) + Q_PROPERTY(Optional sourceURL MEMBER sourceURL) + Q_PROPERTY(Optional sourceApplication MEMBER sourceApplication) + Q_PROPERTY(Optional shareDate MEMBER shareDate) + Q_PROPERTY(Optional reminderOrder MEMBER reminderOrder) + Q_PROPERTY(Optional reminderDoneTime MEMBER reminderDoneTime) + Q_PROPERTY(Optional reminderTime MEMBER reminderTime) + Q_PROPERTY(Optional placeName MEMBER placeName) + Q_PROPERTY(Optional contentClass MEMBER contentClass) + Q_PROPERTY(Optional applicationData MEMBER applicationData) + Q_PROPERTY(Optional lastEditedBy MEMBER lastEditedBy) + Q_PROPERTY(Optional classifications MEMBER classifications) + Q_PROPERTY(Optional creatorId MEMBER creatorId) + Q_PROPERTY(Optional lastEditorId MEMBER lastEditorId) + Q_PROPERTY(Optional sharedWithBusiness MEMBER sharedWithBusiness) + Q_PROPERTY(Optional conflictSourceNoteGuid MEMBER conflictSourceNoteGuid) + Q_PROPERTY(Optional noteTitleQuality MEMBER noteTitleQuality) }; /** @@ -3074,34 +3324,45 @@ struct QEVERCLOUD_EXPORT NoteAttributes { * take on the note. * * */ -struct QEVERCLOUD_EXPORT SharedNote { +struct QEVERCLOUD_EXPORT SharedNote: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The user ID of the user who shared the note with the recipient. */ - Optional< UserID > sharerUserID; + Optional sharerUserID; /** The identity of the recipient of the share. For a given note, there may be only one SharedNote per recipient identity. Only recipientIdentity.id is guaranteed to be set. Other fields on the Identity may or my not be set based on the requesting user's relationship with the recipient. */ - Optional< Identity > recipientIdentity; + Optional recipientIdentity; /** The privilege level that the share grants to the recipient. */ - Optional< SharedNotePrivilegeLevel::type > privilege; + Optional privilege; /** The time at which the share was created. */ - Optional< Timestamp > serviceCreated; + Optional serviceCreated; /** The time at which the share was last updated. */ - Optional< Timestamp > serviceUpdated; + Optional serviceUpdated; /** The time at which the share was assigned to a specific recipient user ID. */ - Optional< Timestamp > serviceAssigned; + Optional serviceAssigned; + + virtual void print(QTextStream & strm) const override; bool operator==(const SharedNote & other) const { @@ -3119,6 +3380,13 @@ struct QEVERCLOUD_EXPORT SharedNote { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional sharerUserID MEMBER sharerUserID) + Q_PROPERTY(Optional recipientIdentity MEMBER recipientIdentity) + Q_PROPERTY(Optional privilege MEMBER privilege) + Q_PROPERTY(Optional serviceCreated MEMBER serviceCreated) + Q_PROPERTY(Optional serviceUpdated MEMBER serviceUpdated) + Q_PROPERTY(Optional serviceAssigned MEMBER serviceAssigned) }; /** @@ -3158,26 +3426,37 @@ struct QEVERCLOUD_EXPORT SharedNote { * restrictions. * * */ -struct QEVERCLOUD_EXPORT NoteRestrictions { +struct QEVERCLOUD_EXPORT NoteRestrictions: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The client may not update the note's title (Note.title). */ - Optional< bool > noUpdateTitle; + Optional noUpdateTitle; /** NOT DOCUMENTED */ - Optional< bool > noUpdateContent; + Optional noUpdateContent; /** The client may not email the note (NoteStore.emailNote). */ - Optional< bool > noEmail; + Optional noEmail; /** The client may not share the note with specific recipients (NoteStore.createOrUpdateSharedNotes). */ - Optional< bool > noShare; + Optional noShare; /** The client may not make the note public (NoteStore.shareNote). */ - Optional< bool > noSharePublicly; + Optional noSharePublicly; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteRestrictions & other) const { @@ -3194,6 +3473,12 @@ struct QEVERCLOUD_EXPORT NoteRestrictions { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional noUpdateTitle MEMBER noUpdateTitle) + Q_PROPERTY(Optional noUpdateContent MEMBER noUpdateContent) + Q_PROPERTY(Optional noEmail MEMBER noEmail) + Q_PROPERTY(Optional noShare MEMBER noShare) + Q_PROPERTY(Optional noSharePublicly MEMBER noSharePublicly) }; /** @@ -3204,17 +3489,28 @@ struct QEVERCLOUD_EXPORT NoteRestrictions { *

    * See SyncState and AccountLimits struct field definitions for more details. */ -struct QEVERCLOUD_EXPORT NoteLimits { +struct QEVERCLOUD_EXPORT NoteLimits: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** NOT DOCUMENTED */ - Optional< qint32 > noteResourceCountMax; + Optional noteResourceCountMax; /** NOT DOCUMENTED */ - Optional< qint64 > uploadLimit; + Optional uploadLimit; /** NOT DOCUMENTED */ - Optional< qint64 > resourceSizeMax; + Optional resourceSizeMax; /** NOT DOCUMENTED */ - Optional< qint64 > noteSizeMax; + Optional noteSizeMax; /** NOT DOCUMENTED */ - Optional< qint64 > uploaded; + Optional uploaded; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteLimits & other) const { @@ -3231,13 +3527,28 @@ struct QEVERCLOUD_EXPORT NoteLimits { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional noteResourceCountMax MEMBER noteResourceCountMax) + Q_PROPERTY(Optional uploadLimit MEMBER uploadLimit) + Q_PROPERTY(Optional resourceSizeMax MEMBER resourceSizeMax) + Q_PROPERTY(Optional noteSizeMax MEMBER noteSizeMax) + Q_PROPERTY(Optional uploaded MEMBER uploaded) }; /** * Represents a single note in the user's account. * * */ -struct QEVERCLOUD_EXPORT Note { +struct QEVERCLOUD_EXPORT Note: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The unique identifier of this note. Will be set by the server, but will be omitted by clients calling NoteStore.createNote() @@ -3246,7 +3557,7 @@ struct QEVERCLOUD_EXPORT Note {
    Regex: EDAM_GUID_REGEX */ - Optional< Guid > guid; + Optional guid; /** The subject of the note. Can't begin or end with a space.
    @@ -3254,7 +3565,7 @@ struct QEVERCLOUD_EXPORT Note {
    Regex: EDAM_NOTE_TITLE_REGEX */ - Optional< QString > title; + Optional title; /** The XHTML block that makes up the note. This is the canonical form of the note's contents, so will include abstract @@ -3265,7 +3576,7 @@ struct QEVERCLOUD_EXPORT Note {
    Length: EDAM_NOTE_CONTENT_LEN_MIN - EDAM_NOTE_CONTENT_LEN_MAX */ - Optional< QString > content; + Optional content; /** The binary MD5 checksum of the UTF-8 encoded content body. This will always be set by the server, but clients may choose to omit @@ -3273,13 +3584,13 @@ struct QEVERCLOUD_EXPORT Note {
    Length: EDAM_HASH_LEN (exactly) */ - Optional< QByteArray > contentHash; + Optional contentHash; /** The number of Unicode characters in the content of the note. This will always be set by the service, but clients may choose to omit this value when they submit a Note. */ - Optional< qint32 > contentLength; + Optional contentLength; /** The date and time when the note was created in one of the clients. In most cases, this will match the user's sense of when @@ -3289,14 +3600,14 @@ struct QEVERCLOUD_EXPORT Note { ordering between notes. Notes created directly through the service (e.g. via the web GUI) will have an absolutely ordered "created" value. */ - Optional< Timestamp > created; + Optional created; /** The date and time when the note was last modified in one of the clients. In most cases, this will match the user's sense of when the note was modified, but this field may not be absolutely reliable due to the possibility of client clock errors. */ - Optional< Timestamp > updated; + Optional updated; /** If present, the note is considered "deleted", and this stores the date and time when the note was deleted by one of the clients. @@ -3304,19 +3615,19 @@ struct QEVERCLOUD_EXPORT Note { deleted, but this field may be unreliable due to the possibility of client clock errors. */ - Optional< Timestamp > deleted; + Optional deleted; /** If the note is available for normal actions and viewing, this flag will be set to true. */ - Optional< bool > active; + Optional active; /** A number identifying the last transaction to modify the state of this note (including changes to the note's attributes or resources). The USN values are sequential within an account, and can be used to compare the order of modifications within the service. */ - Optional< qint32 > updateSequenceNum; + Optional updateSequenceNum; /** The unique identifier of the notebook that contains this note. If no notebookGuid is provided on a call to createNote(), the @@ -3326,7 +3637,7 @@ struct QEVERCLOUD_EXPORT Note {
    Regex: EDAM_GUID_REGEX */ - Optional< QString > notebookGuid; + Optional notebookGuid; /** A list of the GUID identifiers for tags that are applied to this note. This may be provided in a call to createNote() to unambiguously declare @@ -3337,7 +3648,7 @@ struct QEVERCLOUD_EXPORT Note { the server will assume that no changes have been made to the resources. Maximum: EDAM_NOTE_TAGS_MAX tags per note */ - Optional< QList< Guid > > tagGuids; + Optional> tagGuids; /** The list of resources that are embedded within this note. If the list of resources are omitted on a call to updateNote(), then @@ -3347,13 +3658,13 @@ struct QEVERCLOUD_EXPORT Note { the Note is returned in the future. Maximum: EDAM_NOTE_RESOURCES_MAX resources per note */ - Optional< QList< Resource > > resources; + Optional> resources; /** A list of the attributes for this note. If the list of attributes are omitted on a call to updateNote(), then the server will assume that no changes have been made to the resources. */ - Optional< NoteAttributes > attributes; + Optional attributes; /** May be provided by clients during calls to createNote() as an alternative to providing the tagGuids of existing tags. If any tagNames @@ -3361,14 +3672,14 @@ struct QEVERCLOUD_EXPORT Note { don't already exist. Created tags will have no parent (they will be at the top level of the tag panel). */ - Optional< QStringList > tagNames; + Optional tagNames; /** The list of recipients with whom this note has been shared. This field will be unset if the caller has access to the note via the containing notebook, but does not have activity feed permission for that notebook. This field is read-only. Clients may not make changes to a note's sharing state via this field. */ - Optional< QList< SharedNote > > sharedNotes; + Optional> sharedNotes; /** If this field is set, the user has note-level permissions that may differ from their notebook-level permissions. In this case, the restrictions structure specifies @@ -3377,9 +3688,11 @@ struct QEVERCLOUD_EXPORT Note { note-specific restrictions. However, a client may still be limited based on the user's notebook permissions. */ - Optional< NoteRestrictions > restrictions; + Optional restrictions; /** NOT DOCUMENTED */ - Optional< NoteLimits > limits; + Optional limits; + + virtual void print(QTextStream & strm) const override; bool operator==(const Note & other) const { @@ -3409,6 +3722,25 @@ struct QEVERCLOUD_EXPORT Note { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional guid MEMBER guid) + Q_PROPERTY(Optional title MEMBER title) + Q_PROPERTY(Optional content MEMBER content) + Q_PROPERTY(Optional contentHash MEMBER contentHash) + Q_PROPERTY(Optional contentLength MEMBER contentLength) + Q_PROPERTY(Optional created MEMBER created) + Q_PROPERTY(Optional updated MEMBER updated) + Q_PROPERTY(Optional deleted MEMBER deleted) + Q_PROPERTY(Optional active MEMBER active) + Q_PROPERTY(Optional updateSequenceNum MEMBER updateSequenceNum) + Q_PROPERTY(Optional notebookGuid MEMBER notebookGuid) + Q_PROPERTY(Optional> tagGuids MEMBER tagGuids) + Q_PROPERTY(Optional> resources MEMBER resources) + Q_PROPERTY(Optional attributes MEMBER attributes) + Q_PROPERTY(Optional tagNames MEMBER tagNames) + Q_PROPERTY(Optional> sharedNotes MEMBER sharedNotes) + Q_PROPERTY(Optional restrictions MEMBER restrictions) + Q_PROPERTY(Optional limits MEMBER limits) }; /** @@ -3416,7 +3748,16 @@ struct QEVERCLOUD_EXPORT Note { * reference to one of these structures, which gives the location and optional * description of the externally-visible public Notebook. * */ -struct QEVERCLOUD_EXPORT Publishing { +struct QEVERCLOUD_EXPORT Publishing: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** If this field is present, then the notebook is published for mass consumption on the Internet under the provided URI, which is @@ -3428,18 +3769,18 @@ struct QEVERCLOUD_EXPORT Publishing {
    Regex: EDAM_PUBLISHING_URI_REGEX */ - Optional< QString > uri; + Optional uri; /** When the notes are publicly displayed, they will be sorted based on the requested criteria. */ - Optional< NoteSortOrder::type > order; + Optional order; /** If this is set to true, then the public notes will be displayed in ascending order (e.g. from oldest to newest). Otherwise, the notes will be displayed in descending order (e.g. newest to oldest). */ - Optional< bool > ascending; + Optional ascending; /** This field may be used to provide a short description of the notebook, which may be displayed when (e.g.) the @@ -3450,7 +3791,9 @@ struct QEVERCLOUD_EXPORT Publishing {
    Regex: EDAM_PUBLISHING_DESCRIPTION_REGEX */ - Optional< QString > publicDescription; + Optional publicDescription; + + virtual void print(QTextStream & strm) const override; bool operator==(const Publishing & other) const { @@ -3466,6 +3809,11 @@ struct QEVERCLOUD_EXPORT Publishing { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional uri MEMBER uri) + Q_PROPERTY(Optional order MEMBER order) + Q_PROPERTY(Optional ascending MEMBER ascending) + Q_PROPERTY(Optional publicDescription MEMBER publicDescription) }; /** @@ -3475,7 +3823,16 @@ struct QEVERCLOUD_EXPORT Publishing { * library. * * */ -struct QEVERCLOUD_EXPORT BusinessNotebook { +struct QEVERCLOUD_EXPORT BusinessNotebook: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** A short description of the notebook's content that will be displayed in the business library user interface. The description may not begin @@ -3486,17 +3843,19 @@ struct QEVERCLOUD_EXPORT BusinessNotebook {
    Regex: EDAM_BUSINESS_NOTEBOOK_DESCRIPTION_REGEX */ - Optional< QString > notebookDescription; + Optional notebookDescription; /** The privileges that will be granted to users who join the notebook through the business library. */ - Optional< SharedNotebookPrivilegeLevel::type > privilege; + Optional privilege; /** Whether the notebook should be "recommended" when displayed in the business library user interface. */ - Optional< bool > recommended; + Optional recommended; + + virtual void print(QTextStream & strm) const override; bool operator==(const BusinessNotebook & other) const { @@ -3511,28 +3870,43 @@ struct QEVERCLOUD_EXPORT BusinessNotebook { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional notebookDescription MEMBER notebookDescription) + Q_PROPERTY(Optional privilege MEMBER privilege) + Q_PROPERTY(Optional recommended MEMBER recommended) }; /** * A structure defining the scope of a SavedSearch. * * */ -struct QEVERCLOUD_EXPORT SavedSearchScope { +struct QEVERCLOUD_EXPORT SavedSearchScope: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The search should include notes from the account that contains the SavedSearch. */ - Optional< bool > includeAccount; + Optional includeAccount; /** The search should include notes within those shared notebooks that the user has joined that are NOT business notebooks. */ - Optional< bool > includePersonalLinkedNotebooks; + Optional includePersonalLinkedNotebooks; /** The search should include notes within those shared notebooks that the user has joined that are business notebooks in the business that the user is currently a member of. */ - Optional< bool > includeBusinessLinkedNotebooks; + Optional includeBusinessLinkedNotebooks; + + virtual void print(QTextStream & strm) const override; bool operator==(const SavedSearchScope & other) const { @@ -3547,12 +3921,25 @@ struct QEVERCLOUD_EXPORT SavedSearchScope { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional includeAccount MEMBER includeAccount) + Q_PROPERTY(Optional includePersonalLinkedNotebooks MEMBER includePersonalLinkedNotebooks) + Q_PROPERTY(Optional includeBusinessLinkedNotebooks MEMBER includeBusinessLinkedNotebooks) }; /** * A named search associated with the account that can be quickly re-used. * */ -struct QEVERCLOUD_EXPORT SavedSearch { +struct QEVERCLOUD_EXPORT SavedSearch: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The unique identifier of this search. Will be set by the service, so may be omitted by the client when creating. @@ -3561,7 +3948,7 @@ struct QEVERCLOUD_EXPORT SavedSearch {
    Regex: EDAM_GUID_REGEX */ - Optional< Guid > guid; + Optional guid; /** The name of the saved search to display in the GUI. The account may only contain one search with a given name (case-insensitive @@ -3571,25 +3958,25 @@ struct QEVERCLOUD_EXPORT SavedSearch {
    Regex: EDAM_SAVED_SEARCH_NAME_REGEX */ - Optional< QString > name; + Optional name; /** A string expressing the search to be performed.
    Length: EDAM_SAVED_SEARCH_QUERY_LEN_MIN - EDAM_SAVED_SEARCH_QUERY_LEN_MAX */ - Optional< QString > query; + Optional query; /** The format of the query string, to determine how to parse and process it. */ - Optional< QueryFormat::type > format; + Optional format; /** A number identifying the last transaction to modify the state of this object. The USN values are sequential within an account, and can be used to compare the order of modifications within the service. */ - Optional< qint32 > updateSequenceNum; + Optional updateSequenceNum; /**

    Specifies the set of notes that should be included in the search, if possible.

    @@ -3603,7 +3990,9 @@ struct QEVERCLOUD_EXPORT SavedSearch { context. If a client cannot search any of the desired scopes, it should refuse to execute the search.

    */ - Optional< SavedSearchScope > scope; + Optional scope; + + virtual void print(QTextStream & strm) const override; bool operator==(const SavedSearch & other) const { @@ -3621,6 +4010,13 @@ struct QEVERCLOUD_EXPORT SavedSearch { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional guid MEMBER guid) + Q_PROPERTY(Optional name MEMBER name) + Q_PROPERTY(Optional query MEMBER query) + Q_PROPERTY(Optional format MEMBER format) + Q_PROPERTY(Optional updateSequenceNum MEMBER updateSequenceNum) + Q_PROPERTY(Optional scope MEMBER scope) }; /** @@ -3637,21 +4033,32 @@ struct QEVERCLOUD_EXPORT SavedSearch { * value. * * */ -struct QEVERCLOUD_EXPORT SharedNotebookRecipientSettings { +struct QEVERCLOUD_EXPORT SharedNotebookRecipientSettings: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** Indicates that the user wishes to receive daily e-mail notifications for reminders associated with the notebook. This may be true only for business notebooks that belong to the business of which the user is a member. You may only set this value on a notebook in your business. */ - Optional< bool > reminderNotifyEmail; + Optional reminderNotifyEmail; /** Indicates that the user wishes to receive notifications for reminders by applications that support providing such notifications. The exact nature of the notification is defined by the individual applications. */ - Optional< bool > reminderNotifyInApp; + Optional reminderNotifyInApp; + + virtual void print(QTextStream & strm) const override; bool operator==(const SharedNotebookRecipientSettings & other) const { @@ -3665,6 +4072,9 @@ struct QEVERCLOUD_EXPORT SharedNotebookRecipientSettings { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional reminderNotifyEmail MEMBER reminderNotifyEmail) + Q_PROPERTY(Optional reminderNotifyInApp MEMBER reminderNotifyInApp) }; /** @@ -3677,7 +4087,16 @@ struct QEVERCLOUD_EXPORT SharedNotebookRecipientSettings { * has a true/false value, it will always have a true/false value. * * */ -struct QEVERCLOUD_EXPORT NotebookRecipientSettings { +struct QEVERCLOUD_EXPORT NotebookRecipientSettings: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** Indicates that the user wishes to receive daily e-mail notifications for reminders associated with the notebook. This may be @@ -3685,32 +4104,34 @@ struct QEVERCLOUD_EXPORT NotebookRecipientSettings { which the user is a member. You may only set this value on a notebook in your business. This value will initially be unset. */ - Optional< bool > reminderNotifyEmail; + Optional reminderNotifyEmail; /** Indicates that the user wishes to receive notifications for reminders by applications that support providing such notifications. The exact nature of the notification is defined by the individual applications. This value will initially be unset. */ - Optional< bool > reminderNotifyInApp; + Optional reminderNotifyInApp; /** DEPRECATED: Use recipientStatus instead. The notebook is on the recipient's notebook list (formerly, we would say that the recipient has "joined" the notebook) */ - Optional< bool > inMyList; + Optional inMyList; /** The stack the recipient has put this notebook into. See Notebook.stack for a definition. Every recipient can have their own stack value for the same notebook. */ - Optional< QString > stack; + Optional stack; /** The notebook is on/off the recipient's notebook list (formerly, we would say that the recipient has "joined" the notebook) and perhaps also their default notebook */ - Optional< RecipientStatus::type > recipientStatus; + Optional recipientStatus; + + virtual void print(QTextStream & strm) const override; bool operator==(const NotebookRecipientSettings & other) const { @@ -3727,46 +4148,61 @@ struct QEVERCLOUD_EXPORT NotebookRecipientSettings { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional reminderNotifyEmail MEMBER reminderNotifyEmail) + Q_PROPERTY(Optional reminderNotifyInApp MEMBER reminderNotifyInApp) + Q_PROPERTY(Optional inMyList MEMBER inMyList) + Q_PROPERTY(Optional stack MEMBER stack) + Q_PROPERTY(Optional recipientStatus MEMBER recipientStatus) }; /** * Shared notebooks represent a relationship between a notebook and a single * share invitation recipient. * */ -struct QEVERCLOUD_EXPORT SharedNotebook { +struct QEVERCLOUD_EXPORT SharedNotebook: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The primary identifier of the share, which is not globally unique. */ - Optional< qint64 > id; + Optional id; /** The user id of the owner of the notebook. */ - Optional< UserID > userId; + Optional userId; /** The GUID of the notebook that has been shared. */ - Optional< Guid > notebookGuid; + Optional notebookGuid; /** A string containing a display name for the recipient of the share. This may be an email address, a phone number, a full name, or some other descriptive string This field is read-only to clients. It will be filled in by the service when returning shared notebooks. */ - Optional< QString > email; + Optional email; /** The IdentityID of the share recipient. If present, only the user who has claimed that identity may access this share. */ - Optional< IdentityID > recipientIdentityId; + Optional recipientIdentityId; /** DEPRECATED */ - Optional< bool > notebookModifiable; + Optional notebookModifiable; /** The date that the owner first created the share with the specific email address. */ - Optional< Timestamp > serviceCreated; + Optional serviceCreated; /** The date the shared notebook was last updated on the service. This will be updated when authenticateToSharedNotebook is called the first @@ -3775,7 +4211,7 @@ struct QEVERCLOUD_EXPORT SharedNotebook { as part of a shareNotebook(...) call, as well as on any calls to updateSharedNotebook(...). */ - Optional< Timestamp > serviceUpdated; + Optional serviceUpdated; /** An immutable, opaque string that acts as a globally unique identifier for this shared notebook record. You can use this field to @@ -3783,25 +4219,25 @@ struct QEVERCLOUD_EXPORT SharedNotebook { create new LinkedNotebook records. This field replaces the deprecated shareKey field. */ - Optional< QString > globalId; + Optional globalId; /** DEPRECATED. The username of the user who can access this share. This value is read-only to clients. It will be filled in by the service when returning shared notebooks. */ - Optional< QString > username; + Optional username; /** The privilege level granted to the notebook, activity stream, and invitations. See the corresponding enumeration for details. */ - Optional< SharedNotebookPrivilegeLevel::type > privilege; + Optional privilege; /** Settings intended for use only by the recipient of this shared notebook. You should skip setting this value unless you want to change the value contained inside the structure, and only if you are the recipient. */ - Optional< SharedNotebookRecipientSettings > recipientSettings; + Optional recipientSettings; /** The user id of the user who shared a notebook via this shared notebook instance. This may not be the same as userId, since a user with full @@ -3810,7 +4246,7 @@ struct QEVERCLOUD_EXPORT SharedNotebook { field is currently unset for a SharedNotebook created by joining a notebook that has been published to the business. */ - Optional< UserID > sharerUserId; + Optional sharerUserId; /** The username of the user who can access this share. This is the username for the user with the id in recipientUserId. This value can be set @@ -3818,7 +4254,7 @@ struct QEVERCLOUD_EXPORT SharedNotebook { created SharedNotebook being assigned to a user. This value is always set if serviceAssigned is set. */ - Optional< QString > recipientUsername; + Optional recipientUsername; /** The id of the user who can access this share. This is the id for the user with the username in recipientUsername. This value is read-only and set @@ -3827,13 +4263,15 @@ struct QEVERCLOUD_EXPORT SharedNotebook { prefer this field over recipientUsername unless they need to use usernames directly. */ - Optional< UserID > recipientUserId; + Optional recipientUserId; /** The date this SharedNotebook was assigned (i.e. has been associated with an Evernote user whose user ID is set in recipientUserId). Unset if the SharedNotebook is not assigned. This field is a read-only value that is set by the service. */ - Optional< Timestamp > serviceAssigned; + Optional serviceAssigned; + + virtual void print(QTextStream & strm) const override; bool operator==(const SharedNotebook & other) const { @@ -3861,14 +4299,42 @@ struct QEVERCLOUD_EXPORT SharedNotebook { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional id MEMBER id) + Q_PROPERTY(Optional userId MEMBER userId) + Q_PROPERTY(Optional notebookGuid MEMBER notebookGuid) + Q_PROPERTY(Optional email MEMBER email) + Q_PROPERTY(Optional recipientIdentityId MEMBER recipientIdentityId) + Q_PROPERTY(Optional notebookModifiable MEMBER notebookModifiable) + Q_PROPERTY(Optional serviceCreated MEMBER serviceCreated) + Q_PROPERTY(Optional serviceUpdated MEMBER serviceUpdated) + Q_PROPERTY(Optional globalId MEMBER globalId) + Q_PROPERTY(Optional username MEMBER username) + Q_PROPERTY(Optional privilege MEMBER privilege) + Q_PROPERTY(Optional recipientSettings MEMBER recipientSettings) + Q_PROPERTY(Optional sharerUserId MEMBER sharerUserId) + Q_PROPERTY(Optional recipientUsername MEMBER recipientUsername) + Q_PROPERTY(Optional recipientUserId MEMBER recipientUserId) + Q_PROPERTY(Optional serviceAssigned MEMBER serviceAssigned) }; /** * Specifies if the client can move a Notebook to a Workspace. */ -struct QEVERCLOUD_EXPORT CanMoveToContainerRestrictions { +struct QEVERCLOUD_EXPORT CanMoveToContainerRestrictions: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** NOT DOCUMENTED */ - Optional< CanMoveToContainerStatus::type > canMoveToContainer; + Optional canMoveToContainer; + + virtual void print(QTextStream & strm) const override; bool operator==(const CanMoveToContainerRestrictions & other) const { @@ -3881,6 +4347,8 @@ struct QEVERCLOUD_EXPORT CanMoveToContainerRestrictions { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional canMoveToContainer MEMBER canMoveToContainer) }; /** @@ -3909,136 +4377,147 @@ struct QEVERCLOUD_EXPORT CanMoveToContainerRestrictions { * the values were obtained. * * */ -struct QEVERCLOUD_EXPORT NotebookRestrictions { +struct QEVERCLOUD_EXPORT NotebookRestrictions: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The client is not able to read notes from the service and the notebook is write-only. */ - Optional< bool > noReadNotes; + Optional noReadNotes; /** The client may not create new notes in the notebook. */ - Optional< bool > noCreateNotes; + Optional noCreateNotes; /** The client may not update notes currently in the notebook. */ - Optional< bool > noUpdateNotes; + Optional noUpdateNotes; /** The client may not expunge notes currently in the notebook. */ - Optional< bool > noExpungeNotes; + Optional noExpungeNotes; /** The client may not share notes in the notebook via the shareNote or createOrUpdateSharedNotes methods. */ - Optional< bool > noShareNotes; + Optional noShareNotes; /** The client may not e-mail notes by guid via the Evernote service by using the emailNote method. Email notes by value by populating the note parameter instead. */ - Optional< bool > noEmailNotes; + Optional noEmailNotes; /** The client may not send messages to the share recipients of the notebook. */ - Optional< bool > noSendMessageToRecipients; + Optional noSendMessageToRecipients; /** The client may not update the Notebook object itself, for example, via the updateNotebook method. */ - Optional< bool > noUpdateNotebook; + Optional noUpdateNotebook; /** The client may not expunge the Notebook object itself, for example, via the expungeNotebook method. */ - Optional< bool > noExpungeNotebook; + Optional noExpungeNotebook; /** The client may not set this notebook to be the default notebook. The caller should leave Notebook.defaultNotebook unset. */ - Optional< bool > noSetDefaultNotebook; + Optional noSetDefaultNotebook; /** If the client is able to update the Notebook, the Notebook.stack value may not be set. */ - Optional< bool > noSetNotebookStack; + Optional noSetNotebookStack; /** The client may not publish the notebook to the public. For example, business notebooks may not be shared publicly. */ - Optional< bool > noPublishToPublic; + Optional noPublishToPublic; /** The client may not publish the notebook to the business library. */ - Optional< bool > noPublishToBusinessLibrary; + Optional noPublishToBusinessLibrary; /** The client may not complete an operation that results in a new tag being created in the owner's account. */ - Optional< bool > noCreateTags; + Optional noCreateTags; /** The client may not update tags in the owner's account. */ - Optional< bool > noUpdateTags; + Optional noUpdateTags; /** The client may not expunge tags in the owner's account. */ - Optional< bool > noExpungeTags; + Optional noExpungeTags; /** If the client is able to create or update tags in the owner's account, then they will not be able to set the parent tag. Leave the value unset. */ - Optional< bool > noSetParentTag; + Optional noSetParentTag; /** The client is unable to create shared notebooks for the notebook. */ - Optional< bool > noCreateSharedNotebooks; + Optional noCreateSharedNotebooks; /** Restrictions on which shared notebook instances can be updated. If the value is not set or null, then the client can update any of the shared notebooks associated with the notebook on which the NotebookRestrictions are defined. See the enumeration for further details. */ - Optional< SharedNotebookInstanceRestrictions::type > updateWhichSharedNotebookRestrictions; + Optional updateWhichSharedNotebookRestrictions; /** Restrictions on which shared notebook instances can be expunged. If the value is not set or null, then the client can expunge any of the shared notebooks associated with the notebook on which the NotebookRestrictions are defined. See the enumeration for further details. */ - Optional< SharedNotebookInstanceRestrictions::type > expungeWhichSharedNotebookRestrictions; + Optional expungeWhichSharedNotebookRestrictions; /** The client may not share notes in the notebook via the shareNoteWithBusiness method. */ - Optional< bool > noShareNotesWithBusiness; + Optional noShareNotesWithBusiness; /** The client may not rename this notebook. */ - Optional< bool > noRenameNotebook; + Optional noRenameNotebook; /** clients may not change the NotebookRecipientSettings.inMyList settings for this notebook. */ - Optional< bool > noSetInMyList; + Optional noSetInMyList; /** NOT DOCUMENTED */ - Optional< bool > noChangeContact; + Optional noChangeContact; /** Specifies if the client can move this notebook to a container and if not, the reason why. */ - Optional< CanMoveToContainerRestrictions > canMoveToContainerRestrictions; + Optional canMoveToContainerRestrictions; /** NOT DOCUMENTED */ - Optional< bool > noSetReminderNotifyEmail; + Optional noSetReminderNotifyEmail; /** NOT DOCUMENTED */ - Optional< bool > noSetReminderNotifyInApp; + Optional noSetReminderNotifyInApp; /** NOT DOCUMENTED */ - Optional< bool > noSetRecipientSettingsStack; + Optional noSetRecipientSettingsStack; /** If set, the client cannot move a Note into or out of the Notebook. */ - Optional< bool > noCanMoveNote; + Optional noCanMoveNote; + + virtual void print(QTextStream & strm) const override; bool operator==(const NotebookRestrictions & other) const { @@ -4079,12 +4558,51 @@ struct QEVERCLOUD_EXPORT NotebookRestrictions { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional noReadNotes MEMBER noReadNotes) + Q_PROPERTY(Optional noCreateNotes MEMBER noCreateNotes) + Q_PROPERTY(Optional noUpdateNotes MEMBER noUpdateNotes) + Q_PROPERTY(Optional noExpungeNotes MEMBER noExpungeNotes) + Q_PROPERTY(Optional noShareNotes MEMBER noShareNotes) + Q_PROPERTY(Optional noEmailNotes MEMBER noEmailNotes) + Q_PROPERTY(Optional noSendMessageToRecipients MEMBER noSendMessageToRecipients) + Q_PROPERTY(Optional noUpdateNotebook MEMBER noUpdateNotebook) + Q_PROPERTY(Optional noExpungeNotebook MEMBER noExpungeNotebook) + Q_PROPERTY(Optional noSetDefaultNotebook MEMBER noSetDefaultNotebook) + Q_PROPERTY(Optional noSetNotebookStack MEMBER noSetNotebookStack) + Q_PROPERTY(Optional noPublishToPublic MEMBER noPublishToPublic) + Q_PROPERTY(Optional noPublishToBusinessLibrary MEMBER noPublishToBusinessLibrary) + Q_PROPERTY(Optional noCreateTags MEMBER noCreateTags) + Q_PROPERTY(Optional noUpdateTags MEMBER noUpdateTags) + Q_PROPERTY(Optional noExpungeTags MEMBER noExpungeTags) + Q_PROPERTY(Optional noSetParentTag MEMBER noSetParentTag) + Q_PROPERTY(Optional noCreateSharedNotebooks MEMBER noCreateSharedNotebooks) + Q_PROPERTY(Optional updateWhichSharedNotebookRestrictions MEMBER updateWhichSharedNotebookRestrictions) + Q_PROPERTY(Optional expungeWhichSharedNotebookRestrictions MEMBER expungeWhichSharedNotebookRestrictions) + Q_PROPERTY(Optional noShareNotesWithBusiness MEMBER noShareNotesWithBusiness) + Q_PROPERTY(Optional noRenameNotebook MEMBER noRenameNotebook) + Q_PROPERTY(Optional noSetInMyList MEMBER noSetInMyList) + Q_PROPERTY(Optional noChangeContact MEMBER noChangeContact) + Q_PROPERTY(Optional canMoveToContainerRestrictions MEMBER canMoveToContainerRestrictions) + Q_PROPERTY(Optional noSetReminderNotifyEmail MEMBER noSetReminderNotifyEmail) + Q_PROPERTY(Optional noSetReminderNotifyInApp MEMBER noSetReminderNotifyInApp) + Q_PROPERTY(Optional noSetRecipientSettingsStack MEMBER noSetRecipientSettingsStack) + Q_PROPERTY(Optional noCanMoveNote MEMBER noCanMoveNote) }; /** * A unique container for a set of notes. * */ -struct QEVERCLOUD_EXPORT Notebook { +struct QEVERCLOUD_EXPORT Notebook: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The unique identifier of this notebook.
    @@ -4092,7 +4610,7 @@ struct QEVERCLOUD_EXPORT Notebook {
    Regex: EDAM_GUID_REGEX */ - Optional< Guid > guid; + Optional guid; /** A sequence of characters representing the name of the notebook. May be changed by clients, but the account may not contain two @@ -4103,14 +4621,14 @@ struct QEVERCLOUD_EXPORT Notebook {
    Regex: EDAM_NOTEBOOK_NAME_REGEX */ - Optional< QString > name; + Optional name; /** A number identifying the last transaction to modify the state of this object. The USN values are sequential within an account, and can be used to compare the order of modifications within the service. */ - Optional< qint32 > updateSequenceNum; + Optional updateSequenceNum; /** If true, this notebook should be used for new notes whenever the user has not (or cannot) specify a desired target notebook. @@ -4123,21 +4641,21 @@ struct QEVERCLOUD_EXPORT Notebook { set to false by the service. If the account has no default notebook set, the service will use the most recent notebook as the default. */ - Optional< bool > defaultNotebook; + Optional defaultNotebook; /** The time when this notebook was created on the service. This will be set on the service during creation, and the service will provide this value when it returns a Notebook to a client. The service will ignore this value if it is sent by clients. */ - Optional< Timestamp > serviceCreated; + Optional serviceCreated; /** The time when this notebook was last modified on the service. This will be set on the service during creation, and the service will provide this value when it returns a Notebook to a client. The service will ignore this value if it is sent by clients. */ - Optional< Timestamp > serviceUpdated; + Optional serviceUpdated; /** If the Notebook has been opened for public access, then this will point to the set of publishing information for the Notebook (URI, description, etc.). A Notebook cannot be @@ -4147,7 +4665,7 @@ struct QEVERCLOUD_EXPORT Notebook { Note that this structure is never populated for business notebooks, see the businessNotebook field. */ - Optional< Publishing > publishing; + Optional publishing; /** If this is set to true, then the Notebook will be accessible either to the public, or for business users to their business, @@ -4156,7 +4674,7 @@ struct QEVERCLOUD_EXPORT Notebook { Clients that do not wish to change the publishing behavior of a Notebook should not set this value when calling NoteStore.updateNotebook(). */ - Optional< bool > published; + Optional published; /** If this is set, then the notebook is visually contained within a stack of notebooks with this name. All notebooks in the same account with the @@ -4164,11 +4682,11 @@ struct QEVERCLOUD_EXPORT Notebook { Notebooks with no stack set are "top level" and not contained within a stack. */ - Optional< QString > stack; + Optional stack; /** DEPRECATED - replaced by sharedNotebooks. */ - Optional< QList< qint64 > > sharedNotebookIds; + Optional> sharedNotebookIds; /** The list of recipients to whom this notebook has been shared (one SharedNotebook object per recipient email address). This field will @@ -4178,14 +4696,14 @@ struct QEVERCLOUD_EXPORT Notebook { This field is read-only. Clients may not make changes to shared notebooks via this field. */ - Optional< QList< SharedNotebook > > sharedNotebooks; + Optional> sharedNotebooks; /** If the notebook is part of a business account and has been shared with the entire business, this will contain sharing information. The presence or absence of this field is not a reliable test of whether a given notebook is in fact a business notebook - the field is only used when a notebook is or has been shared with the entire business. */ - Optional< BusinessNotebook > businessNotebook; + Optional businessNotebook; /** Intended for use with Business accounts, this field identifies the user who has been designated as the "contact". For notebooks created in business @@ -4195,15 +4713,17 @@ struct QEVERCLOUD_EXPORT Notebook { field unset, indicating that no change to the value is being requested and that the existing value, if any, should be preserved. */ - Optional< User > contact; + Optional contact; /** NOT DOCUMENTED */ - Optional< NotebookRestrictions > restrictions; + Optional restrictions; /** This represents the preferences/settings that a recipient has set for this notebook. These are intended to be changed only by the recipient, and each recipient has their own recipient settings. */ - Optional< NotebookRecipientSettings > recipientSettings; + Optional recipientSettings; + + virtual void print(QTextStream & strm) const override; bool operator==(const Notebook & other) const { @@ -4230,6 +4750,22 @@ struct QEVERCLOUD_EXPORT Notebook { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional guid MEMBER guid) + Q_PROPERTY(Optional name MEMBER name) + Q_PROPERTY(Optional updateSequenceNum MEMBER updateSequenceNum) + Q_PROPERTY(Optional defaultNotebook MEMBER defaultNotebook) + Q_PROPERTY(Optional serviceCreated MEMBER serviceCreated) + Q_PROPERTY(Optional serviceUpdated MEMBER serviceUpdated) + Q_PROPERTY(Optional publishing MEMBER publishing) + Q_PROPERTY(Optional published MEMBER published) + Q_PROPERTY(Optional stack MEMBER stack) + Q_PROPERTY(Optional> sharedNotebookIds MEMBER sharedNotebookIds) + Q_PROPERTY(Optional> sharedNotebooks MEMBER sharedNotebooks) + Q_PROPERTY(Optional businessNotebook MEMBER businessNotebook) + Q_PROPERTY(Optional contact MEMBER contact) + Q_PROPERTY(Optional restrictions MEMBER restrictions) + Q_PROPERTY(Optional recipientSettings MEMBER recipientSettings) }; /** @@ -4237,22 +4773,31 @@ struct QEVERCLOUD_EXPORT Notebook { * individual shared notebook in another user's account. * * */ -struct QEVERCLOUD_EXPORT LinkedNotebook { +struct QEVERCLOUD_EXPORT LinkedNotebook: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The display name of the shared notebook. The link owner can change this. */ - Optional< QString > shareName; + Optional shareName; /** The username of the user who owns the shared or public notebook. */ - Optional< QString > username; + Optional username; /** The shard ID of the notebook if the notebook is not public.
    uri The identifier of the public notebook. */ - Optional< QString > shardId; + Optional shardId; /** The globally unique identifier (globalId) of the shared notebook that corresponds to the share key, or the GUID of the Notebook that the linked notebook @@ -4260,9 +4805,9 @@ struct QEVERCLOUD_EXPORT LinkedNotebook { Notebook.GUID value when creating new LinkedNotebooks. This field replaces the deprecated "shareKey" field. */ - Optional< QString > sharedNotebookGlobalId; + Optional sharedNotebookGlobalId; /** NOT DOCUMENTED */ - Optional< QString > uri; + Optional uri; /** The unique identifier of this linked notebook. Will be set whenever a linked notebook is retrieved from the service, but may be null when a client @@ -4272,21 +4817,21 @@ struct QEVERCLOUD_EXPORT LinkedNotebook {
    Regex: EDAM_GUID_REGEX */ - Optional< Guid > guid; + Optional guid; /** A number identifying the last transaction to modify the state of this object. The USN values are sequential within an account, and can be used to compare the order of modifications within the service. */ - Optional< qint32 > updateSequenceNum; + Optional updateSequenceNum; /** This field will contain the full URL that clients should use to make NoteStore requests to the server shard that contains that notebook's data. I.e. this is the URL that should be used to create the Thrift HTTP client transport to send messages to the NoteStore service for the account. */ - Optional< QString > noteStoreUrl; + Optional noteStoreUrl; /** This field will contain the initial part of the URLs that should be used to make requests to Evernote's thin client "web API", which provide @@ -4296,7 +4841,7 @@ struct QEVERCLOUD_EXPORT LinkedNotebook { end of this string to construct the full URL, as documented on our developer web site. */ - Optional< QString > webApiUrlPrefix; + Optional webApiUrlPrefix; /** If this is set, then the notebook is visually contained within a stack of notebooks with this name. All notebooks in the same account with the @@ -4305,12 +4850,14 @@ struct QEVERCLOUD_EXPORT LinkedNotebook { stack. The link owner can change this and this field is for the benefit of the link owner. */ - Optional< QString > stack; + Optional stack; /** If set, this will be the unique identifier for the business that owns the notebook to which the linked notebook refers. */ - Optional< qint32 > businessId; + Optional businessId; + + virtual void print(QTextStream & strm) const override; bool operator==(const LinkedNotebook & other) const { @@ -4333,6 +4880,18 @@ struct QEVERCLOUD_EXPORT LinkedNotebook { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional shareName MEMBER shareName) + Q_PROPERTY(Optional username MEMBER username) + Q_PROPERTY(Optional shardId MEMBER shardId) + Q_PROPERTY(Optional sharedNotebookGlobalId MEMBER sharedNotebookGlobalId) + Q_PROPERTY(Optional uri MEMBER uri) + Q_PROPERTY(Optional guid MEMBER guid) + Q_PROPERTY(Optional updateSequenceNum MEMBER updateSequenceNum) + Q_PROPERTY(Optional noteStoreUrl MEMBER noteStoreUrl) + Q_PROPERTY(Optional webApiUrlPrefix MEMBER webApiUrlPrefix) + Q_PROPERTY(Optional stack MEMBER stack) + Q_PROPERTY(Optional businessId MEMBER businessId) }; /** @@ -4340,29 +4899,40 @@ struct QEVERCLOUD_EXPORT LinkedNotebook { * a notebook. NotebookDescriptor is expected to remain a lighter-weight * structure when compared to Notebook. * */ -struct QEVERCLOUD_EXPORT NotebookDescriptor { +struct QEVERCLOUD_EXPORT NotebookDescriptor: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The unique identifier of the notebook. */ - Optional< Guid > guid; + Optional guid; /** A sequence of characters representing the name of the notebook. */ - Optional< QString > notebookDisplayName; + Optional notebookDisplayName; /** The User.name value of the notebook's "contact". */ - Optional< QString > contactName; + Optional contactName; /** Whether a SharedNotebook record exists between the calling user and this notebook. */ - Optional< bool > hasSharedNotebook; + Optional hasSharedNotebook; /** The number of users who have joined this notebook. */ - Optional< qint32 > joinedUserCount; + Optional joinedUserCount; + + virtual void print(QTextStream & strm) const override; bool operator==(const NotebookDescriptor & other) const { @@ -4379,54 +4949,71 @@ struct QEVERCLOUD_EXPORT NotebookDescriptor { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional guid MEMBER guid) + Q_PROPERTY(Optional notebookDisplayName MEMBER notebookDisplayName) + Q_PROPERTY(Optional contactName MEMBER contactName) + Q_PROPERTY(Optional hasSharedNotebook MEMBER hasSharedNotebook) + Q_PROPERTY(Optional joinedUserCount MEMBER joinedUserCount) }; /** * This structure represents profile information for a user in a business. * * */ -struct QEVERCLOUD_EXPORT UserProfile { +struct QEVERCLOUD_EXPORT UserProfile: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The numeric identifier that uniquely identifies a user. */ - Optional< UserID > id; + Optional id; /** The full name of the user. */ - Optional< QString > name; + Optional name; /** The user's business email address. If the user has not registered their business email address, this field will be empty. */ - Optional< QString > email; + Optional email; /** The user's Evernote username. */ - Optional< QString > username; + Optional username; /** The user's business specific attributes. */ - Optional< BusinessUserAttributes > attributes; + Optional attributes; /** The time when the user joined the business */ - Optional< Timestamp > joined; + Optional joined; /** The time when the user's profile photo was most recently updated */ - Optional< Timestamp > photoLastUpdated; + Optional photoLastUpdated; /** A URL identifying a copy of the user's current profile photo */ - Optional< QString > photoUrl; + Optional photoUrl; /** The BusinessUserRole for the user */ - Optional< BusinessUserRole::type > role; + Optional role; /** The BusinessUserStatus for the user */ - Optional< BusinessUserStatus::type > status; + Optional status; + + virtual void print(QTextStream & strm) const override; bool operator==(const UserProfile & other) const { @@ -4448,6 +5035,17 @@ struct QEVERCLOUD_EXPORT UserProfile { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional id MEMBER id) + Q_PROPERTY(Optional name MEMBER name) + Q_PROPERTY(Optional email MEMBER email) + Q_PROPERTY(Optional username MEMBER username) + Q_PROPERTY(Optional attributes MEMBER attributes) + Q_PROPERTY(Optional joined MEMBER joined) + Q_PROPERTY(Optional photoLastUpdated MEMBER photoLastUpdated) + Q_PROPERTY(Optional photoUrl MEMBER photoUrl) + Q_PROPERTY(Optional role MEMBER role) + Q_PROPERTY(Optional status MEMBER status) }; /** @@ -4456,27 +5054,38 @@ struct QEVERCLOUD_EXPORT UserProfile { * depending on available screen real estate, resolution and aspect ratio. * * */ -struct QEVERCLOUD_EXPORT RelatedContentImage { +struct QEVERCLOUD_EXPORT RelatedContentImage: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The external URL of the image */ - Optional< QString > url; + Optional url; /** The width of the image, in pixels. */ - Optional< qint32 > width; + Optional width; /** The height of the image, in pixels. */ - Optional< qint32 > height; + Optional height; /** the pixel ratio (usually either 1.0, 1.5 or 2.0) */ - Optional< double > pixelRatio; + Optional pixelRatio; /** the size of the image file, in bytes */ - Optional< qint32 > fileSize; + Optional fileSize; + + virtual void print(QTextStream & strm) const override; bool operator==(const RelatedContentImage & other) const { @@ -4493,6 +5102,12 @@ struct QEVERCLOUD_EXPORT RelatedContentImage { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional url MEMBER url) + Q_PROPERTY(Optional width MEMBER width) + Q_PROPERTY(Optional height MEMBER height) + Q_PROPERTY(Optional pixelRatio MEMBER pixelRatio) + Q_PROPERTY(Optional fileSize MEMBER fileSize) }; /** @@ -4500,78 +5115,89 @@ struct QEVERCLOUD_EXPORT RelatedContentImage { * part of an Evernote account but might still be relevant to the user). * * */ -struct QEVERCLOUD_EXPORT RelatedContent { +struct QEVERCLOUD_EXPORT RelatedContent: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** An identifier that uniquely identifies the content. */ - Optional< QString > contentId; + Optional contentId; /** The main title to show. */ - Optional< QString > title; + Optional title; /** The URL the client can use to retrieve the content. */ - Optional< QString > url; + Optional url; /** An identifier that uniquely identifies the source. */ - Optional< QString > sourceId; + Optional sourceId; /** A URL the client can access to know more about the source. */ - Optional< QString > sourceUrl; + Optional sourceUrl; /** The favicon URL of the source which the content belongs to. */ - Optional< QString > sourceFaviconUrl; + Optional sourceFaviconUrl; /** A human-readable name of the source that provided this content. */ - Optional< QString > sourceName; + Optional sourceName; /** A timestamp telling the user about the recency of the content. */ - Optional< Timestamp > date; + Optional date; /** A teaser text to show to the user; usually the first few sentences of the content, excluding the title. */ - Optional< QString > teaser; + Optional teaser; /** A list of thumbnails the client can show in the snippet. */ - Optional< QList< RelatedContentImage > > thumbnails; + Optional> thumbnails; /** The type of this related content. */ - Optional< RelatedContentType::type > contentType; + Optional contentType; /** An indication of how this content can be accessed. This type influences the semantics of the url parameter. */ - Optional< RelatedContentAccess::type > accessType; + Optional accessType; /** If set, the client should show this URL to the user, instead of the URL that was used to retrieve the content. This URL should be used when opening the content in an external browser window, or when sharing with another person. */ - Optional< QString > visibleUrl; + Optional visibleUrl; /** If set, the client should use this URL for clipping purposes, instead of the URL that was used to retrieve the content. The clipUrl may directly point to an .enex file, for example. */ - Optional< QString > clipUrl; + Optional clipUrl; /** If set, the client may use this Contact for messaging purposes. This will typically only be set for user profiles. */ - Optional< Contact > contact; + Optional contact; /** For News articles only. A list of names of the article authors, if available. */ - Optional< QStringList > authors; + Optional authors; + + virtual void print(QTextStream & strm) const override; bool operator==(const RelatedContent & other) const { @@ -4599,48 +5225,76 @@ struct QEVERCLOUD_EXPORT RelatedContent { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional contentId MEMBER contentId) + Q_PROPERTY(Optional title MEMBER title) + Q_PROPERTY(Optional url MEMBER url) + Q_PROPERTY(Optional sourceId MEMBER sourceId) + Q_PROPERTY(Optional sourceUrl MEMBER sourceUrl) + Q_PROPERTY(Optional sourceFaviconUrl MEMBER sourceFaviconUrl) + Q_PROPERTY(Optional sourceName MEMBER sourceName) + Q_PROPERTY(Optional date MEMBER date) + Q_PROPERTY(Optional teaser MEMBER teaser) + Q_PROPERTY(Optional> thumbnails MEMBER thumbnails) + Q_PROPERTY(Optional contentType MEMBER contentType) + Q_PROPERTY(Optional accessType MEMBER accessType) + Q_PROPERTY(Optional visibleUrl MEMBER visibleUrl) + Q_PROPERTY(Optional clipUrl MEMBER clipUrl) + Q_PROPERTY(Optional contact MEMBER contact) + Q_PROPERTY(Optional authors MEMBER authors) }; /** * A structure describing an invitation to join a business account. * * */ -struct QEVERCLOUD_EXPORT BusinessInvitation { +struct QEVERCLOUD_EXPORT BusinessInvitation: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The ID of the business to which the invitation grants access. */ - Optional< qint32 > businessId; + Optional businessId; /** The email address that was invited to join the business. */ - Optional< QString > email; + Optional email; /** The role to grant the user after the invitation is accepted. */ - Optional< BusinessUserRole::type > role; + Optional role; /** The status of the invitation. */ - Optional< BusinessInvitationStatus::type > status; + Optional status; /** For invitations that were initially requested by a non-admin member of the business, this field specifies the user ID of the requestor. For all other invitations, this field will be unset. */ - Optional< UserID > requesterId; + Optional requesterId; /** If this invitation was created implicitly via a WorkChat, this field will be true. */ - Optional< bool > fromWorkChat; + Optional fromWorkChat; /** The timestamp at which this invitation was created. */ - Optional< Timestamp > created; + Optional created; /** The timestamp at which the most recent reminder was sent. */ - Optional< Timestamp > mostRecentReminder; + Optional mostRecentReminder; + + virtual void print(QTextStream & strm) const override; bool operator==(const BusinessInvitation & other) const { @@ -4660,6 +5314,15 @@ struct QEVERCLOUD_EXPORT BusinessInvitation { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional businessId MEMBER businessId) + Q_PROPERTY(Optional email MEMBER email) + Q_PROPERTY(Optional role MEMBER role) + Q_PROPERTY(Optional status MEMBER status) + Q_PROPERTY(Optional requesterId MEMBER requesterId) + Q_PROPERTY(Optional fromWorkChat MEMBER fromWorkChat) + Q_PROPERTY(Optional created MEMBER created) + Q_PROPERTY(Optional mostRecentReminder MEMBER mostRecentReminder) }; /** @@ -4691,13 +5354,24 @@ struct QEVERCLOUD_EXPORT BusinessInvitation { * to that e-mail address, to join the notebook, we do not know an * Evernote UserID UserIdentity ID to match the e-mail address. */ -struct QEVERCLOUD_EXPORT UserIdentity { +struct QEVERCLOUD_EXPORT UserIdentity: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** NOT DOCUMENTED */ - Optional< UserIdentityType::type > type; + Optional type; /** NOT DOCUMENTED */ - Optional< QString > stringIdentifier; + Optional stringIdentifier; /** NOT DOCUMENTED */ - Optional< qint64 > longIdentifier; + Optional longIdentifier; + + virtual void print(QTextStream & strm) const override; bool operator==(const UserIdentity & other) const { @@ -4712,30 +5386,43 @@ struct QEVERCLOUD_EXPORT UserIdentity { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional type MEMBER type) + Q_PROPERTY(Optional stringIdentifier MEMBER stringIdentifier) + Q_PROPERTY(Optional longIdentifier MEMBER longIdentifier) }; /** * This structure is used to provide publicly-available user information * about a particular account. **/ -struct QEVERCLOUD_EXPORT PublicUserInfo { +struct QEVERCLOUD_EXPORT PublicUserInfo: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The unique numeric user identifier for the user account. */ - UserID userId; + UserID userId = 0; /** The service level of the account. */ - Optional< ServiceLevel::type > serviceLevel; + Optional serviceLevel; /** NOT DOCUMENTED */ - Optional< QString > username; + Optional username; /** This field will contain the full URL that clients should use to make NoteStore requests to the server shard that contains that user's data. I.e. this is the URL that should be used to create the Thrift HTTP client transport to send messages to the NoteStore service for the account. */ - Optional< QString > noteStoreUrl; + Optional noteStoreUrl; /** This field will contain the initial part of the URLs that should be used to make requests to Evernote's thin client "web API", which provide @@ -4745,7 +5432,9 @@ struct QEVERCLOUD_EXPORT PublicUserInfo { end of this string to construct the full URL, as documented on our developer web site. */ - Optional< QString > webApiUrlPrefix; + Optional webApiUrlPrefix; + + virtual void print(QTextStream & strm) const override; bool operator==(const PublicUserInfo & other) const { @@ -4762,18 +5451,33 @@ struct QEVERCLOUD_EXPORT PublicUserInfo { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(UserID userId MEMBER userId) + Q_PROPERTY(Optional serviceLevel MEMBER serviceLevel) + Q_PROPERTY(Optional username MEMBER username) + Q_PROPERTY(Optional noteStoreUrl MEMBER noteStoreUrl) + Q_PROPERTY(Optional webApiUrlPrefix MEMBER webApiUrlPrefix) }; /** * */ -struct QEVERCLOUD_EXPORT UserUrls { +struct QEVERCLOUD_EXPORT UserUrls: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** This field will contain the full URL that clients should use to make NoteStore requests to the server shard that contains that user's data. I.e. this is the URL that should be used to create the Thrift HTTP client transport to send messages to the NoteStore service for the account. */ - Optional< QString > noteStoreUrl; + Optional noteStoreUrl; /** This field will contain the initial part of the URLs that should be used to make requests to Evernote's thin client "web API", which provide @@ -4783,33 +5487,35 @@ struct QEVERCLOUD_EXPORT UserUrls { end of this string to construct the full URL, as documented on our developer web site. */ - Optional< QString > webApiUrlPrefix; + Optional webApiUrlPrefix; /** This field will contain the full URL that clients should use to make UserStore requests after successfully authenticating. I.e. this is the URL that should be used to create the Thrift HTTP client transport to send messages to the UserStore service for this account. */ - Optional< QString > userStoreUrl; + Optional userStoreUrl; /** This field will contain the full URL that clients should use to make Utility requests to the server shard that contains that user's data. I.e. this is the URL that should be used to create the Thrift HTTP client transport to send messages to the Utility service for the account. */ - Optional< QString > utilityUrl; + Optional utilityUrl; /** This field will contain the full URL that clients should use to make MessageStore requests to the server. I.e. this is the URL that should be used to create the Thrift HTTP client transport to send messages to the MessageStore service for the account. */ - Optional< QString > messageStoreUrl; + Optional messageStoreUrl; /** This field will contain the full URL that clients should use when opening a - persistent web socket to recieve notification of events for the authenticated user. + persistent web socket to receive notification of events for the authenticated user. */ - Optional< QString > userWebSocketUrl; + Optional userWebSocketUrl; + + virtual void print(QTextStream & strm) const override; bool operator==(const UserUrls & other) const { @@ -4827,18 +5533,34 @@ struct QEVERCLOUD_EXPORT UserUrls { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional noteStoreUrl MEMBER noteStoreUrl) + Q_PROPERTY(Optional webApiUrlPrefix MEMBER webApiUrlPrefix) + Q_PROPERTY(Optional userStoreUrl MEMBER userStoreUrl) + Q_PROPERTY(Optional utilityUrl MEMBER utilityUrl) + Q_PROPERTY(Optional messageStoreUrl MEMBER messageStoreUrl) + Q_PROPERTY(Optional userWebSocketUrl MEMBER userWebSocketUrl) }; /** * When an authentication (or re-authentication) is performed, this structure * provides the result to the client. **/ -struct QEVERCLOUD_EXPORT AuthenticationResult { +struct QEVERCLOUD_EXPORT AuthenticationResult: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The server-side date and time when this result was generated. */ - Timestamp currentTime; + Timestamp currentTime = 0; /** Holds an opaque, ASCII-encoded token that can be used by the client to perform actions on a NoteStore. @@ -4850,27 +5572,27 @@ struct QEVERCLOUD_EXPORT AuthenticationResult { This time can be compared to "currentTime" to produce an expiration time that can be reconciled with the client's local clock. */ - Timestamp expiration; + Timestamp expiration = 0; /** Holds the information about the account which was authenticated if this was a full authentication. May be absent if this particular authentication did not require user information. */ - Optional< User > user; + Optional user; /** If this authentication result was achieved without full permissions to access the full User structure, this field may be set to give back a more limited public set of data. */ - Optional< PublicUserInfo > publicUserInfo; + Optional publicUserInfo; /** DEPRECATED - Client applications should use urls.noteStoreUrl. */ - Optional< QString > noteStoreUrl; + Optional noteStoreUrl; /** DEPRECATED - Client applications should use urls.webApiUrlPrefix. */ - Optional< QString > webApiUrlPrefix; + Optional webApiUrlPrefix; /** If set to true, this field indicates that the user has enabled two-factor authentication and must enter their second factor in order to complete @@ -4878,7 +5600,7 @@ struct QEVERCLOUD_EXPORT AuthenticationResult { a short-lived authentication token that may only be used to make a subsequent call to completeTwoFactorAuthentication. */ - Optional< bool > secondFactorRequired; + Optional secondFactorRequired; /** When secondFactorRequired is set to true, this field may contain a string describing the second factor delivery method that the user has configured. @@ -4886,12 +5608,14 @@ struct QEVERCLOUD_EXPORT AuthenticationResult { "(xxx) xxx-x095". This string can be displayed to the user to remind them how to obtain the required second factor. */ - Optional< QString > secondFactorDeliveryHint; + Optional secondFactorDeliveryHint; /** This structure will contain all of the URLs that clients need to make requests to the Evernote service on behalf of the authenticated User. */ - Optional< UserUrls > urls; + Optional urls; + + virtual void print(QTextStream & strm) const override; bool operator==(const AuthenticationResult & other) const { @@ -4913,12 +5637,32 @@ struct QEVERCLOUD_EXPORT AuthenticationResult { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Timestamp currentTime MEMBER currentTime) + Q_PROPERTY(QString authenticationToken MEMBER authenticationToken) + Q_PROPERTY(Timestamp expiration MEMBER expiration) + Q_PROPERTY(Optional user MEMBER user) + Q_PROPERTY(Optional publicUserInfo MEMBER publicUserInfo) + Q_PROPERTY(Optional noteStoreUrl MEMBER noteStoreUrl) + Q_PROPERTY(Optional webApiUrlPrefix MEMBER webApiUrlPrefix) + Q_PROPERTY(Optional secondFactorRequired MEMBER secondFactorRequired) + Q_PROPERTY(Optional secondFactorDeliveryHint MEMBER secondFactorDeliveryHint) + Q_PROPERTY(Optional urls MEMBER urls) }; /** * This structure describes a collection of bootstrap settings. **/ -struct QEVERCLOUD_EXPORT BootstrapSettings { +struct QEVERCLOUD_EXPORT BootstrapSettings: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The hostname and optional port for composing Evernote web service URLs. This URL can be used to access the UserStore and related services, @@ -4948,40 +5692,42 @@ struct QEVERCLOUD_EXPORT BootstrapSettings { /** Whether the client application should enable sharing of notes on Facebook. */ - Optional< bool > enableFacebookSharing; + Optional enableFacebookSharing; /** Whether the client application should enable gift subscriptions. */ - Optional< bool > enableGiftSubscriptions; + Optional enableGiftSubscriptions; /** Whether the client application should enable in-client creation of support tickets. */ - Optional< bool > enableSupportTickets; + Optional enableSupportTickets; /** Whether the client application should enable shared notebooks. */ - Optional< bool > enableSharedNotebooks; + Optional enableSharedNotebooks; /** Whether the client application should enable single note sharing. */ - Optional< bool > enableSingleNoteSharing; + Optional enableSingleNoteSharing; /** Whether the client application should enable sponsored accounts. */ - Optional< bool > enableSponsoredAccounts; + Optional enableSponsoredAccounts; /** Whether the client application should enable sharing of notes on Twitter. */ - Optional< bool > enableTwitterSharing; + Optional enableTwitterSharing; /** NOT DOCUMENTED */ - Optional< bool > enableLinkedInSharing; + Optional enableLinkedInSharing; /** NOT DOCUMENTED */ - Optional< bool > enablePublicNotebooks; + Optional enablePublicNotebooks; /** Whether the client application should enable authentication with Google, for example to allow integration with a user's Gmail contacts. */ - Optional< bool > enableGoogle; + Optional enableGoogle; + + virtual void print(QTextStream & strm) const override; bool operator==(const BootstrapSettings & other) const { @@ -5007,12 +5753,36 @@ struct QEVERCLOUD_EXPORT BootstrapSettings { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(QString serviceHost MEMBER serviceHost) + Q_PROPERTY(QString marketingUrl MEMBER marketingUrl) + Q_PROPERTY(QString supportUrl MEMBER supportUrl) + Q_PROPERTY(QString accountEmailDomain MEMBER accountEmailDomain) + Q_PROPERTY(Optional enableFacebookSharing MEMBER enableFacebookSharing) + Q_PROPERTY(Optional enableGiftSubscriptions MEMBER enableGiftSubscriptions) + Q_PROPERTY(Optional enableSupportTickets MEMBER enableSupportTickets) + Q_PROPERTY(Optional enableSharedNotebooks MEMBER enableSharedNotebooks) + Q_PROPERTY(Optional enableSingleNoteSharing MEMBER enableSingleNoteSharing) + Q_PROPERTY(Optional enableSponsoredAccounts MEMBER enableSponsoredAccounts) + Q_PROPERTY(Optional enableTwitterSharing MEMBER enableTwitterSharing) + Q_PROPERTY(Optional enableLinkedInSharing MEMBER enableLinkedInSharing) + Q_PROPERTY(Optional enablePublicNotebooks MEMBER enablePublicNotebooks) + Q_PROPERTY(Optional enableGoogle MEMBER enableGoogle) }; /** * This structure describes a collection of bootstrap settings. **/ -struct QEVERCLOUD_EXPORT BootstrapProfile { +struct QEVERCLOUD_EXPORT BootstrapProfile: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The unique name of the profile, which is guaranteed to remain consistent across calls to getBootstrapInfo. @@ -5023,6 +5793,8 @@ struct QEVERCLOUD_EXPORT BootstrapProfile { */ BootstrapSettings settings; + virtual void print(QTextStream & strm) const override; + bool operator==(const BootstrapProfile & other) const { return (name == other.name) @@ -5035,17 +5807,31 @@ struct QEVERCLOUD_EXPORT BootstrapProfile { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(QString name MEMBER name) + Q_PROPERTY(BootstrapSettings settings MEMBER settings) }; /** * This structure describes a collection of bootstrap profiles. **/ -struct QEVERCLOUD_EXPORT BootstrapInfo { +struct QEVERCLOUD_EXPORT BootstrapInfo: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** List of one or more bootstrap profiles, in descending preference order. */ - QList< BootstrapProfile > profiles; + QList profiles; + + virtual void print(QTextStream & strm) const override; bool operator==(const BootstrapInfo & other) const { @@ -5058,6 +5844,8 @@ struct QEVERCLOUD_EXPORT BootstrapInfo { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(QList profiles MEMBER profiles) }; /** @@ -5078,18 +5866,21 @@ struct QEVERCLOUD_EXPORT BootstrapInfo { * indicate which parameter. For some errors (USER_NOT_ASSOCIATED, USER_NOT_REGISTERED, * SSO_AUTHENTICATION_REQUIRED), this is the user's email. */ -class QEVERCLOUD_EXPORT EDAMUserException: public EvernoteException +class QEVERCLOUD_EXPORT EDAMUserException: public EvernoteException, public Printable { + Q_GADGET public: - EDAMErrorCode::type errorCode; - Optional< QString > parameter; + EDAMErrorCode errorCode; + Optional parameter; EDAMUserException(); - virtual ~EDAMUserException() throw() Q_DECL_OVERRIDE; + virtual ~EDAMUserException() noexcept override; EDAMUserException(const EDAMUserException & other); - const char * what() const throw() Q_DECL_OVERRIDE; - virtual QSharedPointer exceptionData() const Q_DECL_OVERRIDE; + const char * what() const noexcept override; + virtual EverCloudExceptionDataPtr exceptionData() const override; + + virtual void print(QTextStream & strm) const override; bool operator==(const EDAMUserException & other) const { @@ -5103,6 +5894,8 @@ class QEVERCLOUD_EXPORT EDAMUserException: public EvernoteException return !(*this == other); } + Q_PROPERTY(EDAMErrorCode errorCode MEMBER errorCode) + Q_PROPERTY(Optional parameter MEMBER parameter) }; /** @@ -5119,19 +5912,22 @@ class QEVERCLOUD_EXPORT EDAMUserException: public EvernoteException * API requests for the user until at least this many seconds have passed. Present only * when errorCode is RATE_LIMIT_REACHED, */ -class QEVERCLOUD_EXPORT EDAMSystemException: public EvernoteException +class QEVERCLOUD_EXPORT EDAMSystemException: public EvernoteException, public Printable { + Q_GADGET public: - EDAMErrorCode::type errorCode; - Optional< QString > message; - Optional< qint32 > rateLimitDuration; + EDAMErrorCode errorCode; + Optional message; + Optional rateLimitDuration; EDAMSystemException(); - virtual ~EDAMSystemException() throw() Q_DECL_OVERRIDE; + virtual ~EDAMSystemException() noexcept override; EDAMSystemException(const EDAMSystemException & other); - const char * what() const throw() Q_DECL_OVERRIDE; - virtual QSharedPointer exceptionData() const Q_DECL_OVERRIDE; + const char * what() const noexcept override; + virtual EverCloudExceptionDataPtr exceptionData() const override; + + virtual void print(QTextStream & strm) const override; bool operator==(const EDAMSystemException & other) const { @@ -5146,6 +5942,9 @@ class QEVERCLOUD_EXPORT EDAMSystemException: public EvernoteException return !(*this == other); } + Q_PROPERTY(EDAMErrorCode errorCode MEMBER errorCode) + Q_PROPERTY(Optional message MEMBER message) + Q_PROPERTY(Optional rateLimitDuration MEMBER rateLimitDuration) }; /** @@ -5161,18 +5960,21 @@ class QEVERCLOUD_EXPORT EDAMSystemException: public EvernoteException * key: The value passed from the client in the identifier, which was not * found. For example, the GUID that was not found. */ -class QEVERCLOUD_EXPORT EDAMNotFoundException: public EvernoteException +class QEVERCLOUD_EXPORT EDAMNotFoundException: public EvernoteException, public Printable { + Q_GADGET public: - Optional< QString > identifier; - Optional< QString > key; + Optional identifier; + Optional key; EDAMNotFoundException(); - virtual ~EDAMNotFoundException() throw() Q_DECL_OVERRIDE; + virtual ~EDAMNotFoundException() noexcept override; EDAMNotFoundException(const EDAMNotFoundException & other); - const char * what() const throw() Q_DECL_OVERRIDE; - virtual QSharedPointer exceptionData() const Q_DECL_OVERRIDE; + const char * what() const noexcept override; + virtual EverCloudExceptionDataPtr exceptionData() const override; + + virtual void print(QTextStream & strm) const override; bool operator==(const EDAMNotFoundException & other) const { @@ -5186,6 +5988,8 @@ class QEVERCLOUD_EXPORT EDAMNotFoundException: public EvernoteException return !(*this == other); } + Q_PROPERTY(Optional identifier MEMBER identifier) + Q_PROPERTY(Optional key MEMBER key) }; /** @@ -5210,19 +6014,22 @@ class QEVERCLOUD_EXPORT EDAMNotFoundException: public EvernoteException * matching, in order, the list returned in the contacts field. * */ -class QEVERCLOUD_EXPORT EDAMInvalidContactsException: public EvernoteException +class QEVERCLOUD_EXPORT EDAMInvalidContactsException: public EvernoteException, public Printable { + Q_GADGET public: - QList< Contact > contacts; - Optional< QString > parameter; - Optional< QList< EDAMInvalidContactReason::type > > reasons; + QList contacts; + Optional parameter; + Optional> reasons; EDAMInvalidContactsException(); - virtual ~EDAMInvalidContactsException() throw() Q_DECL_OVERRIDE; + virtual ~EDAMInvalidContactsException() noexcept override; EDAMInvalidContactsException(const EDAMInvalidContactsException & other); - const char * what() const throw() Q_DECL_OVERRIDE; - virtual QSharedPointer exceptionData() const Q_DECL_OVERRIDE; + const char * what() const noexcept override; + virtual EverCloudExceptionDataPtr exceptionData() const override; + + virtual void print(QTextStream & strm) const override; bool operator==(const EDAMInvalidContactsException & other) const { @@ -5237,6 +6044,9 @@ class QEVERCLOUD_EXPORT EDAMInvalidContactsException: public EvernoteException return !(*this == other); } + Q_PROPERTY(QList contacts MEMBER contacts) + Q_PROPERTY(Optional parameter MEMBER parameter) + Q_PROPERTY(Optional> reasons MEMBER reasons) }; /** @@ -5250,17 +6060,26 @@ class QEVERCLOUD_EXPORT EDAMInvalidContactsException: public EvernoteException * Sequence Numbers (USNs). * **/ -struct QEVERCLOUD_EXPORT SyncChunk { +struct QEVERCLOUD_EXPORT SyncChunk: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The server's current date and time. */ - Timestamp currentTime; + Timestamp currentTime = 0; /** The highest USN for any of the data objects represented in this sync chunk. If there are no objects in the chunk, this will not be set. */ - Optional< qint32 > chunkHighUSN; + Optional chunkHighUSN; /** The total number of updates that have been performed in the service for this account. This is equal to the highest USN within the @@ -5268,7 +6087,7 @@ struct QEVERCLOUD_EXPORT SyncChunk { and chunkHighUSN are identical, that means that this is the last chunk in the account ... there is no more recent information. */ - qint32 updateCount; + qint32 updateCount = 0; /** If present, this is a list of non-expunged notes that have a USN in this chunk. This will include notes that are "deleted" @@ -5276,61 +6095,63 @@ struct QEVERCLOUD_EXPORT SyncChunk { of tags and resources, but the note content, resource content, resource recognition data and resource alternate data will not be supplied. */ - Optional< QList< Note > > notes; + Optional> notes; /** If present, this is a list of non-expunged notebooks that have a USN in this chunk. */ - Optional< QList< Notebook > > notebooks; + Optional> notebooks; /** If present, this is a list of the non-expunged tags that have a USN in this chunk. */ - Optional< QList< Tag > > tags; + Optional> tags; /** If present, this is a list of non-expunged searches that have a USN in this chunk. */ - Optional< QList< SavedSearch > > searches; + Optional> searches; /** If present, this is a list of the non-expunged resources that have a USN in this chunk. This will include the metadata for each resource, but not its binary contents or recognition data, which must be retrieved separately. */ - Optional< QList< Resource > > resources; + Optional> resources; /** If present, the GUIDs of all of the notes that were permanently expunged in this chunk. */ - Optional< QList< Guid > > expungedNotes; + Optional> expungedNotes; /** If present, the GUIDs of all of the notebooks that were permanently expunged in this chunk. When a notebook is expunged, this implies that all of its child notes (and their resources) were also expunged. */ - Optional< QList< Guid > > expungedNotebooks; + Optional> expungedNotebooks; /** If present, the GUIDs of all of the tags that were permanently expunged in this chunk. */ - Optional< QList< Guid > > expungedTags; + Optional> expungedTags; /** If present, the GUIDs of all of the saved searches that were permanently expunged in this chunk. */ - Optional< QList< Guid > > expungedSearches; + Optional> expungedSearches; /** If present, this is a list of non-expunged LinkedNotebooks that have a USN in this chunk. */ - Optional< QList< LinkedNotebook > > linkedNotebooks; + Optional> linkedNotebooks; /** If present, the GUIDs of all of the LinkedNotebooks that were permanently expunged in this chunk. */ - Optional< QList< Guid > > expungedLinkedNotebooks; + Optional> expungedLinkedNotebooks; + + virtual void print(QTextStream & strm) const override; bool operator==(const SyncChunk & other) const { @@ -5356,43 +6177,67 @@ struct QEVERCLOUD_EXPORT SyncChunk { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Timestamp currentTime MEMBER currentTime) + Q_PROPERTY(Optional chunkHighUSN MEMBER chunkHighUSN) + Q_PROPERTY(qint32 updateCount MEMBER updateCount) + Q_PROPERTY(Optional> notes MEMBER notes) + Q_PROPERTY(Optional> notebooks MEMBER notebooks) + Q_PROPERTY(Optional> tags MEMBER tags) + Q_PROPERTY(Optional> searches MEMBER searches) + Q_PROPERTY(Optional> resources MEMBER resources) + Q_PROPERTY(Optional> expungedNotes MEMBER expungedNotes) + Q_PROPERTY(Optional> expungedNotebooks MEMBER expungedNotebooks) + Q_PROPERTY(Optional> expungedTags MEMBER expungedTags) + Q_PROPERTY(Optional> expungedSearches MEMBER expungedSearches) + Q_PROPERTY(Optional> linkedNotebooks MEMBER linkedNotebooks) + Q_PROPERTY(Optional> expungedLinkedNotebooks MEMBER expungedLinkedNotebooks) }; /** * A small structure for returning a list of notes out of a larger set. * **/ -struct QEVERCLOUD_EXPORT NoteList { +struct QEVERCLOUD_EXPORT NoteList: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The starting index within the overall set of notes. This is also the number of notes that are "before" this list in the set. */ - qint32 startIndex; + qint32 startIndex = 0; /** The number of notes in the larger set. This can be used to calculate how many notes are "after" this note in the set. (I.e. remaining = totalNotes - (startIndex + notes.length) ) */ - qint32 totalNotes; + qint32 totalNotes = 0; /** The list of notes from this range. The Notes will include all metadata (attributes, resources, etc.), but will not include the ENML content of the note or the binary contents of any resources. */ - QList< Note > notes; + QList notes; /** If the NoteList was produced using a text based search query that included words that are not indexed or searched by the service, this will include a list of those ignored words. */ - Optional< QStringList > stoppedWords; + Optional stoppedWords; /** If the NoteList was produced using a text based search query that included viable search words or quoted expressions, this will include a list of those words. Any stopped words will not be included in this list. */ - Optional< QStringList > searchedWords; + Optional searchedWords; /** Indicates the total number of transactions that have been committed within the account. This reflects (for example) the @@ -5401,16 +6246,18 @@ struct QEVERCLOUD_EXPORT NoteList { This number is the "high water mark" for Update Sequence Numbers (USN) within the account. */ - Optional< qint32 > updateCount; + Optional updateCount; /** Specifies the correlating information about the current search session, in byte array. */ - Optional< QByteArray > searchContextBytes; + Optional searchContextBytes; /** Depends on the value of context in NoteFilter, this field may contain debug information if the service decides to do so. */ - Optional< QString > debugInfo; + Optional debugInfo; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteList & other) const { @@ -5430,6 +6277,15 @@ struct QEVERCLOUD_EXPORT NoteList { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(qint32 startIndex MEMBER startIndex) + Q_PROPERTY(qint32 totalNotes MEMBER totalNotes) + Q_PROPERTY(QList notes MEMBER notes) + Q_PROPERTY(Optional stoppedWords MEMBER stoppedWords) + Q_PROPERTY(Optional searchedWords MEMBER searchedWords) + Q_PROPERTY(Optional updateCount MEMBER updateCount) + Q_PROPERTY(Optional searchContextBytes MEMBER searchContextBytes) + Q_PROPERTY(Optional debugInfo MEMBER debugInfo) }; /** @@ -5442,39 +6298,50 @@ struct QEVERCLOUD_EXPORT NoteList { * the Note structure, with the exception of: * * */ -struct QEVERCLOUD_EXPORT NoteMetadata { +struct QEVERCLOUD_EXPORT NoteMetadata: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** NOT DOCUMENTED */ Guid guid; /** NOT DOCUMENTED */ - Optional< QString > title; + Optional title; /** NOT DOCUMENTED */ - Optional< qint32 > contentLength; + Optional contentLength; /** NOT DOCUMENTED */ - Optional< Timestamp > created; + Optional created; /** NOT DOCUMENTED */ - Optional< Timestamp > updated; + Optional updated; /** NOT DOCUMENTED */ - Optional< Timestamp > deleted; + Optional deleted; /** NOT DOCUMENTED */ - Optional< qint32 > updateSequenceNum; + Optional updateSequenceNum; /** NOT DOCUMENTED */ - Optional< QString > notebookGuid; + Optional notebookGuid; /** NOT DOCUMENTED */ - Optional< QList< Guid > > tagGuids; + Optional> tagGuids; /** NOT DOCUMENTED */ - Optional< NoteAttributes > attributes; + Optional attributes; /** If set, then this will contain the MIME type of the largest Resource (in bytes) within the Note. This may be useful, for example, to choose an appropriate icon or thumbnail to represent the Note. */ - Optional< QString > largestResourceMime; + Optional largestResourceMime; /** If set, this will contain the size of the largest Resource file, in bytes, within the Note. This may be useful, for example, to decide whether to ask the server for a thumbnail to represent the Note. */ - Optional< qint32 > largestResourceSize; + Optional largestResourceSize; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteMetadata & other) const { @@ -5498,6 +6365,19 @@ struct QEVERCLOUD_EXPORT NoteMetadata { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Guid guid MEMBER guid) + Q_PROPERTY(Optional title MEMBER title) + Q_PROPERTY(Optional contentLength MEMBER contentLength) + Q_PROPERTY(Optional created MEMBER created) + Q_PROPERTY(Optional updated MEMBER updated) + Q_PROPERTY(Optional deleted MEMBER deleted) + Q_PROPERTY(Optional updateSequenceNum MEMBER updateSequenceNum) + Q_PROPERTY(Optional notebookGuid MEMBER notebookGuid) + Q_PROPERTY(Optional> tagGuids MEMBER tagGuids) + Q_PROPERTY(Optional attributes MEMBER attributes) + Q_PROPERTY(Optional largestResourceMime MEMBER largestResourceMime) + Q_PROPERTY(Optional largestResourceSize MEMBER largestResourceSize) }; /** @@ -5506,18 +6386,27 @@ struct QEVERCLOUD_EXPORT NoteMetadata { * match a specified NoteFilter in a search. * **/ -struct QEVERCLOUD_EXPORT NotesMetadataList { +struct QEVERCLOUD_EXPORT NotesMetadataList: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The starting index within the overall set of notes. This is also the number of notes that are "before" this list in the set. */ - qint32 startIndex; + qint32 startIndex = 0; /** The number of notes in the larger set. This can be used to calculate how many notes are "after" this note in the set. (I.e. remaining = totalNotes - (startIndex + notes.length) ) */ - qint32 totalNotes; + qint32 totalNotes = 0; /** The list of metadata for Notes in this range. The set of optional fields that are set in each metadata structure will depend on the @@ -5525,20 +6414,20 @@ struct QEVERCLOUD_EXPORT NotesMetadataList { performed. Only the 'guid' field will be guaranteed to be set in each Note. */ - QList< NoteMetadata > notes; + QList notes; /** If the NoteList was produced using a text based search query that included words that are not indexed or searched by the service, this will include a list of those ignored words. */ - Optional< QStringList > stoppedWords; + Optional stoppedWords; /** If the NoteList was produced using a text based search query that included viable search words or quoted expressions, this will include a list of those words. Any stopped words will not be included in this list. */ - Optional< QStringList > searchedWords; + Optional searchedWords; /** Indicates the total number of transactions that have been committed within the account. This reflects (for example) the @@ -5547,16 +6436,18 @@ struct QEVERCLOUD_EXPORT NotesMetadataList { This number is the "high water mark" for Update Sequence Numbers (USN) within the account. */ - Optional< qint32 > updateCount; + Optional updateCount; /** Specifies the correlating information about the current search session, in byte array. */ - Optional< QByteArray > searchContextBytes; + Optional searchContextBytes; /** Depends on the value of context in NoteFilter, this field may contain debug information if the service decides to do so. */ - Optional< QString > debugInfo; + Optional debugInfo; + + virtual void print(QTextStream & strm) const override; bool operator==(const NotesMetadataList & other) const { @@ -5576,6 +6467,15 @@ struct QEVERCLOUD_EXPORT NotesMetadataList { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(qint32 startIndex MEMBER startIndex) + Q_PROPERTY(qint32 totalNotes MEMBER totalNotes) + Q_PROPERTY(QList notes MEMBER notes) + Q_PROPERTY(Optional stoppedWords MEMBER stoppedWords) + Q_PROPERTY(Optional searchedWords MEMBER searchedWords) + Q_PROPERTY(Optional updateCount MEMBER updateCount) + Q_PROPERTY(Optional searchContextBytes MEMBER searchContextBytes) + Q_PROPERTY(Optional debugInfo MEMBER debugInfo) }; /** @@ -5583,43 +6483,54 @@ struct QEVERCLOUD_EXPORT NotesMetadataList { * the caller to specify the note to send, the recipient addresses, etc. * * */ -struct QEVERCLOUD_EXPORT NoteEmailParameters { +struct QEVERCLOUD_EXPORT NoteEmailParameters: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** If set, this must be the GUID of a note within the user's account that should be retrieved from the service and sent as email. If not set, the 'note' field must be provided instead. */ - Optional< QString > guid; + Optional guid; /** If the 'guid' field is not set, this field must be provided, including the full contents of the note note (and all of its Resources) to send. This can be used for a Note that as not been created in the service, for example by a local client with local notes. */ - Optional< Note > note; + Optional note; /** If provided, this should contain a list of the SMTP email addresses that should be included in the "To:" line of the email. Callers must specify at least one "to" or "cc" email address. */ - Optional< QStringList > toAddresses; + Optional toAddresses; /** If provided, this should contain a list of the SMTP email addresses that should be included in the "Cc:" line of the email. Callers must specify at least one "to" or "cc" email address. */ - Optional< QStringList > ccAddresses; + Optional ccAddresses; /** If provided, this should contain the subject line of the email that will be sent. If not provided, the title of the note will be used as the subject of the email. */ - Optional< QString > subject; + Optional subject; /** If provided, this is additional personal text that should be included into the email as a message from the owner to the recipient(s). */ - Optional< QString > message; + Optional message; + + virtual void print(QTextStream & strm) const override; bool operator==(const NoteEmailParameters & other) const { @@ -5637,6 +6548,13 @@ struct QEVERCLOUD_EXPORT NoteEmailParameters { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional guid MEMBER guid) + Q_PROPERTY(Optional note MEMBER note) + Q_PROPERTY(Optional toAddresses MEMBER toAddresses) + Q_PROPERTY(Optional ccAddresses MEMBER ccAddresses) + Q_PROPERTY(Optional subject MEMBER subject) + Q_PROPERTY(Optional message MEMBER message) }; /** @@ -5647,22 +6565,31 @@ struct QEVERCLOUD_EXPORT NoteEmailParameters { * in cases where the relevance is estimated to be low. * * */ -struct QEVERCLOUD_EXPORT RelatedResult { +struct QEVERCLOUD_EXPORT RelatedResult: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** If notes have been requested to be included, this will be the list of notes. */ - Optional< QList< Note > > notes; + Optional> notes; /** If notebooks have been requested to be included, this will be the list of notebooks. */ - Optional< QList< Notebook > > notebooks; + Optional> notebooks; /** If tags have been requested to be included, this will be the list of tags. */ - Optional< QList< Tag > > tags; + Optional> tags; /** If includeContainingNotebooks is set to true in the RelatedResultSpec, return the list of notebooks to @@ -5670,19 +6597,19 @@ struct QEVERCLOUD_EXPORT RelatedResult { list will occur once per notebook GUID and are represented as NotebookDescriptor objects. */ - Optional< QList< NotebookDescriptor > > containingNotebooks; + Optional> containingNotebooks; /** NOT DOCUMENTED */ - Optional< QString > debugInfo; + Optional debugInfo; /** If experts have been requested to be included, this will return a list of users within your business who have knowledge about the specified query. */ - Optional< QList< UserProfile > > experts; + Optional> experts; /** If related content has been requested to be included, this will be the list of related content snippets. */ - Optional< QList< RelatedContent > > relatedContent; + Optional> relatedContent; /** If set and non-empty, this cache key may be used in subsequent "NoteStore.findRelated" calls (via "RelatedQuery") to re-use previous @@ -5716,7 +6643,7 @@ struct QEVERCLOUD_EXPORT RelatedResult { "RelatedResult.relatedContent". List fields that are set, but empty indicate that no results could be found; the cache should be updated correspondingly. */ - Optional< QString > cacheKey; + Optional cacheKey; /** If set, clients should reuse this response for any situations where the same input parameters are applicable for up to this many seconds after receiving this result. @@ -5725,7 +6652,9 @@ struct QEVERCLOUD_EXPORT RelatedResult { but it should supply the stored cacheKey to the service when checking for an update. */ - Optional< qint32 > cacheExpires; + Optional cacheExpires; + + virtual void print(QTextStream & strm) const override; bool operator==(const RelatedResult & other) const { @@ -5746,6 +6675,16 @@ struct QEVERCLOUD_EXPORT RelatedResult { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional> notes MEMBER notes) + Q_PROPERTY(Optional> notebooks MEMBER notebooks) + Q_PROPERTY(Optional> tags MEMBER tags) + Q_PROPERTY(Optional> containingNotebooks MEMBER containingNotebooks) + Q_PROPERTY(Optional debugInfo MEMBER debugInfo) + Q_PROPERTY(Optional> experts MEMBER experts) + Q_PROPERTY(Optional> relatedContent MEMBER relatedContent) + Q_PROPERTY(Optional cacheKey MEMBER cacheKey) + Q_PROPERTY(Optional cacheExpires MEMBER cacheExpires) }; /** @@ -5753,7 +6692,16 @@ struct QEVERCLOUD_EXPORT RelatedResult { * based on the current value of the note's update sequence number on the service. * * */ -struct QEVERCLOUD_EXPORT UpdateNoteIfUsnMatchesResult { +struct QEVERCLOUD_EXPORT UpdateNoteIfUsnMatchesResult: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** Either the current state of the note if updated is false or the result of updating the note as would be done via the updateNote method. @@ -5762,11 +6710,13 @@ struct QEVERCLOUD_EXPORT UpdateNoteIfUsnMatchesResult { You can check for updates to these large objects by checking the Data.bodyHash values and downloading accordingly. */ - Optional< Note > note; + Optional note; /** Whether or not the note was updated by the operation. */ - Optional< bool > updated; + Optional updated; + + virtual void print(QTextStream & strm) const override; bool operator==(const UpdateNoteIfUsnMatchesResult & other) const { @@ -5780,6 +6730,9 @@ struct QEVERCLOUD_EXPORT UpdateNoteIfUsnMatchesResult { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional note MEMBER note) + Q_PROPERTY(Optional updated MEMBER updated) }; /** @@ -5787,12 +6740,21 @@ struct QEVERCLOUD_EXPORT UpdateNoteIfUsnMatchesResult { * credentials to become a member of a notebook. * * */ -struct QEVERCLOUD_EXPORT InvitationShareRelationship { +struct QEVERCLOUD_EXPORT InvitationShareRelationship: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The string that clients should show to users to represent this invitation. */ - Optional< QString > displayName; + Optional displayName; /** Identifies the recipient of the invitation. The user identity type can be either EMAIL, EVERNOTE or IDENTITYID. If the @@ -5801,7 +6763,7 @@ struct QEVERCLOUD_EXPORT InvitationShareRelationship { EVERNOTE or IDENTITYID, depending on whether we can map the identity to an Evernote user at the time of creation. */ - Optional< UserIdentity > recipientUserIdentity; + Optional recipientUserIdentity; /** The privilege level at which the member will be joined, if it turns out that the member is not already joined at a higher level. @@ -5809,13 +6771,15 @@ struct QEVERCLOUD_EXPORT InvitationShareRelationship { Evernote User ID, and so we won't know until the invitation is redeemed whether or not the recipient already has privilege. */ - Optional< ShareRelationshipPrivilegeLevel::type > privilege; + Optional privilege; /** The user id of the user who most recently shared this notebook to this identity. This field is used by the service to convey information to the user, so clients should treat it as read-only. */ - Optional< UserID > sharerUserId; + Optional sharerUserId; + + virtual void print(QTextStream & strm) const override; bool operator==(const InvitationShareRelationship & other) const { @@ -5831,6 +6795,11 @@ struct QEVERCLOUD_EXPORT InvitationShareRelationship { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional displayName MEMBER displayName) + Q_PROPERTY(Optional recipientUserIdentity MEMBER recipientUserIdentity) + Q_PROPERTY(Optional privilege MEMBER privilege) + Q_PROPERTY(Optional sharerUserId MEMBER sharerUserId) }; /** @@ -5840,18 +6809,27 @@ struct QEVERCLOUD_EXPORT InvitationShareRelationship { * invitations that can be used to become members. * * */ -struct QEVERCLOUD_EXPORT ShareRelationships { +struct QEVERCLOUD_EXPORT ShareRelationships: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** A list of open invitations that can be redeemed into memberships to the notebook. */ - Optional< QList< InvitationShareRelationship > > invitations; + Optional> invitations; /** A list of memberships of the notebook. A member is identified by their Evernote UserID and has rights to access the notebook. */ - Optional< QList< MemberShareRelationship > > memberships; + Optional> memberships; /** The restrictions on what privileges may be granted to invitees to this notebook. These restrictions may be specific to the calling @@ -5860,7 +6838,9 @@ struct QEVERCLOUD_EXPORT ShareRelationships { recipient of the invitation has been identified by the service, such as by a business auto-join, the actual assigned privilege may change. */ - Optional< ShareRelationshipRestrictions > invitationRestrictions; + Optional invitationRestrictions; + + virtual void print(QTextStream & strm) const override; bool operator==(const ShareRelationships & other) const { @@ -5875,6 +6855,10 @@ struct QEVERCLOUD_EXPORT ShareRelationships { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional> invitations MEMBER invitations) + Q_PROPERTY(Optional> memberships MEMBER memberships) + Q_PROPERTY(Optional invitationRestrictions MEMBER invitationRestrictions) }; /** @@ -5882,16 +6866,25 @@ struct QEVERCLOUD_EXPORT ShareRelationships { * shares for a given notebook via the manageNotebookShares method. * * */ -struct QEVERCLOUD_EXPORT ManageNotebookSharesParameters { +struct QEVERCLOUD_EXPORT ManageNotebookSharesParameters: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The GUID of the notebook whose shares are being managed. */ - Optional< QString > notebookGuid; + Optional notebookGuid; /** If the service sends a message to invitees, this parameter will be used to form the actual message that is sent. */ - Optional< QString > inviteMessage; + Optional inviteMessage; /** The list of existing memberships to update. This field is not intended to be the full set of memberships for the notebook and @@ -5904,7 +6897,7 @@ struct QEVERCLOUD_EXPORT ManageNotebookSharesParameters { joined by the service, so the client is creating an invitation, not a membership). */ - Optional< QList< MemberShareRelationship > > membershipsToUpdate; + Optional> membershipsToUpdate; /** The list of invitations to update, as matched by the identity field of the InvitationShareRelationship instances, or to create if @@ -5918,7 +6911,7 @@ struct QEVERCLOUD_EXPORT ManageNotebookSharesParameters { belongs. Note that to discover the user IDs for business members, the sharer must also be part of the business. */ - Optional< QList< InvitationShareRelationship > > invitationsToCreateOrUpdate; + Optional> invitationsToCreateOrUpdate; /** The list of share relationships to expunge from the service. If the user identity is for an Evernote UserID, then matching invitations or @@ -5927,7 +6920,9 @@ struct QEVERCLOUD_EXPORT ManageNotebookSharesParameters { match the identity (by identity ID or user ID or e-mail for legacy invitations) will be removed. */ - Optional< QList< UserIdentity > > unshares; + Optional> unshares; + + virtual void print(QTextStream & strm) const override; bool operator==(const ManageNotebookSharesParameters & other) const { @@ -5944,6 +6939,12 @@ struct QEVERCLOUD_EXPORT ManageNotebookSharesParameters { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional notebookGuid MEMBER notebookGuid) + Q_PROPERTY(Optional inviteMessage MEMBER inviteMessage) + Q_PROPERTY(Optional> membershipsToUpdate MEMBER membershipsToUpdate) + Q_PROPERTY(Optional> invitationsToCreateOrUpdate MEMBER invitationsToCreateOrUpdate) + Q_PROPERTY(Optional> unshares MEMBER unshares) }; /** @@ -5957,24 +6958,35 @@ struct QEVERCLOUD_EXPORT ManageNotebookSharesParameters { * relationship and one of the exception fields. * * */ -struct QEVERCLOUD_EXPORT ManageNotebookSharesError { +struct QEVERCLOUD_EXPORT ManageNotebookSharesError: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The identity of the share relationship whose update encountered an error. */ - Optional< UserIdentity > userIdentity; + Optional userIdentity; /** If the error is represented as an EDAMUserException that would have otherwise been thrown without best-effort execution. Only one exception field will be set. */ - Optional< EDAMUserException > userException; + Optional userException; /** If the error is represented as an EDAMNotFoundException that would have otherwise been thrown without best-effort execution. Only one exception field will be set. */ - Optional< EDAMNotFoundException > notFoundException; + Optional notFoundException; + + virtual void print(QTextStream & strm) const override; bool operator==(const ManageNotebookSharesError & other) const { @@ -5989,19 +7001,34 @@ struct QEVERCLOUD_EXPORT ManageNotebookSharesError { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional userIdentity MEMBER userIdentity) + Q_PROPERTY(Optional userException MEMBER userException) + Q_PROPERTY(Optional notFoundException MEMBER notFoundException) }; /** * The return value of a call to the manageNotebookShares method. * * */ -struct QEVERCLOUD_EXPORT ManageNotebookSharesResult { +struct QEVERCLOUD_EXPORT ManageNotebookSharesResult: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** If the method completed without throwing exceptions, some errors might still have occurred, and in that case, this field will contain the list of those errors the occurred. */ - Optional< QList< ManageNotebookSharesError > > errors; + Optional> errors; + + virtual void print(QTextStream & strm) const override; bool operator==(const ManageNotebookSharesResult & other) const { @@ -6014,17 +7041,28 @@ struct QEVERCLOUD_EXPORT ManageNotebookSharesResult { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional> errors MEMBER errors) }; /** * A structure used to share a note with one or more recipients at a given privilege. * * */ -struct QEVERCLOUD_EXPORT SharedNoteTemplate { +struct QEVERCLOUD_EXPORT SharedNoteTemplate: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The GUID of the note. */ - Optional< Guid > noteGuid; + Optional noteGuid; /** The recipients of the note share specified as a messaging thread ID. If you have an existing messaging thread to share the note with, specify its ID @@ -6032,18 +7070,20 @@ struct QEVERCLOUD_EXPORT SharedNoteTemplate { identities. The sharer must be a participant of the thread. Either this field or recipientContacts must be set. */ - Optional< MessageThreadID > recipientThreadId; + Optional recipientThreadId; /** The recipients of the note share specified as a list of contacts. This should only be set if the sharing takes place before the thread is created. Use recipientThreadId instead when sharing with an existing thread. Either this field or recipientThreadId must be set. */ - Optional< QList< Contact > > recipientContacts; + Optional> recipientContacts; /** The privilege level to be granted. */ - Optional< SharedNotePrivilegeLevel::type > privilege; + Optional privilege; + + virtual void print(QTextStream & strm) const override; bool operator==(const SharedNoteTemplate & other) const { @@ -6059,17 +7099,31 @@ struct QEVERCLOUD_EXPORT SharedNoteTemplate { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional noteGuid MEMBER noteGuid) + Q_PROPERTY(Optional recipientThreadId MEMBER recipientThreadId) + Q_PROPERTY(Optional> recipientContacts MEMBER recipientContacts) + Q_PROPERTY(Optional privilege MEMBER privilege) }; /** * A structure used to share a notebook with one or more recipients at a given privilege. * * */ -struct QEVERCLOUD_EXPORT NotebookShareTemplate { +struct QEVERCLOUD_EXPORT NotebookShareTemplate: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The GUID of the notebook. */ - Optional< Guid > notebookGuid; + Optional notebookGuid; /** The recipients of the notebook share specified as a messaging thread ID. If you have an existing messaging thread to share the note with, specify its ID @@ -6077,18 +7131,20 @@ struct QEVERCLOUD_EXPORT NotebookShareTemplate { identities. The sharer must be a participant of the thread. Either this field or recipientContacts must be set. */ - Optional< MessageThreadID > recipientThreadId; + Optional recipientThreadId; /** The recipients of the notebook share specified as a list of contacts. This should only be set if the sharing takes place before the thread is created. Use recipientThreadId instead when sharing with an existing thread. Either this field or recipientThreadId must be set. */ - Optional< QList< Contact > > recipientContacts; + Optional> recipientContacts; /** The privilege level to be granted. */ - Optional< SharedNotebookPrivilegeLevel::type > privilege; + Optional privilege; + + virtual void print(QTextStream & strm) const override; bool operator==(const NotebookShareTemplate & other) const { @@ -6104,24 +7160,40 @@ struct QEVERCLOUD_EXPORT NotebookShareTemplate { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional notebookGuid MEMBER notebookGuid) + Q_PROPERTY(Optional recipientThreadId MEMBER recipientThreadId) + Q_PROPERTY(Optional> recipientContacts MEMBER recipientContacts) + Q_PROPERTY(Optional privilege MEMBER privilege) }; /** * A structure containing the results of a call to createOrUpdateNotebookShares. * * */ -struct QEVERCLOUD_EXPORT CreateOrUpdateNotebookSharesResult { +struct QEVERCLOUD_EXPORT CreateOrUpdateNotebookSharesResult: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The USN of the notebook after the call. */ - Optional< qint32 > updateSequenceNum; + Optional updateSequenceNum; /** A list of SharedNotebook records that match the desired recipients. These records may have been either created or updated by the call to createOrUpdateNotebookShares, or they may have been at the desired privilege privilege level prior to the call. */ - Optional< QList< SharedNotebook > > matchingShares; + Optional> matchingShares; + + virtual void print(QTextStream & strm) const override; bool operator==(const CreateOrUpdateNotebookSharesResult & other) const { @@ -6135,6 +7207,9 @@ struct QEVERCLOUD_EXPORT CreateOrUpdateNotebookSharesResult { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional updateSequenceNum MEMBER updateSequenceNum) + Q_PROPERTY(Optional> matchingShares MEMBER matchingShares) }; /** @@ -6148,22 +7223,31 @@ struct QEVERCLOUD_EXPORT CreateOrUpdateNotebookSharesResult { * Only one of the two exception fields will be set on a given error. * * */ -struct QEVERCLOUD_EXPORT ManageNoteSharesError { +struct QEVERCLOUD_EXPORT ManageNoteSharesError: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** The identity ID of an outstanding invitation that was not updated due to the error. */ - Optional< IdentityID > identityID; + Optional identityID; /** The user ID of an existing membership that was not updated due to the error. */ - Optional< UserID > userID; + Optional userID; /** If the error is represented as an EDAMUserException that would have otherwise been thrown without best-effort execution. */ - Optional< EDAMUserException > userException; + Optional userException; /** If the error is represented as an EDAMNotFoundException that would have otherwise been thrown without best-effort execution. @@ -6171,7 +7255,9 @@ struct QEVERCLOUD_EXPORT ManageNoteSharesError { or "User.id", indicating that no existing share could be found for the specified recipient. */ - Optional< EDAMNotFoundException > notFoundException; + Optional notFoundException; + + virtual void print(QTextStream & strm) const override; bool operator==(const ManageNoteSharesError & other) const { @@ -6187,19 +7273,35 @@ struct QEVERCLOUD_EXPORT ManageNoteSharesError { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional identityID MEMBER identityID) + Q_PROPERTY(Optional userID MEMBER userID) + Q_PROPERTY(Optional userException MEMBER userException) + Q_PROPERTY(Optional notFoundException MEMBER notFoundException) }; /** * The return value of a call to the manageNoteShares function. * * */ -struct QEVERCLOUD_EXPORT ManageNoteSharesResult { +struct QEVERCLOUD_EXPORT ManageNoteSharesResult: public Printable +{ +private: + Q_GADGET +public: + /** + * See the declaration of EverCloudLocalData for details + */ + EverCloudLocalData localData; + /** If the call succeeded without throwing an exception, some errors might still have occurred. In that case, this field will contain the list of errors. */ - Optional< QList< ManageNoteSharesError > > errors; + Optional> errors; + + virtual void print(QTextStream & strm) const override; bool operator==(const ManageNoteSharesResult & other) const { @@ -6212,12 +7314,13 @@ struct QEVERCLOUD_EXPORT ManageNoteSharesResult { return !(*this == other); } + Q_PROPERTY(EverCloudLocalData localData MEMBER localData) + Q_PROPERTY(Optional> errors MEMBER errors) }; - - } // namespace qevercloud +Q_DECLARE_METATYPE(qevercloud::EverCloudLocalData) Q_DECLARE_METATYPE(qevercloud::SyncState) Q_DECLARE_METATYPE(qevercloud::SyncChunkFilter) Q_DECLARE_METATYPE(qevercloud::NoteFilter) @@ -6297,4 +7400,5 @@ Q_DECLARE_METATYPE(qevercloud::CreateOrUpdateNotebookSharesResult) Q_DECLARE_METATYPE(qevercloud::ManageNoteSharesError) Q_DECLARE_METATYPE(qevercloud::ManageNoteSharesResult) + #endif // QEVERCLOUD_GENERATED_TYPES_H diff --git a/src/qevercloud/QEverCloud/headers/globals.h b/src/qevercloud/QEverCloud/headers/globals.h deleted file mode 100644 index 8c904cac..00000000 --- a/src/qevercloud/QEverCloud/headers/globals.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - */ - -#ifndef QEVERCLOUD_GLOBALS_H -#define QEVERCLOUD_GLOBALS_H - -#include "export.h" -#include - -/** - * All the library lives in this namespace. - */ -namespace qevercloud { - -/** - * All network request made by QEverCloud - including OAuth - are - * served by this NetworkAccessManager. - * - * Use this function to handle proxy authentication requests etc. - */ -QEVERCLOUD_EXPORT QNetworkAccessManager * evernoteNetworkAccessManager(); - -/** - * Network request timeout in milliseconds - */ -QEVERCLOUD_EXPORT int connectionTimeout(); - -/** - * Set network request timeout; negative values mean no timeout - */ -QEVERCLOUD_EXPORT void setConnectionTimeout(int timeout); - -/** - * qevercloud library version. - */ -QEVERCLOUD_EXPORT int libraryVersion(); - -} // namespace qevercloud - -#endif // QEVERCLOUD_GLOBALS_H diff --git a/src/qevercloud/QEverCloud/headers/qt4helpers.h b/src/qevercloud/QEverCloud/headers/qt4helpers.h deleted file mode 100644 index ff2a5bf1..00000000 --- a/src/qevercloud/QEverCloud/headers/qt4helpers.h +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - * - * This header provides the "backports" of several Qt5 macros into Qt4 - * so that one can use Qt5 candies with Qt4 as well - */ - -#ifndef QEVERCLOUD_QT4_HELPERS_H -#define QEVERCLOUD_QT4_HELPERS_H - -#include -#include - -#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) - -#if __cplusplus >= 201103L - -#ifndef Q_DECL_OVERRIDE -#define Q_DECL_OVERRIDE override -#endif - -#ifndef Q_DECL_FINAL -#define Q_DECL_FINAL final -#endif - -#ifndef Q_STATIC_ASSERT_X -#define Q_STATIC_ASSERT_X(x1,x2) static_assert(x1, x2) -#endif - -#ifndef Q_DECL_EQ_DELETE -#define Q_DECL_EQ_DELETE = delete -#endif - -#ifndef Q_NULLPTR -#define Q_NULLPTR nullptr -#endif - -#else // __cplusplus - -#ifndef Q_DECL_OVERRIDE -#define Q_DECL_OVERRIDE -#endif - -#ifndef Q_DECL_FINAL -#define Q_DECL_FINAL -#endif - -#ifndef Q_STATIC_ASSERT_X -#define Q_STATIC_ASSERT_X(x1,x2) -#endif - -#ifndef Q_DECL_EQ_DELETE -#define Q_DECL_EQ_DELETE -#endif - -#ifndef Q_NULLPTR -#define Q_NULLPTR NULL -#endif - -#endif // __cplusplus - -#ifndef QStringLiteral -#define QStringLiteral(x) QString::fromUtf8(x, sizeof(x) - 1) -#endif - -#define QEC_SIGNAL(className, methodName, ...) SIGNAL(methodName(__VA_ARGS__)) -#define QEC_SLOT(className, methodName, ...) SLOT(methodName(__VA_ARGS__)) - -#else // QT_VERSION - -// VS2010 is supposed to be C++11 but does not fulfull the entire standard. -#if defined(_MSC_VER) && _MSC_VER <= 1600 // MSVC <= 2010 - -#ifdef Q_DECL_OVERRIDE -#undef Q_DECL_OVERRIDE -#endif -#define Q_DECL_OVERRIDE - -#endif // VS2010 - -#define QEC_SIGNAL(className, methodName, ...) &className::methodName -#define QEC_SLOT(className, methodName, ...) &className::methodName - -#endif // QT_VERSION - -#endif // QEVERCLOUD_QT4_HELPERS_H diff --git a/src/qevercloud/QEverCloud/src/AsyncResult.cpp b/src/qevercloud/QEverCloud/src/AsyncResult.cpp index c7a3aa49..c2b6e927 100644 --- a/src/qevercloud/QEverCloud/src/AsyncResult.cpp +++ b/src/qevercloud/QEverCloud/src/AsyncResult.cpp @@ -1,84 +1,76 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: * https://opensource.org/licenses/MIT */ +#include "AsyncResult_p.h" +#include "Http.h" + #include #include -#include "http.h" + #include #include + #include namespace qevercloud { -class AsyncResultPrivate -{ -public: - explicit AsyncResultPrivate(QString url, QByteArray postData, AsyncResult::ReadFunctionType readFunction, - bool autoDelete, AsyncResult * q); - - explicit AsyncResultPrivate(QNetworkRequest request, QByteArray postData, AsyncResult::ReadFunctionType readFunction, - bool autoDelete, AsyncResult * q); - - virtual ~AsyncResultPrivate(); - - QNetworkRequest m_request; - QByteArray m_postData; - AsyncResult::ReadFunctionType m_readFunction; - bool m_autoDelete; - -private: - AsyncResult * const q_ptr; - Q_DECLARE_PUBLIC(AsyncResult) -}; - -AsyncResultPrivate::AsyncResultPrivate(QString url, QByteArray postData, AsyncResult::ReadFunctionType readFunction, - bool autoDelete, AsyncResult * q) : - m_request(createEvernoteRequest(url)), - m_postData(postData), - m_readFunction(readFunction), - m_autoDelete(autoDelete), - q_ptr(q) -{} - -AsyncResultPrivate::AsyncResultPrivate(QNetworkRequest request, QByteArray postData, AsyncResult::ReadFunctionType readFunction, - bool autoDelete, AsyncResult * q) : - m_request(request), - m_postData(postData), - m_readFunction(readFunction), - m_autoDelete(autoDelete), - q_ptr(q) -{} - - -AsyncResultPrivate::~AsyncResultPrivate() -{} - QVariant AsyncResult::asIs(QByteArray replyData) { return replyData; } -AsyncResult::AsyncResult(QString url, QByteArray postData, AsyncResult::ReadFunctionType readFunction, - bool autoDelete, QObject * parent) : +AsyncResult::AsyncResult( + QString url, QByteArray postData, IRequestContextPtr ctx, + AsyncResult::ReadFunctionType readFunction, bool autoDelete, + QObject * parent) : QObject(parent), - d_ptr(new AsyncResultPrivate(url, postData, readFunction, autoDelete, this)) + d_ptr(new AsyncResultPrivate( + url, + std::move(postData), + std::move(ctx), + std::move(readFunction), + autoDelete, + this)) { - QMetaObject::invokeMethod(this, "start", Qt::QueuedConnection); + if (!url.isEmpty()) { + QMetaObject::invokeMethod(d_ptr, "start", Qt::QueuedConnection); + } } -AsyncResult::AsyncResult(QNetworkRequest request, QByteArray postData, qevercloud::AsyncResult::ReadFunctionType readFunction, - bool autoDelete, QObject * parent) : +AsyncResult::AsyncResult( + QNetworkRequest request, QByteArray postData, IRequestContextPtr ctx, + qevercloud::AsyncResult::ReadFunctionType readFunction, + bool autoDelete, QObject * parent) : QObject(parent), - d_ptr(new AsyncResultPrivate(request, postData, readFunction, autoDelete, this)) + d_ptr(new AsyncResultPrivate( + std::move(request), + std::move(postData), + std::move(ctx), + std::move(readFunction), + autoDelete, + this)) { - QMetaObject::invokeMethod(this, "start", Qt::QueuedConnection); + QMetaObject::invokeMethod(d_ptr, "start", Qt::QueuedConnection); } +AsyncResult::AsyncResult( + QVariant result, EverCloudExceptionDataPtr error, + IRequestContextPtr ctx, bool autoDelete, QObject * parent) : + QObject(parent), + d_ptr(new AsyncResultPrivate( + std::move(result), + std::move(error), + std::move(ctx), + autoDelete, + this)) +{} + AsyncResult::~AsyncResult() { delete d_ptr; @@ -87,12 +79,30 @@ AsyncResult::~AsyncResult() bool AsyncResult::waitForFinished(int timeout) { QEventLoop loop; - QObject::connect(this, SIGNAL(finished(QVariant,QSharedPointer)), &loop, SLOT(quit())); - - if(timeout >= 0) { + QObject::connect( + this, + &AsyncResult::finished, + &loop, + [&loop](const QVariant & result, + const EverCloudExceptionDataPtr & error, + const IRequestContextPtr & ctx) + { + Q_UNUSED(result) + Q_UNUSED(error) + Q_UNUSED(ctx) + loop.quit(); + }); + + if (timeout >= 0) + { QTimer timer; EventLoopFinisher finisher(&loop, 1); - connect(&timer, SIGNAL(timeout()), &finisher, SLOT(stopEventLoop())); + QObject::connect( + &timer, + &QTimer::timeout, + &finisher, + &EventLoopFinisher::stopEventLoop); + timer.setSingleShot(true); timer.setInterval(timeout); timer.start(); @@ -102,52 +112,4 @@ bool AsyncResult::waitForFinished(int timeout) return res; } -void AsyncResult::start() -{ - Q_D(AsyncResult); - ReplyFetcher * replyFetcher = new ReplyFetcher; - QObject::connect(replyFetcher, QEC_SIGNAL(ReplyFetcher,replyFetched,QObject*), - this, QEC_SLOT(AsyncResult,onReplyFetched,QObject*)); - replyFetcher->start(evernoteNetworkAccessManager(), d->m_request, d->m_postData); -} - -void AsyncResult::onReplyFetched(QObject * rp) -{ - Q_D(AsyncResult); - - ReplyFetcher * reply = qobject_cast(rp); - QSharedPointer error; - QVariant result; - - try - { - if (reply->isError()) { - error = QSharedPointer(new EverCloudExceptionData(reply->errorText())); - } - else if(reply->httpStatusCode() != 200) { - error = QSharedPointer(new EverCloudExceptionData(QStringLiteral("HTTP Status Code = %1").arg(reply->httpStatusCode()))); - } - else { - result = d->m_readFunction(reply->receivedData()); - } - } - catch(const EverCloudException & e) { - error = e.exceptionData(); - } - catch(const std::exception & e) { - error = QSharedPointer(new EverCloudExceptionData(QStringLiteral("Exception of type \"%1\" with the message: %2") - .arg(QString::fromUtf8(typeid(e).name()), QString::fromUtf8(e.what())))); - } - catch(...) { - error = QSharedPointer(new EverCloudExceptionData(QStringLiteral("Unknown exception"))); - } - - emit finished(result, error); - reply->deleteLater(); - - if (d->m_autoDelete) { - this->deleteLater(); - } -} - } // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/AsyncResult_p.cpp b/src/qevercloud/QEverCloud/src/AsyncResult_p.cpp new file mode 100644 index 00000000..b39ae27c --- /dev/null +++ b/src/qevercloud/QEverCloud/src/AsyncResult_p.cpp @@ -0,0 +1,151 @@ +/** + * Copyright (c) 2019-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include "AsyncResult_p.h" +#include "Http.h" + +#include +#include + +#include + +#include + +namespace qevercloud { + +AsyncResultPrivate::AsyncResultPrivate( + QString url, QByteArray postData, + IRequestContextPtr ctx, AsyncResult::ReadFunctionType readFunction, + bool autoDelete, AsyncResult * q) : + m_request(createEvernoteRequest(url, ctx->cookies())), + m_postData(std::move(postData)), + m_ctx(std::move(ctx)), + m_readFunction(std::move(readFunction)), + m_autoDelete(autoDelete), + q_ptr(q) +{} + +AsyncResultPrivate::AsyncResultPrivate( + QNetworkRequest request, QByteArray postData, IRequestContextPtr ctx, + AsyncResult::ReadFunctionType readFunction, bool autoDelete, + AsyncResult * q) : + m_request(std::move(request)), + m_postData(std::move(postData)), + m_ctx(std::move(ctx)), + m_readFunction(std::move(readFunction)), + m_autoDelete(autoDelete), + q_ptr(q) +{} + +AsyncResultPrivate::AsyncResultPrivate( + QVariant result, EverCloudExceptionDataPtr error, + IRequestContextPtr ctx, bool autoDelete, AsyncResult * q) : + m_ctx(std::move(ctx)), + m_autoDelete(autoDelete), + q_ptr(q) +{ + QMetaObject::invokeMethod( + this, + "setValue", + Qt::QueuedConnection, + Q_ARG(QVariant, result), + Q_ARG(EverCloudExceptionDataPtr, error)); +} + +AsyncResultPrivate::~AsyncResultPrivate() +{} + +void AsyncResultPrivate::start() +{ + if (m_request.url().isEmpty() && m_postData.isEmpty()) { + // No network request to start, will wait for value to be set explicitly + return; + } + + auto * replyFetcher = new ReplyFetcher(this); + auto * pNam = new QNetworkAccessManager(replyFetcher); + pNam->setProxy(evernoteNetworkProxy()); + + QObject::connect( + replyFetcher, + &ReplyFetcher::replyFetched, + this, + &AsyncResultPrivate::onReplyFetched); + + replyFetcher->start( + pNam, + m_request, + m_ctx->requestTimeout(), + m_postData); +} + +void AsyncResultPrivate::onReplyFetched(ReplyFetcher * pReplyFetcher) +{ + QEC_DEBUG("async_result", "received reply for request with id " + << m_ctx->requestId()); + + EverCloudExceptionDataPtr error; + QVariant result; + + try + { + if (pReplyFetcher->isError()) + { + error = std::make_shared( + pReplyFetcher->errorText()); + } + else if (pReplyFetcher->httpStatusCode() != 200) + { + error = std::make_shared( + QString::fromUtf8("HTTP Status Code = %1") + .arg(pReplyFetcher->httpStatusCode())); + } + else + { + result = m_readFunction(pReplyFetcher->receivedData()); + } + } + catch(const EverCloudException & e) + { + error = e.exceptionData(); + } + catch(const std::exception & e) + { + error = std::make_shared( + QString::fromUtf8("Exception of type \"%1\" with the message: %2") + .arg(QString::fromUtf8(typeid(e).name()), QString::fromUtf8(e.what()))); + } + catch(...) + { + error = std::make_shared( + QStringLiteral("Unknown exception")); + } + + pReplyFetcher->deleteLater(); + setValue(result, error); +} + +void AsyncResultPrivate::setValue( + QVariant result, EverCloudExceptionDataPtr error) +{ + Q_Q(AsyncResult); + QObject::connect( + this, + &AsyncResultPrivate::finished, + q, + &AsyncResult::finished, + Qt::DirectConnection); + + Q_EMIT finished(result, error, m_ctx); + + if (m_autoDelete) { + q->deleteLater(); + } +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/AsyncResult_p.h b/src/qevercloud/QEverCloud/src/AsyncResult_p.h new file mode 100644 index 00000000..93254255 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/AsyncResult_p.h @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2019-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_ASYNC_RESULT_PRIVATE_H +#define QEVERCLOUD_ASYNC_RESULT_PRIVATE_H + +#include + +namespace qevercloud { + +QT_FORWARD_DECLARE_CLASS(ReplyFetcher) + +class AsyncResultPrivate: public QObject +{ + Q_OBJECT +public: + explicit AsyncResultPrivate( + QString url, QByteArray postData, IRequestContextPtr ctx, + AsyncResult::ReadFunctionType readFunction, bool autoDelete, + AsyncResult * q); + + explicit AsyncResultPrivate( + QNetworkRequest request, QByteArray postData, IRequestContextPtr ctx, + AsyncResult::ReadFunctionType readFunction, bool autoDelete, + AsyncResult * q); + + explicit AsyncResultPrivate( + QVariant result, EverCloudExceptionDataPtr error, + IRequestContextPtr ctx, bool autoDelete, AsyncResult * q); + + virtual ~AsyncResultPrivate() override; + +Q_SIGNALS: + void finished( + QVariant result, EverCloudExceptionDataPtr error, + IRequestContextPtr ctx); + +public Q_SLOTS: + void start(); + + void onReplyFetched(ReplyFetcher * pReplyFetcher); + + void setValue(QVariant result, EverCloudExceptionDataPtr error); + +public: + QNetworkRequest m_request; + QByteArray m_postData; + IRequestContextPtr m_ctx; + AsyncResult::ReadFunctionType m_readFunction; + bool m_autoDelete; + +private: + AsyncResult * const q_ptr; + Q_DECLARE_PUBLIC(AsyncResult) +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_ASYNC_RESULT_PRIVATE_H diff --git a/src/qevercloud/QEverCloud/src/DurableService.cpp b/src/qevercloud/QEverCloud/src/DurableService.cpp new file mode 100644 index 00000000..2ce96d26 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/DurableService.cpp @@ -0,0 +1,345 @@ +/** + * Copyright (c) 2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#include "AsyncResult_p.h" + +#include +#include +#include + +#include +#include +#include + +namespace qevercloud { + +namespace { + +//////////////////////////////////////////////////////////////////////////////// + +struct RetryState +{ + quint32 m_retryCount = 0; +}; + +//////////////////////////////////////////////////////////////////////////////// + +quint64 exponentiallyIncreasedTimeoutMsec( + quint64 timeout, const quint64 maxTimeout) +{ + timeout = static_cast(std::floor(timeout * 1.6 + 0.5)); + timeout = std::min(timeout, maxTimeout); + return timeout; +} + +//////////////////////////////////////////////////////////////////////////////// + +struct Q_DECL_HIDDEN RetryPolicy: public IRetryPolicy +{ + virtual bool shouldRetry( + const EverCloudExceptionDataPtr & exceptionData) override + { + if (Q_UNLIKELY(!exceptionData)) { + return true; + } + + try + { + exceptionData->throwException(); + } + catch(const NetworkException & e) + { + switch(e.type()) + { + case QNetworkReply::TimeoutError: + return true; + case QNetworkReply::TemporaryNetworkFailureError: + return true; + case QNetworkReply::NetworkSessionFailedError: + return true; + case QNetworkReply::ProxyConnectionClosedError: + return true; + case QNetworkReply::ProxyTimeoutError: + return true; + case QNetworkReply::ContentReSendError: + return true; + case QNetworkReply::InternalServerError: + return true; + case QNetworkReply::ServiceUnavailableError: + return true; + case QNetworkReply::ProtocolFailure: + return true; + default: + return false; + } + } + catch(const ThriftException & e) + { + switch(e.type()) + { + case ThriftException::Type::BAD_SEQUENCE_ID: + return true; + case ThriftException::Type::INTERNAL_ERROR: + return true; + case ThriftException::Type::PROTOCOL_ERROR: + return true; + case ThriftException::Type::UNKNOWN: + return true; + default: + return false; + } + } + catch(const EDAMSystemException &) + { + return true; + } + catch(...) + { + } + + return false; + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +struct Q_DECL_HIDDEN NullRetryPolicy: public IRetryPolicy +{ + virtual bool shouldRetry( + const EverCloudExceptionDataPtr & exceptionData) override + { + Q_UNUSED(exceptionData) + return false; + } +}; + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// + +class Q_DECL_HIDDEN DurableService: public IDurableService +{ +public: + DurableService(IRetryPolicyPtr retryPolicy, IRequestContextPtr ctx); + + virtual SyncResult executeSyncRequest( + SyncRequest && syncRequest, IRequestContextPtr ctx) override; + + virtual AsyncResult * executeAsyncRequest( + AsyncRequest && asyncRequest, IRequestContextPtr ctx) override; + +private: + void doExecuteAsyncRequest( + AsyncRequest && asyncRequest, IRequestContextPtr ctx, + RetryState && retryState, AsyncResult * result); + +private: + IRetryPolicyPtr m_retryPolicy; + IRequestContextPtr m_ctx; +}; + +DurableService::DurableService(IRetryPolicyPtr retryPolicy, + IRequestContextPtr ctx) : + m_retryPolicy(std::move(retryPolicy)), + m_ctx(std::move(ctx)) +{ + if (!m_retryPolicy) { + m_retryPolicy = newRetryPolicy(); + } + + if (!m_ctx) { + m_ctx = newRequestContext(); + } +} + +DurableService::SyncResult DurableService::executeSyncRequest( + SyncRequest && syncRequest, IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + RetryState state; + state.m_retryCount = ctx->maxRequestRetryCount(); + + SyncResult result; + + while(state.m_retryCount) + { + QEC_DEBUG("durable_service", "Executing sync " << syncRequest.m_name + << " request: " << state.m_retryCount << " attempts left, timeout = " + << ctx->requestTimeout()); + QEC_TRACE("durable_service", "Request details: " + << syncRequest.m_description); + + try { + result = syncRequest.m_call(ctx); + } + catch(const EverCloudException & e) { + result.second = e.exceptionData(); + } + catch(const std::exception & e) { + result.second = std::make_shared( + QString::fromLocal8Bit(e.what())); + return result; + } + + if (result.second) + { + QEC_WARNING("durable_service", "Sync request " << syncRequest.m_name + << " failed: " << result.second->errorMessage + << "; request details: " << syncRequest.m_description); + + if (!m_retryPolicy->shouldRetry(result.second)) { + QEC_WARNING("durable_service", "Error is not retriable"); + return result; + } + + --state.m_retryCount; + if (!state.m_retryCount) { + QEC_WARNING("durable_service", "No retry attempts left"); + break; + } + + if (ctx->increaseRequestTimeoutExponentially()) + { + auto timeout = ctx->requestTimeout(); + auto maxTimeout = ctx->maxRequestTimeout(); + timeout = exponentiallyIncreasedTimeoutMsec(timeout, maxTimeout); + + ctx = newRequestContext( + ctx->authenticationToken(), + timeout, + /* increase request timeout exponentially = */ true, + maxTimeout, + ctx->maxRequestRetryCount()); + } + + QEC_INFO("durable_service", "Retrying sync " << syncRequest.m_name + << " request, " << state.m_retryCount << " attempts left"); + continue; + } + + if (!result.second) { + QEC_DEBUG("durable_service", "Successfully executed sync " + << syncRequest.m_name << " request"); + } + + break; + } + + return result; +} + +AsyncResult * DurableService::executeAsyncRequest( + AsyncRequest && asyncRequest, IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + RetryState state; + state.m_retryCount = ctx->maxRequestRetryCount(); + + AsyncResult * result = new AsyncResult(QString(), QByteArray(), ctx); + doExecuteAsyncRequest(std::move(asyncRequest), std::move(ctx), + std::move(state), result); + + return result; +} + +void DurableService::doExecuteAsyncRequest( + AsyncRequest && asyncRequest, IRequestContextPtr ctx, + RetryState && retryState, AsyncResult * result) +{ + QEC_DEBUG("durable_service", "Executing async " << asyncRequest.m_name + << " request: " << retryState.m_retryCount << " attempts left, timeout = " + << ctx->requestTimeout() << ", request id = " << ctx->requestId()); + QEC_TRACE("durable_service", "Request details: " + << asyncRequest.m_description); + + AsyncResult * attemptRes = asyncRequest.m_call(ctx); + QObject::connect( + attemptRes, + &AsyncResult::finished, + result, + [=, retryState = std::move(retryState), retryPolicy = m_retryPolicy] ( + QVariant value, + EverCloudExceptionDataPtr exceptionData, + IRequestContextPtr c) mutable + { + Q_UNUSED(c) + + if (!exceptionData) { + QEC_DEBUG("durable_service", "Successfully executed async " + << asyncRequest.m_name << " request with id " + << ctx->requestId()); + result->d_ptr->setValue(value, {}); + return; + } + + QEC_WARNING("durable_service", "Sync request " + << asyncRequest.m_name << " with id " << ctx->requestId() + << " failed: " << exceptionData->errorMessage + << "; request details: " << asyncRequest.m_description); + + if (!retryPolicy->shouldRetry(exceptionData)) { + QEC_WARNING("durable_service", "Error is not retriable"); + result->d_ptr->setValue({}, exceptionData); + return; + } + + --retryState.m_retryCount; + if (!retryState.m_retryCount) { + QEC_WARNING("durable_service", "No retry attempts left"); + result->d_ptr->setValue({}, exceptionData); + return; + } + + if (ctx->increaseRequestTimeoutExponentially()) + { + auto timeout = ctx->requestTimeout(); + auto maxTimeout = ctx->maxRequestTimeout(); + timeout = exponentiallyIncreasedTimeoutMsec(timeout, maxTimeout); + + ctx = newRequestContext( + ctx->authenticationToken(), + timeout, + /* increase request timeout exponentially = */ true, + maxTimeout, + ctx->maxRequestRetryCount()); + } + + QEC_INFO("durable_service", "Retrying async " << asyncRequest.m_name + << " request, " << retryState.m_retryCount << " attempts left"); + doExecuteAsyncRequest( + std::move(asyncRequest), std::move(ctx), + std::move(retryState), result); + }, + Qt::QueuedConnection); +} + +//////////////////////////////////////////////////////////////////////////////// + +IRetryPolicyPtr newRetryPolicy() +{ + return std::make_shared(); +} + +IRetryPolicyPtr nullRetryPolicy() +{ + return std::make_shared(); +} + +IDurableServicePtr newDurableService( + IRetryPolicyPtr retryPolicy, + IRequestContextPtr ctx) +{ + return std::make_shared(retryPolicy, ctx); +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/EventLoopFinisher.cpp b/src/qevercloud/QEverCloud/src/EventLoopFinisher.cpp index 7cb688c0..4112a102 100644 --- a/src/qevercloud/QEverCloud/src/EventLoopFinisher.cpp +++ b/src/qevercloud/QEverCloud/src/EventLoopFinisher.cpp @@ -1,8 +1,9 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: * https://opensource.org/licenses/MIT */ @@ -22,7 +23,9 @@ class EventLoopFinisherPrivate int m_exitCode; }; -qevercloud::EventLoopFinisher::EventLoopFinisher(QEventLoop * loop, int exitCode, QObject * parent) : +qevercloud::EventLoopFinisher::EventLoopFinisher(QEventLoop * loop, + int exitCode, + QObject * parent) : QObject(parent), d_ptr(new EventLoopFinisherPrivate(loop, exitCode)) {} diff --git a/src/qevercloud/QEverCloud/src/EverCloudException.cpp b/src/qevercloud/QEverCloud/src/EverCloudException.cpp index 6f5c3d14..ae5dfd6b 100644 --- a/src/qevercloud/QEverCloud/src/EverCloudException.cpp +++ b/src/qevercloud/QEverCloud/src/EverCloudException.cpp @@ -1,12 +1,14 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: * https://opensource.org/licenses/MIT */ #include +#include namespace qevercloud { @@ -34,9 +36,10 @@ const char * EverCloudException::what() const throw() return m_error.constData(); } -QSharedPointer QEVERCLOUD_EXPORT EverCloudException::exceptionData() const +EverCloudExceptionDataPtr EverCloudException::exceptionData() const { - return QSharedPointer(new EverCloudExceptionData(QString::fromUtf8(what()))); + return std::make_shared( + QString::fromUtf8(what())); } EverCloudExceptionData::EverCloudExceptionData(QString error) : @@ -64,9 +67,10 @@ EvernoteException::EvernoteException(const char * error) : EverCloudException(error) {} -QSharedPointer EvernoteException::exceptionData() const +EverCloudExceptionDataPtr EvernoteException::exceptionData() const { - return QSharedPointer(new EvernoteExceptionData(QString::fromUtf8(what()))); + return std::make_shared( + QString::fromUtf8(what())); } EvernoteExceptionData::EvernoteExceptionData(QString error) : diff --git a/src/qevercloud/QEverCloud/src/Exceptions.cpp b/src/qevercloud/QEverCloud/src/Exceptions.cpp new file mode 100644 index 00000000..78b5279c --- /dev/null +++ b/src/qevercloud/QEverCloud/src/Exceptions.cpp @@ -0,0 +1,588 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include "Impl.h" +#include "generated/Types_io.h" + +#include +#include +#include + +#include +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +NetworkException::NetworkException() : + EverCloudException(), + m_type(QNetworkReply::UnknownNetworkError) +{} + +NetworkException::NetworkException(QNetworkReply::NetworkError type) : + EverCloudException(), + m_type(type) +{} + +NetworkException::NetworkException( + QNetworkReply::NetworkError type, + QString message) : + EverCloudException(message), + m_type(type) +{} + +NetworkException::~NetworkException() noexcept +{} + +bool NetworkException::operator==(const NetworkException & other) const +{ + return m_type == other.m_type && m_error == other.m_error; +} + +bool NetworkException::operator!=(const NetworkException & other) const +{ + return !operator==(other); +} + +QNetworkReply::NetworkError NetworkException::type() const +{ + return m_type; +} + +const char * NetworkException::what() const noexcept +{ + if (m_error.isEmpty()) + { + switch (m_type) + { + case QNetworkReply::NoError: + return "NetworkException: No error"; + case QNetworkReply::ConnectionRefusedError: + return "NetworkException: Connection refused"; + case QNetworkReply::RemoteHostClosedError: + return "NetworkException: Remote host closed"; + case QNetworkReply::HostNotFoundError: + return "NetworkException: Host not found"; + case QNetworkReply::TimeoutError: + return "NetworkException: The connection to remote host timed out"; + case QNetworkReply::OperationCanceledError: + return "NetworkException: Operation canceled"; + case QNetworkReply::SslHandshakeFailedError: + return "NetworkError: SSL handshake failed"; + case QNetworkReply::TemporaryNetworkFailureError: + return "NetworkError: Temporary network failure"; + case QNetworkReply::NetworkSessionFailedError: + return "NetworkError: Network session failed"; + case QNetworkReply::BackgroundRequestNotAllowedError: + return "NetworkError: Background request not allowed"; +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) + case QNetworkReply::TooManyRedirectsError: + return "NetworkError: Too many redirects"; + case QNetworkReply::InsecureRedirectError: + return "NetworkError: Insecure redirect"; +#endif + case QNetworkReply::ProxyConnectionRefusedError: + return "NetworkError: Proxy connection refused"; + case QNetworkReply::ProxyConnectionClosedError: + return "NetworkError: Proxy connection closed"; + case QNetworkReply::ProxyNotFoundError: + return "NetworkError: Proxy not found"; + case QNetworkReply::ProxyTimeoutError: + return "NetworkError: Proxy timeout"; + case QNetworkReply::ProxyAuthenticationRequiredError: + return "NetworkError: Proxy authentication required"; + case QNetworkReply::ContentAccessDenied: + return "NetworkError: Content access denied"; + case QNetworkReply::ContentOperationNotPermittedError: + return "NetworkError: Content operation not permitted"; + case QNetworkReply::ContentNotFoundError: + return "NetworkError: Content not found"; + case QNetworkReply::AuthenticationRequiredError: + return "NetworkError: Authentication required"; + case QNetworkReply::ContentReSendError: + return "NetworkError: Content resend failed"; + case QNetworkReply::ContentConflictError: + return "NetworkError: Content conflict error"; + case QNetworkReply::ContentGoneError: + return "NetworkError: Content gone"; + case QNetworkReply::InternalServerError: + return "NetworkError: Internal server error"; + case QNetworkReply::OperationNotImplementedError: + return "NetworkError: Operation not implemented error"; + case QNetworkReply::ServiceUnavailableError: + return "NetworkError: Service unavailable"; + case QNetworkReply::ProtocolUnknownError: + return "NetworkError: Protocol unknown"; + case QNetworkReply::ProtocolInvalidOperationError: + return "NetworkError: Protocol invalid operation"; + case QNetworkReply::UnknownNetworkError: + return "NetworkError: Unknown network"; + case QNetworkReply::UnknownProxyError: + return "NetworkError: Unknown proxy"; + case QNetworkReply::UnknownContentError: + return "NetworkError: Unknown content"; + case QNetworkReply::ProtocolFailure: + return "NetworkError: Protocol failure"; + case QNetworkReply::UnknownServerError: + return "NetworkError: Unknown server"; + default: + return "NetworkError: (Invlaid exception type)"; + } + } + else + { + return m_error.constData(); + } +} + +EverCloudExceptionDataPtr NetworkException::exceptionData() const +{ + return std::make_shared( + QString::fromUtf8(what()), type()); +} + +NetworkExceptionData::NetworkExceptionData( + QString error, + QNetworkReply::NetworkError type) : + EverCloudExceptionData(error), + m_type(type) +{} + +void NetworkExceptionData::throwException() const +{ + throw NetworkException(m_type, errorMessage); +} + +//////////////////////////////////////////////////////////////////////////////// + +ThriftException::ThriftException() : + EverCloudException(), + m_type(Type::UNKNOWN) +{} + +ThriftException::ThriftException(ThriftException::Type type) : + EverCloudException(), + m_type(type) +{} + +ThriftException::ThriftException(ThriftException::Type type, QString message) : + EverCloudException(message), + m_type(type) +{} + +ThriftException::~ThriftException() noexcept +{} + +QTextStream & operator<<(QTextStream & strm, const ThriftException::Type type) +{ + switch(type) + { + case ThriftException::Type::UNKNOWN: + strm << "Unknown application exception"; + break; + case ThriftException::Type::UNKNOWN_METHOD: + strm << "Unknown method"; + break; + case ThriftException::Type::INVALID_MESSAGE_TYPE: + strm << "Invalid message type"; + break; + case ThriftException::Type::WRONG_METHOD_NAME: + strm << "Wrong method name"; + break; + case ThriftException::Type::BAD_SEQUENCE_ID: + strm << "Bad sequence identifier"; + break; + case ThriftException::Type::MISSING_RESULT: + strm << "Missing result"; + break; + case ThriftException::Type::INTERNAL_ERROR: + strm << "Internal error"; + break; + case ThriftException::Type::PROTOCOL_ERROR: + strm << "Protocol error"; + break; + case ThriftException::Type::INVALID_DATA: + strm << "Invalid data"; + break; + default: + strm << "Invalid exception type: " << static_cast(type); + break; + } + + return strm; +} + +bool ThriftException::operator==(const ThriftException & other) const +{ + return m_type == other.m_type && m_error == other.m_error; +} + +bool ThriftException::operator!=(const ThriftException & other) const +{ + return !operator==(other); +} + +ThriftException::Type ThriftException::type() const +{ + return m_type; +} + +const char * ThriftException::what() const noexcept +{ + if (m_error.isEmpty()) + { + switch (m_type) + { + case Type::UNKNOWN: + return "ThriftException: Unknown application exception"; + case Type::UNKNOWN_METHOD: + return "ThriftException: Unknown method"; + case Type::INVALID_MESSAGE_TYPE: + return "ThriftException: Invalid message type"; + case Type::WRONG_METHOD_NAME: + return "ThriftException: Wrong method name"; + case Type::BAD_SEQUENCE_ID: + return "ThriftException: Bad sequence identifier"; + case Type::MISSING_RESULT: + return "ThriftException: Missing result"; + case Type::INTERNAL_ERROR: + return "ThriftException: Internal error"; + case Type::PROTOCOL_ERROR: + return "ThriftException: Protocol error"; + case Type::INVALID_DATA: + return "ThriftException: Invalid data"; + default: + return "ThriftException: (Invalid exception type)"; + }; + } + else + { + return m_error.constData(); + } +} + +EverCloudExceptionDataPtr ThriftException::exceptionData() const +{ + return std::make_shared( + QString::fromUtf8(what()), type()); +} + +ThriftExceptionData::ThriftExceptionData( + QString error, + ThriftException::Type type) : + EverCloudExceptionData(error), + m_type(type) +{} + +void ThriftExceptionData::throwException() const +{ + throw ThriftException(m_type, errorMessage); +} + +//////////////////////////////////////////////////////////////////////////////// + +const char * EDAMUserException::what() const noexcept +{ + if (m_error.isEmpty()) + { + QTextStream strm(&m_error); + strm << "EDAMUserException: " << errorCode; + if (parameter.isSet()) { + strm << " parameter=" << parameter->toUtf8(); + } + } + + return EvernoteException::what(); +} + +const char * EDAMSystemException::what() const noexcept +{ + if (m_error.isEmpty()) + { + QTextStream strm(&m_error); + strm << "EDAMSystemException: " << errorCode; + + if (message.isSet()) { + strm << " " << message->toUtf8(); + } + + if (rateLimitDuration.isSet()) { + strm << " rateLimitDuration= " << rateLimitDuration << " sec."; + } + } + + return EvernoteException::what(); +} + +const char * EDAMNotFoundException::what() const noexcept +{ + if (m_error.isEmpty()) + { + QTextStream strm(&m_error); + strm << "EDAMNotFoundException: "; + + if (identifier.isSet()) { + strm << " identifier=" << identifier; + } + + if (key.isSet()) { + strm << " key=" << key; + } + } + + return EvernoteException::what(); +} + +ThriftException readThriftException(ThriftBinaryBufferReader & reader) +{ + QString name; + ThriftFieldType fieldType; + qint16 fieldId; + + reader.readStructBegin(name); + QString error; + ThriftException::Type type = ThriftException::Type::UNKNOWN; + + while(true) + { + reader.readFieldBegin(name, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + switch(fieldId) + { + case 1: + if (fieldType == ThriftFieldType::T_STRING) { + QString str; + reader.readString(str); + error = str; + } + else { + reader.skip(fieldType); + } + break; + case 2: + if (fieldType == ThriftFieldType::T_I32) { + qint32 t; + reader.readI32(t); + type = static_cast(t); + } + else { + reader.skip(fieldType); + } + break; + default: + reader.skip(fieldType); + break; + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + + return ThriftException(type, error); +} + +void writeThriftException( + ThriftBinaryBufferWriter & writer, const ThriftException & exception) +{ + writer.writeStructBegin(QStringLiteral("ThriftException")); + + writer.writeFieldBegin(QStringLiteral("error"), ThriftFieldType::T_STRING, 1); + writer.writeString(QString::fromUtf8(exception.what())); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QStringLiteral("type"), ThriftFieldType::T_I32, 2); + writer.writeI32(static_cast(exception.type())); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); +} + +EverCloudExceptionDataPtr EDAMInvalidContactsException::exceptionData() const +{ + return std::make_shared( + contacts, parameter, reasons); +} + +EDAMInvalidContactsExceptionData::EDAMInvalidContactsExceptionData( + QList contacts, + Optional parameter, + Optional > reasons) : + EvernoteExceptionData(QStringLiteral("EDAMInvalidContactsExceptionData")), + m_contacts(contacts), + m_parameter(parameter), + m_reasons(reasons) +{} + +const char * EDAMInvalidContactsException::what() const noexcept +{ + return "EDAMInvalidContactsException"; +} + +void EDAMInvalidContactsExceptionData::throwException() const +{ + EDAMInvalidContactsException e; + e.contacts = m_contacts; + e.parameter = m_parameter; + e.reasons = m_reasons; + throw e; +} + +EverCloudExceptionDataPtr EDAMUserException::exceptionData() const +{ + return std::make_shared( + QString::fromUtf8(what()), errorCode, parameter); +} + +void EDAMUserExceptionData::throwException() const +{ + EDAMUserException e; + e.errorCode = m_errorCode; + e.parameter = m_parameter; + throw e; +} + +EverCloudExceptionDataPtr EDAMSystemException::exceptionData() const +{ + return std::make_shared( + QString::fromUtf8(what()), errorCode, message, rateLimitDuration); +} + +EDAMSystemExceptionData::EDAMSystemExceptionData( + QString error, + EDAMErrorCode errorCode, + Optional message, + Optional rateLimitDuration) : + EvernoteExceptionData(error), + m_errorCode(errorCode), + m_message(message), + m_rateLimitDuration(rateLimitDuration) +{} + +void EDAMSystemExceptionData::throwException() const +{ + EDAMSystemException e; + e.errorCode = m_errorCode; + e.message = m_message; + e.rateLimitDuration = m_rateLimitDuration; + throw e; +} + +EDAMSystemExceptionRateLimitReachedData::EDAMSystemExceptionRateLimitReachedData( + QString error, EDAMErrorCode errorCode, + Optional message, + Optional rateLimitDuration) : + EDAMSystemExceptionData(error, errorCode, message, rateLimitDuration) +{} + +void EDAMSystemExceptionRateLimitReachedData::throwException() const +{ + EDAMSystemExceptionRateLimitReached e; + e.errorCode = m_errorCode; + e.message = m_message; + e.rateLimitDuration = m_rateLimitDuration; + throw e; +} + +EverCloudExceptionDataPtr EDAMNotFoundException::exceptionData() const +{ + return std::make_shared( + QString::fromUtf8(what()), identifier, key); +} + +EDAMNotFoundExceptionData::EDAMNotFoundExceptionData( + QString error, + Optional identifier, + Optional key) : + EvernoteExceptionData(error), + m_identifier(identifier), + m_key(key) +{} + +void EDAMNotFoundExceptionData::throwException() const +{ + EDAMNotFoundException e; + e.identifier = m_identifier; + e.key = m_key; + throw e; +} + +void throwEDAMSystemException(const EDAMSystemException & baseException) +{ + if (baseException.errorCode == EDAMErrorCode::AUTH_EXPIRED) { + EDAMSystemExceptionAuthExpired e; + e.errorCode = baseException.errorCode; + e.message = baseException.message; + e.rateLimitDuration = baseException.rateLimitDuration; + throw e; + } + + if (baseException.errorCode == EDAMErrorCode::RATE_LIMIT_REACHED) { + EDAMSystemExceptionRateLimitReached e; + e.errorCode = baseException.errorCode; + e.message = baseException.message; + e.rateLimitDuration = baseException.rateLimitDuration; + throw e; + } + + throw baseException; +} + +EverCloudExceptionDataPtr EDAMSystemExceptionRateLimitReached::exceptionData() const +{ + return std::make_shared( + QString::fromUtf8(what()), + errorCode, + message, + rateLimitDuration); +} + +EverCloudExceptionDataPtr EDAMSystemExceptionAuthExpired::exceptionData() const +{ + return std::make_shared( + QString::fromUtf8(what()), + errorCode, + message, + rateLimitDuration); +} + +EDAMSystemExceptionAuthExpiredData::EDAMSystemExceptionAuthExpiredData( + QString error, + EDAMErrorCode errorCode, + Optional message, + Optional rateLimitDuration) : + EDAMSystemExceptionData(error, errorCode, message, rateLimitDuration) +{} + +void EDAMSystemExceptionAuthExpiredData::throwException() const +{ + EDAMSystemExceptionAuthExpired e; + e.errorCode = m_errorCode; + e.message = m_message; + e.rateLimitDuration = m_rateLimitDuration; + throw e; +} + +EDAMUserExceptionData::EDAMUserExceptionData( + QString error, + EDAMErrorCode errorCode, + Optional parameter) : + EvernoteExceptionData(error), + m_errorCode(errorCode), + m_parameter(parameter) +{} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/Globals.cpp b/src/qevercloud/QEverCloud/src/Globals.cpp new file mode 100644 index 00000000..86bd0130 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/Globals.cpp @@ -0,0 +1,123 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace qevercloud { + +namespace { + +//////////////////////////////////////////////////////////////////////////////// + +class EvernoteProxySettingsHolder +{ +public: + EvernoteProxySettingsHolder() = default; + + QNetworkProxy proxy() + { + QReadLocker locker(&m_lock); + + if (m_pProxy) { + return *m_pProxy; + } + + return QNetworkProxy::applicationProxy(); + } + + void setProxy(QNetworkProxy proxy) + { + QWriteLocker locker(&m_lock); + + if (m_pProxy) { + *m_pProxy = std::move(proxy); + } + else { + m_pProxy = std::make_shared(std::move(proxy)); + } + } + + void resetProxy() + { + QWriteLocker locker(&m_lock); + m_pProxy.reset(); + } + +private: + Q_DISABLE_COPY(EvernoteProxySettingsHolder) + +private: + QReadWriteLock m_lock; + std::shared_ptr m_pProxy; +}; + +Q_GLOBAL_STATIC(EvernoteProxySettingsHolder, evernoteProxySettingsHolder) + +//////////////////////////////////////////////////////////////////////////////// + +void registerMetatypes() +{ + qRegisterMetaType("EverCloudExceptionDataPtr"); + qRegisterMetaType("IRequestContextPtr"); +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// + +QNetworkProxy evernoteNetworkProxy() +{ + return evernoteProxySettingsHolder->proxy(); +} + +void setEvernoteNetworkProxy(QNetworkProxy proxy) +{ + evernoteProxySettingsHolder->setProxy(std::move(proxy)); +} + +void resetEvernoteNetworkProxy() +{ + evernoteProxySettingsHolder->resetProxy(); +} + +//////////////////////////////////////////////////////////////////////////////// + +#if defined(QT_WARNING_PUSH) && defined(QT_WARNING_DISABLE_DEPRECATED) && defined(QT_WARNING_POP) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED +#endif + +int libraryVersion() +{ + return qevercloudVersionMajor() * 10000 + qevercloudVersionMinor() * 100 + + qevercloudVersionPatch(); +} + +#if defined(QT_WARNING_PUSH) && defined(QT_WARNING_DISABLE_DEPRECATED) && defined(QT_WARNING_POP) +QT_WARNING_POP +#endif + +//////////////////////////////////////////////////////////////////////////////// + +void initializeQEverCloud() +{ + registerMetatypes(); +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/Http.cpp b/src/qevercloud/QEverCloud/src/Http.cpp new file mode 100644 index 00000000..64b88507 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/Http.cpp @@ -0,0 +1,297 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include "Http.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +/** @cond HIDDEN_SYMBOLS */ + +namespace qevercloud { + +ReplyFetcher::ReplyFetcher(QObject * parent) : + QObject(parent), + m_pTicker(new QTimer(this)) +{ + QObject::connect( + m_pTicker, + &QTimer::timeout, + this, + &ReplyFetcher::checkForTimeout); +} + +void ReplyFetcher::start( + QNetworkAccessManager * pNam, QUrl url, qint64 timeoutMsec) +{ + QNetworkRequest request; + request.setUrl(url); + start(pNam, request, timeoutMsec); +} + +void ReplyFetcher::start( + QNetworkAccessManager * pNam, QNetworkRequest request, qint64 timeoutMsec, + QByteArray postData) +{ + QEC_TRACE("http", "ReplyFetcher started for URL " << request.url() + << ", post data size: " << postData.size()); + + m_pNam = pNam; + + m_httpStatusCode = 0; + m_errorType = QNetworkReply::NoError; + m_errorText.clear(); + m_receivedData.clear(); + + m_lastNetworkTime = QDateTime::currentMSecsSinceEpoch(); + m_timeoutMsec = timeoutMsec; + m_pTicker->start(1000); + + if (postData.isNull()) { + m_pReply = QNetworkReplyPtr(pNam->get(request)); + } + else { + m_pReply = QNetworkReplyPtr(pNam->post(request, postData)); + } + + QObject::connect( + m_pReply.get(), + &QNetworkReply::finished, + this, + &ReplyFetcher::onFinished); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + QObject::connect( + m_pReply.get(), + &QNetworkReply::errorOccurred, + this, + &ReplyFetcher::onError); +#elif QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) + QObject::connect( + m_pReply.get(), + qOverload(&QNetworkReply::error), + this, + &ReplyFetcher::onError); +#else + QObject::connect( + m_pReply.get(), + SIGNAL(error(QNetworkReply::NetworkError)), + this, + SLOT(onError(QNetworkReply::NetworkError))); +#endif + + QObject::connect( + m_pReply.get(), + &QNetworkReply::sslErrors, + this, + &ReplyFetcher::onSslErrors); + + QObject::connect( + m_pReply.get(), + &QNetworkReply::downloadProgress, + this, + &ReplyFetcher::onDownloadProgress); +} + +void ReplyFetcher::onDownloadProgress(qint64 downloaded, qint64 total) +{ + Q_UNUSED(downloaded) + Q_UNUSED(total) + + m_lastNetworkTime = QDateTime::currentMSecsSinceEpoch(); +} + +void ReplyFetcher::checkForTimeout() +{ + if (m_timeoutMsec < 0) { + return; + } + + if ((QDateTime::currentMSecsSinceEpoch() - m_lastNetworkTime) > m_timeoutMsec) { + setError(QNetworkReply::TimeoutError, QStringLiteral("Request timeout")); + } +} + +void ReplyFetcher::onFinished() +{ + QEC_TRACE("http", "ReplyFetcher finished") + + m_pTicker->stop(); + + if (m_errorType != QNetworkReply::NoError) { + return; + } + + m_receivedData = m_pReply->readAll(); + m_httpStatusCode = m_pReply->attribute( + QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + QObject::disconnect(m_pReply.get()); + Q_EMIT replyFetched(this); +} + +void ReplyFetcher::onError(QNetworkReply::NetworkError error) +{ + QEC_WARNING("http", "ReplyFetcher error: code = " + << error << ", description: " << m_pReply->errorString() + << "; http status code: " << m_pReply->attribute( + QNetworkRequest::HttpStatusCodeAttribute).toInt()); + + setError(error, m_pReply->errorString()); +} + +void ReplyFetcher::onSslErrors(QList errors) +{ + QString errorText = QStringLiteral("SSL Errors:\n"); + + for(int i = 0, numErrors = errors.size(); i < numErrors; ++i) { + const QSslError & error = errors[i]; + errorText += error.errorString().append(QStringLiteral("\n")); + } + + QEC_WARNING("http", errorText); + setError(QNetworkReply::SslHandshakeFailedError, errorText); +} + +void ReplyFetcher::setError( + QNetworkReply::NetworkError errorType, QString errorText) +{ + m_pTicker->stop(); + m_errorType = errorType; + m_errorText = errorText; + QObject::disconnect(m_pReply.get()); + Q_EMIT replyFetched(this); +} + +//////////////////////////////////////////////////////////////////////////////// + +ReplyFetcherLauncher::ReplyFetcherLauncher( + ReplyFetcher * fetcher, + QNetworkAccessManager * nam, + const QNetworkRequest & request, + const qint64 timeoutMsec, + const QByteArray & postData) : + QObject(nam), + m_pFetcher(fetcher), + m_pNam(nam), + m_request(request), + m_timeoutMsec(timeoutMsec), + m_postData(postData) +{} + +void ReplyFetcherLauncher::start() +{ + m_pFetcher->start(m_pNam, m_request, m_timeoutMsec, m_postData); +} + +//////////////////////////////////////////////////////////////////////////////// + +QByteArray simpleDownload( + QNetworkRequest request, const qint64 timeoutMsec, + QByteArray postData, int * pHttpStatusCode) +{ + auto * pFetcher = new ReplyFetcher; + + auto * pNam = new QNetworkAccessManager(pFetcher); + pNam->setProxy(evernoteNetworkProxy()); + + QEventLoop loop; + QObject::connect( + pFetcher, + &ReplyFetcher::replyFetched, + &loop, + [&loop](ReplyFetcher * rf) + { + Q_UNUSED(rf); + loop.quit(); + }); + + auto * fetcherLauncher = new ReplyFetcherLauncher( + pFetcher, + pNam, + request, + timeoutMsec, + postData); + + QTimer::singleShot(0, fetcherLauncher, SLOT(start())); + loop.exec(QEventLoop::ExcludeUserInputEvents); + + fetcherLauncher->deleteLater(); + + if (pHttpStatusCode) { + *pHttpStatusCode = pFetcher->httpStatusCode(); + } + + if (pFetcher->isError()) { + auto errorType = pFetcher->errorType(); + QString errorText = pFetcher->errorText(); + pFetcher->deleteLater(); + throw NetworkException(errorType, errorText); + } + + QByteArray receivedData = pFetcher->receivedData(); + pFetcher->deleteLater(); + return receivedData; +} + +QNetworkRequest createEvernoteRequest( + QString url, QList cookies) +{ + QNetworkRequest request; + request.setUrl(url); + request.setHeader( + QNetworkRequest::ContentTypeHeader, + QStringLiteral("application/x-thrift")); + + request.setHeader( + QNetworkRequest::UserAgentHeader, + QString::fromUtf8("QEverCloud %1.%2.%3") + .arg(qevercloudVersionMajor()) + .arg(qevercloudVersionMinor()) + .arg(qevercloudVersionPatch())); + + request.setRawHeader("Accept", "application/x-thrift"); + + if (!cookies.isEmpty()) { + request.setHeader( + QNetworkRequest::CookieHeader, QVariant::fromValue(cookies)); + } + + return request; +} + +QByteArray askEvernote( + QString url, QByteArray postData, const qint64 timeoutMsec, + QList cookies) +{ + int httpStatusCode = 0; + QByteArray reply = simpleDownload( + createEvernoteRequest(url, std::move(cookies)), + timeoutMsec, + postData, + &httpStatusCode); + + if (httpStatusCode != 200) { + throw EverCloudException( + QString::fromUtf8("HTTP Status Code = %1").arg(httpStatusCode)); + } + + return reply; +} + +} // namespace qevercloud + +/** @endcond */ diff --git a/src/qevercloud/QEverCloud/src/Http.h b/src/qevercloud/QEverCloud/src/Http.h new file mode 100644 index 00000000..647a31a2 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/Http.h @@ -0,0 +1,168 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_HTTP_H +#define QEVERCLOUD_HTTP_H + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/** @cond HIDDEN_SYMBOLS */ + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +/** + * @brief The ReplyFetcher class simplifies handling of QNetworkReply + */ +class ReplyFetcher: public QObject +{ + Q_OBJECT +public: + ReplyFetcher(QObject * parent = nullptr); + + void start(QNetworkAccessManager * nam, QUrl url, qint64 timeoutMsec); + + // if !postData.isNull() then POST will be issued instead of GET + void start( + QNetworkAccessManager * nam, QNetworkRequest request, + qint64 timeoutMsec, QByteArray postData = QByteArray()); + + bool isError() const + { + return m_errorType != QNetworkReply::NoError; + } + + QNetworkReply::NetworkError errorType() const + { + return m_errorType; + } + + QString errorText() const + { + return m_errorText; + } + + QByteArray receivedData() const + { + return m_receivedData; + } + + int httpStatusCode() const + { + return m_httpStatusCode; + } + + QNetworkAccessManager * networkAccessManager() + { + if (!m_pNam.isNull()) { + return m_pNam.data(); + } + else { + return nullptr; + } + } + +Q_SIGNALS: + void replyFetched(ReplyFetcher * pSelf); // sends itself + +private Q_SLOTS: + void onFinished(); + void onError(QNetworkReply::NetworkError); + void onSslErrors(QList list); + void onDownloadProgress(qint64 downloaded, qint64 total); + void checkForTimeout(); + +private: + void setError(QNetworkReply::NetworkError errorType, QString errorText); + +private: + struct QNetworkReplyDeleter + { + void operator()(QNetworkReply * pReply) + { + pReply->deleteLater(); + } + }; + + using QNetworkReplyPtr = std::unique_ptr; + +private: + QPointer m_pNam; + + QNetworkReplyPtr m_pReply; + + QNetworkReply::NetworkError m_errorType = QNetworkReply::NoError; + QString m_errorText; + QByteArray m_receivedData; + int m_httpStatusCode = 0; + + QTimer * m_pTicker = nullptr; + qint64 m_lastNetworkTime = 0; + qint64 m_timeoutMsec = 0; +}; + +//////////////////////////////////////////////////////////////////////////////// + +QNetworkRequest createEvernoteRequest( + QString url, QList cookies); + +QByteArray askEvernote( + QString url, QByteArray postData, const qint64 timeoutMsec, + QList cookies = {}); + +QByteArray simpleDownload( + QNetworkRequest request, const qint64 timeoutMsec, + QByteArray postData = {}, int * pHttpStatusCode = nullptr); + +//////////////////////////////////////////////////////////////////////////////// + +/** + * @brief The ReplyFetcherLauncher class simplifies ReplyFetcher starting + */ +class ReplyFetcherLauncher: public QObject +{ + Q_OBJECT +public: + explicit ReplyFetcherLauncher( + ReplyFetcher * pFetcher, QNetworkAccessManager * pNam, + const QNetworkRequest & request, const qint64 timeoutMsec, + const QByteArray & postData); + +public Q_SLOTS: + void start(); + +private: + ReplyFetcher * m_pFetcher = nullptr; + QNetworkAccessManager * m_pNam = nullptr; + QNetworkRequest m_request; + qint64 m_timeoutMsec = 0; + QByteArray m_postData; +}; + +} // namespace qevercloud + +/** @endcond */ + +#endif // QEVERCLOUD_HTTP_H diff --git a/src/qevercloud/QEverCloud/src/HttpRequestData.h b/src/qevercloud/QEverCloud/src/HttpRequestData.h new file mode 100644 index 00000000..4b9d7465 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/HttpRequestData.h @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_HTTP_REQUEST_DATA_H +#define QEVERCLOUD_HTTP_REQUEST_DATA_H + +#include + +/** @cond HIDDEN_SYMBOLS */ + +namespace qevercloud { + +// (Incomplete) data from HTTP request parsed from data read from QTcpSocket +struct HttpRequestData +{ + enum class Method + { + GET, + POST + }; + + Method method = Method::POST; + QByteArray uri; + QByteArray body; +}; + +} // namespace qevercloud + +/** @endcond */ + +#endif // QEVERCLOUD_HTTP_REQUEST_DATA_H diff --git a/src/qevercloud/QEverCloud/src/HttpRequestParser.cpp b/src/qevercloud/QEverCloud/src/HttpRequestParser.cpp new file mode 100644 index 00000000..589ff9b1 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/HttpRequestParser.cpp @@ -0,0 +1,154 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include "HttpRequestParser.h" + +#include + +#include + +namespace qevercloud { + +HttpRequestParser::HttpRequestParser(QTcpSocket & socket, QObject * parent) : + QObject(parent) +{ + QObject::connect( + &socket, + &QIODevice::readyRead, + this, + &HttpRequestParser::onSocketReadyRead, + Qt::QueuedConnection); +} + +bool HttpRequestParser::status() const noexcept +{ + return m_status; +} + +const QByteArray & HttpRequestParser::data() const noexcept +{ + return m_requestData.body; +} + +HttpRequestData HttpRequestParser::requestData() const +{ + return m_requestData; +} + +void HttpRequestParser::onSocketReadyRead() +{ + QTcpSocket * pSocket = qobject_cast(sender()); + Q_ASSERT(pSocket); + + m_data.append(pSocket->read(pSocket->bytesAvailable())); + tryParseData(); +} + +void HttpRequestParser::tryParseData() +{ + // Data read from socket should be a HTTP request with headers and body. + // Maybe incomplete in which case we postpone the attempt to parse + // the request. + + // The first line of a HTTP request should be the request line: + // methodrequest-urihttp-version + int methodEndIndex = m_data.indexOf(" "); + if (methodEndIndex < 0) { + // No first space symbol, probably not all data has arrived yet + return; + } + + const QByteArray method{m_data.constData(), methodEndIndex}; + if (method == QByteArray::fromRawData("GET", 3)) + { + m_requestData.method = HttpRequestData::Method::GET; + } + else if (method == QByteArray::fromRawData("POST", 4)) + { + m_requestData.method = HttpRequestData::Method::POST; + } + + int resourceUriEndIndex = m_data.indexOf(" ", methodEndIndex + 1); + if (resourceUriEndIndex < 0) { + // No resource URI end index, probably not all data has arrived yet + return; + } + + m_requestData.uri = QByteArray{ + m_data.constData() + methodEndIndex + 1, + resourceUriEndIndex - methodEndIndex - 1}; + + if (m_requestData.method == HttpRequestData::Method::GET) + { + // GET requests don't include Content-Length header so we need to look + // for two consequent carriage returns with nothing in between them + // to determine that the whole HTTP request has been received. + const int requestEndIndex = + m_data.indexOf("\r\n\r\n", resourceUriEndIndex + 1); + if (requestEndIndex < 0) { + return; + } + + m_status = true; + Q_EMIT finished(); + return; + } + + // For POST request will parse headers, find Content-Length one to figure + // out the size of request body + int contentLengthIndex = + m_data.indexOf("Content-Length:", resourceUriEndIndex + 1); + if (contentLengthIndex < 0) { + // No Content-Length header, probably not all data has arrived yet + return; + } + + int contentLengthLineEndIndex = m_data.indexOf("\r\n", contentLengthIndex); + if (contentLengthLineEndIndex < 0) { + // No line end after Content-Length header, probably not all data + // has arrived yet + return; + } + + int contentLengthLen = contentLengthLineEndIndex - contentLengthIndex - 15; + QString contentLengthStr = + QString::fromUtf8(m_data.mid(contentLengthIndex + 15, contentLengthLen)); + + bool conversionResult = false; + int contentLength = contentLengthStr.toInt(&conversionResult); + if (Q_UNLIKELY(!conversionResult)) { + QEC_WARNING( + "http", + "Failed to convert content length header value to int: " + << contentLengthStr); + m_status = false; + Q_EMIT failed(); + return; + } + + // Now see whether whole body data is present + int headersEndIndex = m_data.indexOf("\r\n\r\n", contentLengthLineEndIndex); + if (headersEndIndex < 0) { + // No empty line after http headers, probably not all data has + // arrived yet + return; + } + + QByteArray body = m_data; + body.remove(0, headersEndIndex + 4); + if (body.size() < contentLength) { + // Not all data has arrived yet + return; + } + + m_requestData.body = body; + m_status = true; + Q_EMIT finished(); +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/HttpRequestParser.h b/src/qevercloud/QEverCloud/src/HttpRequestParser.h new file mode 100644 index 00000000..7d544b23 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/HttpRequestParser.h @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_HTTP_REQUEST_PARSER_H +#define QEVERCLOUD_HTTP_REQUEST_PARSER_H + +#include "HttpRequestData.h" + +#include + +QT_BEGIN_NAMESPACE + +class QTcpSocket; + +QT_END_NAMESPACE + +namespace qevercloud { + +// Simplistic parser of HTTP request data from QTcpSocket +class HttpRequestParser: public QObject +{ + Q_OBJECT +public: + explicit HttpRequestParser(QTcpSocket & socket, QObject * parent = nullptr); + + [[nodiscard]] bool status() const noexcept; + + [[nodiscard]] const QByteArray & data() const noexcept; + + [[nodiscard]] HttpRequestData requestData() const; + +Q_SIGNALS: + void finished(); + void failed(); + +private Q_SLOTS: + void onSocketReadyRead(); + +private: + void tryParseData(); + +private: + bool m_status = false; + HttpRequestData m_requestData; + QByteArray m_data; +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_HTTP_REQUEST_PARSER_H diff --git a/src/qevercloud/QEverCloud/src/HttpUtils.cpp b/src/qevercloud/QEverCloud/src/HttpUtils.cpp new file mode 100644 index 00000000..48b89253 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/HttpUtils.cpp @@ -0,0 +1,76 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include "HttpUtils.h" + +#include "HttpRequestParser.h" + +#include +#include + +namespace qevercloud { + +HttpRequestData readRequestDataFromSocket(QTcpSocket & socket) +{ + if (!socket.waitForConnected()) { + return {}; + } + + QEventLoop loop; + HttpRequestParser extractor(socket); + + QObject::connect( + &extractor, + &HttpRequestParser::finished, + &loop, + &QEventLoop::quit); + + QObject::connect( + &extractor, + &HttpRequestParser::failed, + &loop, + &QEventLoop::quit); + + loop.exec(); + + if (!extractor.status()) { + return {}; + } + + return extractor.requestData(); +} + +QByteArray readRequestBodyFromSocket(QTcpSocket & socket) +{ + return readRequestDataFromSocket(socket).body; +} + +bool writeBufferToSocket(const QByteArray & data, QTcpSocket & socket) +{ + int remaining = data.size(); + const char * pData = data.constData(); + while(socket.isOpen() && remaining>0) + { + // If the output buffer has become large, then wait until it has been sent. + if (socket.bytesToWrite() > 16384) + { + socket.waitForBytesWritten(-1); + } + + qint64 written = socket.write(pData, remaining); + if (written < 0) { + return false; + } + + pData += written; + remaining -= written; + } + return true; +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/HttpUtils.h b/src/qevercloud/QEverCloud/src/HttpUtils.h new file mode 100644 index 00000000..3526129f --- /dev/null +++ b/src/qevercloud/QEverCloud/src/HttpUtils.h @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_HTTP_UTILS_H +#define QEVERCLOUD_HTTP_UTILS_H + +#include "HttpRequestData.h" + +QT_BEGIN_NAMESPACE + +class QTcpSocket; + +QT_END_NAMESPACE + +namespace qevercloud { + +[[nodiscard]] HttpRequestData readRequestDataFromSocket(QTcpSocket & socket); + +[[nodiscard]] QByteArray readRequestBodyFromSocket(QTcpSocket & socket); + +[[nodiscard]] bool writeBufferToSocket( + const QByteArray & data, QTcpSocket & socket); + +} // namespace qevercloud + +#endif // QEVERCLOUD_HTTP_UTILS_H diff --git a/src/qevercloud/QEverCloud/src/impl.h b/src/qevercloud/QEverCloud/src/Impl.h similarity index 65% rename from src/qevercloud/QEverCloud/src/impl.h rename to src/qevercloud/QEverCloud/src/Impl.h index ca566c5b..356ec014 100644 --- a/src/qevercloud/QEverCloud/src/impl.h +++ b/src/qevercloud/QEverCloud/src/Impl.h @@ -1,29 +1,33 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: * https://opensource.org/licenses/MIT */ #ifndef QEVERCLOUD_IMPL_H #define QEVERCLOUD_IMPL_H +#include "Http.h" +#include "Thrift.h" + +#include +#include #include -#include -#include -#include "http.h" -#include "thrift.h" /** @mainpage About QEverCloud This library presents complete Evernote SDK for Qt. -All the functionality that is described on Evernote site +All the functionality that is described on +Evernote site is implemented and ready to use. In particular OAuth autentication is implemented. -Include *QEverCloud.h* or *QEverCloudOAuth.h* to use the library. The latter header is needed if you use OAuth functionality. +Include *QEverCloud.h* or *QEverCloudOAuth.h* to use the library. The latter +header is needed if you use OAuth functionality. QEverCloud on GitHub @@ -35,6 +39,9 @@ namespace qevercloud { ThriftException readThriftException(ThriftBinaryBufferReader & reader); +void writeThriftException( + ThriftBinaryBufferWriter & writer, const ThriftException & exception); + void throwEDAMSystemException(const EDAMSystemException & baseException); /** @endcond */ diff --git a/src/qevercloud/QEverCloud/src/InkNoteImageDownloader.cpp b/src/qevercloud/QEverCloud/src/InkNoteImageDownloader.cpp index 20f0422a..f9920032 100644 --- a/src/qevercloud/QEverCloud/src/InkNoteImageDownloader.cpp +++ b/src/qevercloud/QEverCloud/src/InkNoteImageDownloader.cpp @@ -1,25 +1,34 @@ /** - * Copyright (c) 2016 Dmitry Ivanov + * Copyright (c) 2016-2020 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: * https://opensource.org/licenses/MIT */ +#include "Http.h" + +#include +#include #include -#include -#include "http.h" -#include +#include + +#include #include #include -#include +#include + +#include +#include namespace qevercloud { class InkNoteImageDownloaderPrivate { public: - QPair createPostRequest(const QString & urlPart, - const int sliceNumber, const bool isPublic = false); + std::pair createPostRequest( + const QString & urlPart, const int sliceNumber, + const bool isPublic = false); QString m_host; QString m_shardId; @@ -32,8 +41,9 @@ InkNoteImageDownloader::InkNoteImageDownloader() : d_ptr(new InkNoteImageDownloaderPrivate) {} -InkNoteImageDownloader::InkNoteImageDownloader(QString host, QString shardId, QString authenticationToken, - int width, int height) : +InkNoteImageDownloader::InkNoteImageDownloader( + QString host, QString shardId, QString authenticationToken, + int width, int height) : d_ptr(new InkNoteImageDownloaderPrivate) { d_ptr->m_host = host; @@ -60,7 +70,8 @@ InkNoteImageDownloader & InkNoteImageDownloader::setShardId(QString shardId) return *this; } -InkNoteImageDownloader & InkNoteImageDownloader::setAuthenticationToken(QString authenticationToken) +InkNoteImageDownloader & InkNoteImageDownloader::setAuthenticationToken( + QString authenticationToken) { d_ptr->m_authenticationToken = authenticationToken; return *this; @@ -78,8 +89,12 @@ InkNoteImageDownloader & InkNoteImageDownloader::setHeight(int height) return *this; } -QByteArray InkNoteImageDownloader::download(Guid guid, bool isPublic) +QByteArray InkNoteImageDownloader::download( + Guid guid, const bool isPublic, const qint64 timeoutMsec) { + QEC_DEBUG("ink_note_image", "Downloading ink note image: guid = " << guid + << (isPublic ? "public" : "non-public")); + Q_D(InkNoteImageDownloader); QSize size(d_ptr->m_width, d_ptr->m_height); @@ -93,20 +108,38 @@ QByteArray InkNoteImageDownloader::download(Guid guid, bool isPublic) while(true) { int httpStatusCode = 0; - QPair postRequest = d->createPostRequest(urlPart, sliceCounter, isPublic); + auto postRequest = d->createPostRequest(urlPart, sliceCounter, isPublic); + + QEC_DEBUG("ink_note_image", "Sending download request to url: " + << postRequest.first.url()); + + QByteArray reply = simpleDownload( + postRequest.first, + timeoutMsec, + postRequest.second, + &httpStatusCode); - QByteArray reply = simpleDownload(evernoteNetworkAccessManager(), postRequest.first, - postRequest.second, &httpStatusCode); if (httpStatusCode != 200) { - throw EverCloudException(QStringLiteral("HTTP Status Code = %1").arg(httpStatusCode)); + QEC_WARNING("ink_note_image", "Failed to download slice " + << sliceCounter << " for guid " << guid + << ": http status code = " << httpStatusCode); + + throw EverCloudException( + QStringLiteral("HTTP Status Code = %1").arg(httpStatusCode)); } QImage replyImagePart; Q_UNUSED(replyImagePart.loadFromData(reply, "PNG")) if (replyImagePart.isNull()) { - if (Q_UNLIKELY(inkNoteImage.isNull())) { - throw EverCloudException(QStringLiteral("Ink note's image part is null before even starting to assemble")); + if (Q_UNLIKELY(inkNoteImage.isNull())) + { + QEC_WARNING("ink_note_image", "Failed to read downloaded data " + << "as a png image"); + + throw EverCloudException( + QStringLiteral("Ink note's image part is null before even " + "starting to assemble")); } break; @@ -116,7 +149,12 @@ QByteArray InkNoteImageDownloader::download(Guid guid, bool isPublic) inkNoteImage = inkNoteImage.convertToFormat(replyImagePart.format()); } - QRect painterCurrentRect(0, painterPosition, replyImagePart.width(), replyImagePart.height()); + QRect painterCurrentRect( + 0, + painterPosition, + replyImagePart.width(), + replyImagePart.height()); + painterPosition += replyImagePart.height(); QPainter painter(&inkNoteImage); @@ -126,6 +164,8 @@ QByteArray InkNoteImageDownloader::download(Guid guid, bool isPublic) if (painterPosition >= size.height()) { break; } + + ++sliceCounter; } if (inkNoteImage.isNull()) { @@ -136,23 +176,29 @@ QByteArray InkNoteImageDownloader::download(Guid guid, bool isPublic) QBuffer buffer(&imageData); Q_UNUSED(buffer.open(QIODevice::WriteOnly)) inkNoteImage.save(&buffer, "PNG"); + + QEC_DEBUG("ink_note_image", "Finished download for guid " << guid); return imageData; } -QPair InkNoteImageDownloaderPrivate::createPostRequest(const QString & urlPart, - const int sliceNumber, - const bool isPublic) +std::pair +InkNoteImageDownloaderPrivate::createPostRequest( + const QString & urlPart, const int sliceNumber, const bool isPublic) { QNetworkRequest request; request.setUrl(QUrl(urlPart + QString::number(sliceNumber))); - request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-www-form-urlencoded")); + request.setHeader( + QNetworkRequest::ContentTypeHeader, + QStringLiteral("application/x-www-form-urlencoded")); - QByteArray postData = ""; // not QByteArray()! or else ReplyFetcher will not work. + // not QByteArray()! or else ReplyFetcher will not work. + QByteArray postData = ""; if (!isPublic) { - postData = QByteArray("auth=")+ QUrl::toPercentEncoding(m_authenticationToken); + postData = QByteArray("auth=") + + QUrl::toPercentEncoding(m_authenticationToken); } - return qMakePair(request, postData); + return std::make_pair(request, postData); } } // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/Log.cpp b/src/qevercloud/QEverCloud/src/Log.cpp new file mode 100644 index 00000000..c1586855 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/Log.cpp @@ -0,0 +1,231 @@ +/** + * Copyright (c) 2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#include + +#include + +#include +#include +#include +#include + +namespace qevercloud { + +namespace { + +//////////////////////////////////////////////////////////////////////////////// + +Q_GLOBAL_STATIC(ILoggerPtr, globalLogger) + +//////////////////////////////////////////////////////////////////////////////// + +template +void printLogLevel(T & out, const LogLevel level) +{ + switch(level) + { + case LogLevel::Trace: + out << "Trace"; + break; + case LogLevel::Debug: + out << "Debug"; + break; + case LogLevel::Info: + out << "Info"; + break; + case LogLevel::Warn: + out << "Warn"; + break; + case LogLevel::Error: + out << "Error"; + break; + default: + out << "Unknown (" << static_cast(level) << ")"; + break; + } +} + +//////////////////////////////////////////////////////////////////////////////// + +class NullLogger final: public ILogger +{ +public: + virtual bool shouldLog( + const LogLevel level, const char * component) const override + { + Q_UNUSED(level) + Q_UNUSED(component) + return false; + } + + virtual void log( + const LogLevel level, const char * component, const char * fileName, + const quint32 lineNumber, const qint64 timestamp, + const QString & message) override + { + Q_UNUSED(level) + Q_UNUSED(component) + Q_UNUSED(fileName) + Q_UNUSED(lineNumber) + Q_UNUSED(timestamp) + Q_UNUSED(message) + } + + virtual void setLevel(const LogLevel level) override + { + m_level.store(static_cast(level)); + } + + virtual LogLevel level() const override + { + return static_cast(m_level.load()); + } + +private: + std::atomic m_level; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class StdErrLogger final: public ILogger +{ +public: + StdErrLogger(LogLevel level) : + m_cerr(stderr), + m_level(static_cast(level)) + {} + + virtual bool shouldLog( + const LogLevel level, const char * component) const override + { + Q_UNUSED(component) + return (static_cast(level) >= m_level); + } + + virtual void log( + const LogLevel level, const char * component, const char * fileName, + const quint32 lineNumber, const qint64 timestamp, + const QString & message) override + { + if (!shouldLog(level, component)) { + return; + } + + printTimestamp(timestamp); + + m_cerr << "\t" << static_cast(m_level.load()) + << "\t[" << component << "] " + << fileName << ":" << lineNumber << " " + << message << "\n"; + m_cerr.flush(); + } + + virtual void setLevel(const LogLevel level) override + { + m_level.store(static_cast(level)); + } + + virtual LogLevel level() const override + { + return static_cast(m_level.load()); + } + +private: + void printTimestamp(const qint64 timestamp) + { + std::time_t t(timestamp / 1000); + std::tm localTm; + Q_UNUSED(localTm) + std::tm * tm = Q_NULLPTR; + +#ifdef _MSC_VER + // MSVC's localtime is thread-safe since MSVC 2005 + tm = std::localtime(&t); +#else // ifdef _MSC_VER +#ifdef __MINGW32__ + // MinGW lacks localtime_r but uses MS's localtime instead which is told to + // be thread-safe but it's still not re-entrant. + // So, can at best hope it won't cause problems too often + tm = localtime(&t); +#else // POSIX + tm = &localTm; + Q_UNUSED(localtime_r(&t, tm)) +#endif +#endif // ifdef _MSC_VER + + const size_t maxBufSize = 100; + char buffer[maxBufSize]; + const char * format = "%Y-%m-%d %H:%M:%S"; + size_t size = strftime(buffer, maxBufSize, format, tm); + + m_cerr << QString::fromLocal8Bit(buffer, static_cast(size)); + + qint64 msecPart = timestamp - t * 1000; + m_cerr << "."; + m_cerr << QString::fromUtf8("%1").arg(msecPart, 3, 10, QChar::fromLatin1('0')); + +#if !defined(_MSC_VER) && !defined(__MINGW32__) + const char * timezone = tm->tm_zone; + if (timezone) { + m_cerr << " "; + m_cerr << QString::fromLocal8Bit(timezone); + } +#endif + } + +private: + QTextStream m_cerr; + std::atomic m_level; +}; + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// + +ILoggerPtr logger() +{ + if (globalLogger.exists() && + !globalLogger.isDestroyed() && + (globalLogger->get() != nullptr)) + { + return *globalLogger; + } + + return nullLogger(); +} + +void setLogger(ILoggerPtr logger) +{ + if (!globalLogger.isDestroyed()) { + *globalLogger = logger; + } +} + +ILoggerPtr nullLogger() +{ + return std::make_shared(); +} + +ILoggerPtr newStdErrLogger(LogLevel level) +{ + return std::make_shared(level); +} + +QTextStream & operator<<(QTextStream & out, const LogLevel level) +{ + printLogLevel(out, level); + return out; +} + +QDebug & operator<<(QDebug & out, const LogLevel level) +{ + printLogLevel(out, level); + return out; +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/NetworkCookieJar.cpp b/src/qevercloud/QEverCloud/src/NetworkCookieJar.cpp new file mode 100644 index 00000000..db47cb44 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/NetworkCookieJar.cpp @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include "NetworkCookieJar.h" + +#if QEVERCLOUD_USE_QT_WEB_ENGINE +#include +#include +#endif + +namespace qevercloud { + +#if QEVERCLOUD_USE_QT_WEB_ENGINE +void NetworkCookieJar::loadStore() +{ + auto * pProfile = QWebEngineProfile::defaultProfile(); + auto * pCookieStore = pProfile->cookieStore(); + + QObject::connect( + pCookieStore, + &QWebEngineCookieStore::cookieAdded, + this, + &NetworkCookieJar::handleCookieAdded, + Qt::ConnectionType(Qt::UniqueConnection | Qt::DirectConnection)); + + pCookieStore->loadAllCookies(); +} + +void NetworkCookieJar::handleCookieAdded(const QNetworkCookie & cookie) +{ + Q_UNUSED(QNetworkCookieJar::insertCookie(cookie)) +} +#endif + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/NetworkCookieJar.h b/src/qevercloud/QEverCloud/src/NetworkCookieJar.h new file mode 100644 index 00000000..822e694d --- /dev/null +++ b/src/qevercloud/QEverCloud/src/NetworkCookieJar.h @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include +#include + +namespace qevercloud { + +/** + * @brief The NetworkCookieJar class is a small class subclassing from + * QNetworkCookieJar and exposing its protected members. + * + * When QEverCloud uses QtWebEngine, this class is also capable of collecting + * cookies from QtWebEngine's default profile + */ +class NetworkCookieJar: public QNetworkCookieJar +{ + Q_OBJECT +public: + explicit NetworkCookieJar(QObject * parent = nullptr) : + QNetworkCookieJar(parent) + {} + + QList allCookies() + { + return QNetworkCookieJar::allCookies(); + } + + void setAllCookies(QList cookies) + { + QNetworkCookieJar::setAllCookies(std::move(cookies)); + } + +#if QEVERCLOUD_USE_QT_WEB_ENGINE + void loadStore(); + +private Q_SLOTS: + void handleCookieAdded(const QNetworkCookie & cookie); +#endif +}; + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/Printable.cpp b/src/qevercloud/QEverCloud/src/Printable.cpp new file mode 100644 index 00000000..293ce03b --- /dev/null +++ b/src/qevercloud/QEverCloud/src/Printable.cpp @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#include + +namespace qevercloud { + +QString Printable::toString() const +{ + QString str; + QTextStream strm(&str, QIODevice::WriteOnly); + strm << *this; + return str; +} + +QTextStream & operator<<(QTextStream & strm, const Printable & printable) +{ + printable.print(strm); + return strm; +} + +QDebug & operator<<(QDebug & dbg, const Printable & printable) +{ + QString str; + QTextStream strm(&str); + printable.print(strm); + + dbg << str; + return dbg; +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/RequestContext.cpp b/src/qevercloud/QEverCloud/src/RequestContext.cpp new file mode 100644 index 00000000..a54eb200 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/RequestContext.cpp @@ -0,0 +1,147 @@ +/** + * Copyright (c) 2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#include + +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +class Q_DECL_HIDDEN RequestContext final: public IRequestContext +{ +public: + RequestContext(QString authenticationToken, qint64 requestTimeout, + bool increaseRequestTimeoutExponentially, + qint64 maxRequestTimeout, + quint32 maxRequestRetryCount, + QList cookies) : + m_requestId(QUuid::createUuid()), + m_authenticationToken(std::move(authenticationToken)), + m_requestTimeout(requestTimeout), + m_increaseRequestTimeoutExponentially(increaseRequestTimeoutExponentially), + m_maxRequestTimeout(maxRequestTimeout), + m_maxRequestRetryCount(maxRequestRetryCount), + m_cookies(std::move(cookies)) + {} + + virtual QUuid requestId() const override + { + return m_requestId; + } + + virtual QString authenticationToken() const override + { + return m_authenticationToken; + } + + virtual qint64 requestTimeout() const override + { + return m_requestTimeout; + } + + virtual bool increaseRequestTimeoutExponentially() const override + { + return m_increaseRequestTimeoutExponentially; + } + + virtual qint64 maxRequestTimeout() const override + { + return m_maxRequestTimeout; + } + + virtual quint32 maxRequestRetryCount() const override + { + return m_maxRequestRetryCount; + } + + virtual QList cookies() const override + { + return m_cookies; + } + + virtual IRequestContext * clone() const override + { + return new RequestContext( + m_authenticationToken, + m_requestTimeout, + m_increaseRequestTimeoutExponentially, + m_maxRequestTimeout, + m_maxRequestRetryCount, + m_cookies); + } + +private: + QUuid m_requestId; + QString m_authenticationToken; + qint64 m_requestTimeout; + bool m_increaseRequestTimeoutExponentially; + qint64 m_maxRequestTimeout; + quint32 m_maxRequestRetryCount; + + QList m_cookies; +}; + +//////////////////////////////////////////////////////////////////////////////// + +template +void printRequestContext(const IRequestContext & ctx, T & strm) +{ + strm << "RequestContext:\n" + << " authentication token = " << ctx.authenticationToken() << "\n" + << " request timeout = " << ctx.requestTimeout() << "\n" + << " increase request timeout exponentially = " + << (ctx.increaseRequestTimeoutExponentially() ? "yes" : "no") << "\n" + << " max request timeout = " << ctx.maxRequestTimeout() << "\n" + << " max request retry count = " << ctx.maxRequestRetryCount() + << "\n"; + + const auto cookies = ctx.cookies(); + if (!cookies.isEmpty()) + { + strm << " cookies: " << "\n"; + + for(const auto & cookie: qAsConst(cookies)) { + strm << " " << QString::fromUtf8(cookie.toRawForm()) << "\n"; + } + } +} + + +QTextStream & operator<<(QTextStream & strm, const IRequestContext & ctx) +{ + printRequestContext(ctx, strm); + return strm; +} + +QDebug & operator<<(QDebug & dbg, const IRequestContext & ctx) +{ + printRequestContext(ctx, dbg); + return dbg; +} + +//////////////////////////////////////////////////////////////////////////////// + +IRequestContextPtr newRequestContext( + QString authenticationToken, + qint64 requestTimeout, + bool increaseRequestTimeoutExponentially, + qint64 maxRequestTimeout, + quint32 maxRequestRetryCount, + QList cookies) +{ + return std::make_shared( + std::move(authenticationToken), + requestTimeout, + increaseRequestTimeoutExponentially, + maxRequestTimeout, + maxRequestRetryCount, + std::move(cookies)); +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/thrift.h b/src/qevercloud/QEverCloud/src/Thrift.h similarity index 69% rename from src/qevercloud/QEverCloud/src/thrift.h rename to src/qevercloud/QEverCloud/src/Thrift.h index 97638a21..cfeb24ab 100644 --- a/src/qevercloud/QEverCloud/src/thrift.h +++ b/src/qevercloud/QEverCloud/src/Thrift.h @@ -1,23 +1,28 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: * https://opensource.org/licenses/MIT */ #ifndef QEVERCLOUD_THRIFT_H #define QEVERCLOUD_THRIFT_H -#include -#include +#include +#include + #include #include + #include #include namespace qevercloud { +//////////////////////////////////////////////////////////////////////////////// + // Use this to get around strict aliasing rules. // For example, uint64_t i = bitwise_cast(returns_double()); // The most obvious implementation is to just cast a pointer, @@ -61,45 +66,47 @@ static inline To bitwise_cast(From from) return u.t; } -struct ThriftFieldType +//////////////////////////////////////////////////////////////////////////////// + +enum class ThriftFieldType { - enum type - { - T_STOP = 0, - T_VOID = 1, - T_BOOL = 2, - T_BYTE = 3, - T_I08 = 3, - T_I16 = 6, - T_I32 = 8, - T_U64 = 9, - T_I64 = 10, - T_DOUBLE = 4, - T_STRING = 11, - T_UTF7 = 11, - T_STRUCT = 12, - T_MAP = 13, - T_SET = 14, - T_LIST = 15, - T_UTF8 = 16, - T_UTF16 = 17 - }; + T_STOP = 0, + T_VOID = 1, + T_BOOL = 2, + T_BYTE = 3, + T_I08 = 3, + T_I16 = 6, + T_I32 = 8, + T_U64 = 9, + T_I64 = 10, + T_DOUBLE = 4, + T_STRING = 11, + T_UTF7 = 11, + T_STRUCT = 12, + T_MAP = 13, + T_SET = 14, + T_LIST = 15, + T_UTF8 = 16, + T_UTF16 = 17 }; -struct ThriftMessageType +//////////////////////////////////////////////////////////////////////////////// + +enum class ThriftMessageType { - enum type - { - T_CALL = 1, - T_REPLY = 2, - T_EXCEPTION = 3, - T_ONEWAY = 4 - }; + T_CALL = 1, + T_REPLY = 2, + T_EXCEPTION = 3, + T_ONEWAY = 4 }; +//////////////////////////////////////////////////////////////////////////////// + static const qint32 VERSION_1 = ((qint32)0x80010000); static const qint32 VERSION_MASK = ((qint32)0xffff0000); +//////////////////////////////////////////////////////////////////////////////// + class ThriftBinaryBufferWriter { private: @@ -120,7 +127,9 @@ class ThriftBinaryBufferWriter QByteArray buffer() { return m_buf; } - quint32 writeMessageBegin(QString name, const ThriftMessageType::type messageType, const qint32 seqid) + quint32 writeMessageBegin( + QString name, const ThriftMessageType messageType, + const qint32 seqid) { if (m_strict) { @@ -151,7 +160,9 @@ class ThriftBinaryBufferWriter inline quint32 writeStructEnd() { return 0; } - inline quint32 writeFieldBegin(QString name, const ThriftFieldType::type fieldType, const qint16 fieldId) + inline quint32 writeFieldBegin( + QString name, const ThriftFieldType fieldType, + const qint16 fieldId) { Q_UNUSED(name); quint32 wsize = 0; @@ -161,9 +172,15 @@ class ThriftBinaryBufferWriter } inline quint32 writeFieldEnd() { return 0; } - inline quint32 writeFieldStop() { return writeByte((qint8)ThriftFieldType::T_STOP); } - inline quint32 writeMapBegin(const ThriftFieldType::type keyType, const ThriftFieldType::type valType, const qint32 size) + inline quint32 writeFieldStop() + { + return writeByte((qint8)ThriftFieldType::T_STOP); + } + + inline quint32 writeMapBegin( + const ThriftFieldType keyType, const ThriftFieldType valType, + const qint32 size) { quint32 wsize = 0; wsize += writeByte(static_cast(keyType)); @@ -174,7 +191,8 @@ class ThriftBinaryBufferWriter inline quint32 writeMapEnd() { return 0; } - inline quint32 writeListBegin(const ThriftFieldType::type elemType, const qint32 size) + inline quint32 writeListBegin( + const ThriftFieldType elemType, const qint32 size) { quint32 wsize = 0; wsize += writeByte(static_cast(elemType)); @@ -184,7 +202,8 @@ class ThriftBinaryBufferWriter inline quint32 writeListEnd() { return 0; } - inline quint32 writeSetBegin(const ThriftFieldType::type elemType, const qint32 size) + inline quint32 writeSetBegin( + const ThriftFieldType elemType, const qint32 size) { return writeListBegin(elemType, size); } @@ -230,7 +249,10 @@ class ThriftBinaryBufferWriter inline quint32 writeDouble(const double dub) { - Q_STATIC_ASSERT_X(sizeof(double) == sizeof(qint64) && std::numeric_limits::is_iec559, "incompatible double type"); + Q_STATIC_ASSERT_X( + sizeof(double) == sizeof(qint64) && + std::numeric_limits::is_iec559, + "incompatible double type"); quint64 bits = bitwise_cast(dub); qToBigEndian(bits, reinterpret_cast(&bits)); @@ -248,7 +270,9 @@ class ThriftBinaryBufferWriter { qint32 size = static_cast(bytes.length()); if (size > std::numeric_limits::max()) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("The data is too big")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("The data is too big")); } quint32 result = writeI32(static_cast(size)); @@ -258,9 +282,9 @@ class ThriftBinaryBufferWriter return result + static_cast(size); } - }; +//////////////////////////////////////////////////////////////////////////////// class ThriftBinaryBufferReader { @@ -273,14 +297,22 @@ class ThriftBinaryBufferReader void read(quint8 * dest, qint32 bytesCount) { if (Q_UNLIKELY((m_pos + bytesCount) > m_buf.length())) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("Unexpected end of data")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("Unexpected end of data")); } if (Q_UNLIKELY(bytesCount < 0)) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("Negative bytes count")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("Negative bytes count")); } - std::memcpy(dest, m_buf.mid(m_pos, bytesCount).constData(), static_cast(bytesCount)); + std::memcpy( + dest, + m_buf.mid(m_pos, bytesCount).constData(), + static_cast(bytesCount)); + m_pos += bytesCount; } @@ -294,7 +326,8 @@ class ThriftBinaryBufferReader void setStringLimit(qint32 limit) { m_stringLimit = limit; } void setStrictMode(bool on) { m_strict = on; } - quint32 readMessageBegin(QString & name, ThriftMessageType::type & messageType, qint32 & seqid) + quint32 readMessageBegin( + QString & name, ThriftMessageType & messageType, qint32 & seqid) { quint32 result = 0; qint32 sz; @@ -305,17 +338,23 @@ class ThriftBinaryBufferReader // Check for correct version number qint32 version = sz & VERSION_MASK; if (version != VERSION_1) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("Bad version identifier")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("Bad version identifier")); } - messageType = static_cast(sz & 0x000000ff); + messageType = static_cast(sz & 0x000000ff); result += readString(name); result += readI32(seqid); } else { if (m_strict) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("No version identifier... old protocol client in strict mode?")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral( + "No version identifier... old protocol client in " + "strict mode?")); } else { // Handle pre-versioned input @@ -323,7 +362,7 @@ class ThriftBinaryBufferReader m_pos -= 4; result += readString(name); result += readByte(type); - messageType = static_cast(type); + messageType = static_cast(type); result += readI32(seqid); } } @@ -335,14 +374,16 @@ class ThriftBinaryBufferReader inline quint32 readStructBegin(QString & name) { name.clear(); return 0; } inline quint32 readStructEnd() { return 0; } - inline quint32 readFieldBegin(QString & name, ThriftFieldType::type & fieldType, qint16 & fieldId) + + inline quint32 readFieldBegin( + QString & name, ThriftFieldType & fieldType, qint16 & fieldId) { Q_UNUSED(name) quint32 result = 0; qint8 type; result += readByte(type); - fieldType = static_cast(type); + fieldType = static_cast(type); if (fieldType == ThriftFieldType::T_STOP) { fieldId = 0; return result; @@ -354,21 +395,26 @@ class ThriftBinaryBufferReader inline quint32 readFieldEnd() { return 0; } - inline quint32 readMapBegin(ThriftFieldType::type & keyType, ThriftFieldType::type & valType, qint32 & size) + inline quint32 readMapBegin( + ThriftFieldType & keyType, ThriftFieldType & valType, qint32 & size) { qint8 k, v; quint32 result = 0; qint32 sizei; result += readByte(k); - keyType = static_cast(k); + keyType = static_cast(k); result += readByte(v); - valType = static_cast(v); + valType = static_cast(v); result += readI32(sizei); if (sizei < 0) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("Negative size!")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("Negative size!")); } else if (m_stringLimit > 0 && sizei > m_stringLimit) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("The size limit is exceeded.")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("The size limit is exceeded.")); } size = sizei; return result; @@ -376,26 +422,35 @@ class ThriftBinaryBufferReader inline quint32 readMapEnd() {return 0;} - inline quint32 readListBegin(ThriftFieldType::type & elemType, qint32 & size) + inline quint32 readListBegin(ThriftFieldType & elemType, qint32 & size) { qint8 e; quint32 result = 0; qint32 sizei; result += readByte(e); - elemType = static_cast(e); + elemType = static_cast(e); result += readI32(sizei); if (sizei < 0) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("Negative size!")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("Negative size!")); } else if (m_stringLimit > 0 && sizei > m_stringLimit) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("The size limit is exceeded.")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("The size limit is exceeded.")); } size = sizei; return result; } inline quint32 readListEnd() { return 0; } - inline quint32 readSetBegin(ThriftFieldType::type & elemType, qint32 & size) { return readListBegin(elemType, size); } + + inline quint32 readSetBegin(ThriftFieldType & elemType, qint32 & size) + { + return readListBegin(elemType, size); + } + inline quint32 readSetEnd() { return 0; } inline quint32 readBool(bool & value) @@ -452,7 +507,10 @@ class ThriftBinaryBufferReader inline quint32 readDouble(double & dub) { - Q_STATIC_ASSERT_X(sizeof(double) == sizeof(qint64) && std::numeric_limits::is_iec559, "incompatible double type"); + Q_STATIC_ASSERT_X( + sizeof(double) == sizeof(qint64) && + std::numeric_limits::is_iec559, + "incompatible double type"); union bytes { quint8 b[8]; @@ -472,11 +530,15 @@ class ThriftBinaryBufferReader result = readI32(size); if (size < 0) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("Negative size!")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("Negative size!")); } if (m_stringLimit > 0 && size > m_stringLimit) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("The size limit is exceeded.")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("The size limit is exceeded.")); } // Catch empty string case @@ -486,7 +548,9 @@ class ThriftBinaryBufferReader } if ((m_pos + size) > m_buf.length()) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("Unexpected end of data")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("Unexpected end of data")); } str = QString::fromUtf8(m_buf.constData() + m_pos, size); @@ -503,11 +567,15 @@ class ThriftBinaryBufferReader result = readI32(size); if (size < 0) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("Negative size!")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("Negative size!")); } if (m_stringLimit > 0 && size > m_stringLimit) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("The size limit is exceeded.")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("The size limit is exceeded.")); } // Catch empty string case @@ -517,7 +585,9 @@ class ThriftBinaryBufferReader } if ((m_pos + size) > m_buf.length()) { - throw ThriftException(ThriftException::Type::PROTOCOL_ERROR, QStringLiteral("Unexpected end of data")); + throw ThriftException( + ThriftException::Type::PROTOCOL_ERROR, + QStringLiteral("Unexpected end of data")); } str = m_buf.mid(m_pos, size); @@ -527,7 +597,7 @@ class ThriftBinaryBufferReader return result; } - inline quint32 skip(ThriftFieldType::type type) + inline quint32 skip(ThriftFieldType type) { switch (type) { case ThriftFieldType::T_BOOL: @@ -570,7 +640,7 @@ class ThriftBinaryBufferReader quint32 result = 0; QString name; qint16 fid; - ThriftFieldType::type ftype; + ThriftFieldType ftype; result += readStructBegin(name); while (true) { @@ -588,8 +658,8 @@ class ThriftBinaryBufferReader case ThriftFieldType::T_MAP: { quint32 result = 0; - ThriftFieldType::type keyType; - ThriftFieldType::type valType; + ThriftFieldType keyType; + ThriftFieldType valType; qint32 i, size; result += readMapBegin(keyType, valType, size); for(i = 0; i < size; i++) { @@ -602,7 +672,7 @@ class ThriftBinaryBufferReader case ThriftFieldType::T_SET: { quint32 result = 0; - ThriftFieldType::type elemType; + ThriftFieldType elemType; qint32 i, size; result += readSetBegin(elemType, size); for(i = 0; i < size; i++) { @@ -614,7 +684,7 @@ class ThriftBinaryBufferReader case ThriftFieldType::T_LIST: { quint32 result = 0; - ThriftFieldType::type elemType; + ThriftFieldType elemType; qint32 i, size; result += readListBegin(elemType, size); for(i = 0; i < size; i++) { diff --git a/src/qevercloud/QEverCloud/src/Thumbnail.cpp b/src/qevercloud/QEverCloud/src/Thumbnail.cpp new file mode 100644 index 00000000..89e65ba1 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/Thumbnail.cpp @@ -0,0 +1,255 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include "Http.h" + +#include +#include +#include +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +class ThumbnailPrivate +{ +public: + QString m_host; + QString m_shardId; + QString m_authenticationToken; + int m_size; + Thumbnail::ImageType m_imageType; +}; + +//////////////////////////////////////////////////////////////////////////////// + +Thumbnail::Thumbnail(): + d_ptr(new ThumbnailPrivate) +{ + d_ptr->m_size = 300; + d_ptr->m_imageType = ImageType::PNG; +} + + +Thumbnail::Thumbnail( + QString host, QString shardId, QString authenticationToken, + int size, Thumbnail::ImageType imageType) : + d_ptr(new ThumbnailPrivate) +{ + d_ptr->m_host = host; + d_ptr->m_shardId = shardId; + d_ptr->m_authenticationToken = authenticationToken; + d_ptr->m_size = size; + d_ptr->m_imageType = imageType; +} + +Thumbnail::~Thumbnail() +{ + delete d_ptr; +} + +Thumbnail & Thumbnail::setHost(QString host) +{ + d_ptr->m_host = host; + return *this; +} + +Thumbnail & Thumbnail::setShardId(QString shardId) +{ + d_ptr->m_shardId = shardId; + return *this; +} + +Thumbnail & Thumbnail::setAuthenticationToken(QString authenticationToken) +{ + d_ptr->m_authenticationToken = authenticationToken; + return *this; +} + +Thumbnail & Thumbnail::setSize(int size) +{ + d_ptr->m_size = size; + return *this; +} + +Thumbnail & Thumbnail::setImageType(ImageType imageType) +{ + d_ptr->m_imageType = imageType; + return *this; +} + +QByteArray Thumbnail::download( + Guid guid, const bool isPublic, const bool isResourceGuid, + const qint64 timeoutMsec) +{ + QEC_DEBUG("thumbnail", "Downloading thumbnail: guid = " << guid + << (isPublic ? "public" : "non-public") << ", " + << (isResourceGuid ? "resource guid" : "not a resource guid")); + + int httpStatusCode = 0; + auto request = createPostRequest(guid, isPublic, isResourceGuid); + + QByteArray reply = simpleDownload( + request.first, + timeoutMsec, + request.second, + &httpStatusCode); + + if (httpStatusCode != 200) + { + QEC_WARNING("thumbnail", "Failed to download thumbnail with guid " + << guid << ": http status code = " << httpStatusCode); + + throw EverCloudException( + QString::fromUtf8("HTTP Status Code = %1").arg(httpStatusCode)); + } + + QEC_DEBUG("thumbnail", "Finished download for guid " << guid); + return reply; +} + +AsyncResult * Thumbnail::downloadAsync( + Guid guid, const bool isPublic, const bool isResourceGuid, + const qint64 timeoutMsec) +{ + QEC_DEBUG("thumbnail", "Starting async thumbnail download: guid = " << guid + << (isPublic ? "public" : "non-public") << ", " + << (isResourceGuid ? "resource guid" : "not a resource guid")); + + auto pair = createPostRequest(guid, isPublic, isResourceGuid); + auto ctx = newRequestContext({}, timeoutMsec); + auto res = new AsyncResult( + pair.first, + pair.second, + ctx); + + QObject::connect( + res, + &AsyncResult::finished, + [=] (QVariant value, + EverCloudExceptionDataPtr error, + IRequestContextPtr ctx) + { + Q_UNUSED(value) + Q_UNUSED(ctx) + + if (!error) { + QEC_DEBUG("thumbnail", "Finished async download " + << "for guid " << guid); + return; + } + + QEC_WARNING("thumbnail", "Async download for guid " + << guid << " finished with error: " + << error->errorMessage); + }); + return res; +} + +std::pair Thumbnail::createPostRequest( + Guid guid, bool isPublic, bool isResourceGuid) +{ + Q_D(Thumbnail); + + QByteArray postData = ""; // not QByteArray()! or else ReplyFetcher will not work. + QNetworkRequest request; + + QString urlPattern; + if(isResourceGuid) { + urlPattern = QStringLiteral("https://%1/shard/%2/thm/res/%3"); + } + else { + urlPattern = QStringLiteral("https://%1/shard/%2/thm/note/%3"); + } + + QString url = urlPattern.arg(d->m_host, d->m_shardId, guid); + + QString ext; + switch(d->m_imageType) + { + case ImageType::BMP: + ext = QStringLiteral(".bmp"); + break; + case ImageType::GIF: + ext = QStringLiteral(".gif"); + break; + case ImageType::JPEG: + ext = QStringLiteral(".jpg"); + break; + default: + ext = QStringLiteral(".png"); + break; + } + url += ext; + + if (d->m_size != 300) { + url += QStringLiteral("?size=%1").arg(d->m_size); + } + + QEC_TRACE("thumbnail", "Sending thumbnail download request: url = " << url); + + request.setUrl(QUrl(url)); + request.setHeader( + QNetworkRequest::ContentTypeHeader, + QStringLiteral("application/x-www-form-urlencoded")); + + if (!isPublic) { + postData = QByteArray("auth=") + + QUrl::toPercentEncoding(d->m_authenticationToken); + } + + return std::make_pair(request, postData); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +template +void printImageType(T & strm, const Thumbnail::ImageType imageType) +{ + switch(imageType) + { + case Thumbnail::ImageType::PNG: + strm << "PNG"; + break; + case Thumbnail::ImageType::JPEG: + strm << "JPEG"; + break; + case Thumbnail::ImageType::GIF: + strm << "GIF"; + break; + case Thumbnail::ImageType::BMP: + strm << "BMP"; + break; + default: + strm << "Unknown (" << static_cast(imageType) << ")"; + break; + } +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & strm, const Thumbnail::ImageType imageType) +{ + printImageType(strm, imageType); + return strm; +} + +QDebug & operator<<(QDebug & dbg, const Thumbnail::ImageType imageType) +{ + printImageType(dbg, imageType); + return dbg; +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/VersionInfo.cpp b/src/qevercloud/QEverCloud/src/VersionInfo.cpp new file mode 100644 index 00000000..e9875bab --- /dev/null +++ b/src/qevercloud/QEverCloud/src/VersionInfo.cpp @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2017-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#include + +#include + +namespace qevercloud { + +int qevercloudVersionMajor() +{ + return QEVERCLOUD_VERSION_MAJOR; +} + +int qevercloudVersionMinor() +{ + return QEVERCLOUD_VERSION_MINOR; +} + +int qevercloudVersionPatch() +{ + return QEVERCLOUD_VERSION_PATCH; +} + +QString qevercloudBuildInfo() +{ + return QStringLiteral(QEVERCLOUD_BUILD_INFO); +} + +QString qevercloudBuiltWithQtVersion() +{ + return QStringLiteral(QT_VERSION_STR); +} + +bool qevercloudHasOAuth() +{ + return static_cast(QEVERCLOUD_HAS_OAUTH); +} + +bool qevercloudUsesQtWebEngine() +{ + return static_cast(QEVERCLOUD_USE_QT_WEB_ENGINE); +} + +bool qevercloudUsesQNamespace() +{ + return static_cast(QEVERCLOUD_USES_Q_NAMESPACE); +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/exceptions.cpp b/src/qevercloud/QEverCloud/src/exceptions.cpp deleted file mode 100644 index 06151b18..00000000 --- a/src/qevercloud/QEverCloud/src/exceptions.cpp +++ /dev/null @@ -1,378 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - */ - -#include -#include -#include -#include "generated/types_impl.h" -#include "impl.h" - -namespace qevercloud { - -ThriftException::ThriftException() : - EverCloudException(), - m_type(Type::UNKNOWN) -{} - -ThriftException::ThriftException(ThriftException::Type::type type) : - EverCloudException(), - m_type(type) -{} - -ThriftException::ThriftException(ThriftException::Type::type type, QString message) : - EverCloudException(message), - m_type(type) -{} - -ThriftException::Type::type ThriftException::type() const -{ - return m_type; -} - -QByteArray strEDAMErrorCode(EDAMErrorCode::type errorCode) -{ - switch(errorCode) - { - case EDAMErrorCode::UNKNOWN: - return "UNKNOWN"; - case EDAMErrorCode::BAD_DATA_FORMAT: - return "BAD_DATA_FORMAT"; - case EDAMErrorCode::PERMISSION_DENIED: - return "PERMISSION_DENIED"; - case EDAMErrorCode::INTERNAL_ERROR: - return "INTERNAL_ERROR"; - case EDAMErrorCode::DATA_REQUIRED: - return "DATA_REQUIRED"; - case EDAMErrorCode::LIMIT_REACHED: - return "LIMIT_REACHED"; - case EDAMErrorCode::QUOTA_REACHED: - return "QUOTA_REACHED"; - case EDAMErrorCode::INVALID_AUTH: - return "INVALID_AUTH"; - case EDAMErrorCode::AUTH_EXPIRED: - return "AUTH_EXPIRED"; - case EDAMErrorCode::DATA_CONFLICT: - return "DATA_CONFLICT"; - case EDAMErrorCode::ENML_VALIDATION: - return "ENML_VALIDATION"; - case EDAMErrorCode::SHARD_UNAVAILABLE: - return "SHARD_UNAVAILABLE"; - case EDAMErrorCode::LEN_TOO_SHORT: - return "LEN_TOO_SHORT"; - case EDAMErrorCode::LEN_TOO_LONG: - return "LEN_TOO_LONG"; - case EDAMErrorCode::TOO_FEW: - return "TOO_FEW"; - case EDAMErrorCode::TOO_MANY: - return "TOO_MANY"; - case EDAMErrorCode::UNSUPPORTED_OPERATION: - return "UNSUPPORTED_OPERATION"; - case EDAMErrorCode::TAKEN_DOWN: - return "TAKEN_DOWN"; - case EDAMErrorCode::RATE_LIMIT_REACHED: - return "RATE_LIMIT_REACHED"; - default: - return "UNRECOGNIZED_ERROR_CODE"; - } -} - -const char * EDAMUserException::what() const throw() -{ - if (m_error.isEmpty()) - { - m_error = "EDAMUserException: " + strEDAMErrorCode(errorCode); - if (parameter.isSet()) { - m_error += " parameter=" + parameter->toUtf8(); - } - } - - return EvernoteException::what(); -} - -const char * EDAMSystemException::what() const throw() -{ - if (m_error.isEmpty()) - { - m_error = "EDAMSystemException: " + strEDAMErrorCode(errorCode); - - if (message.isSet()) { - m_error += " " + message->toUtf8(); - } - - if (rateLimitDuration.isSet()) { - m_error += QStringLiteral(" rateLimitDuration= %1 sec.").arg(rateLimitDuration).toUtf8(); - } - } - - return EvernoteException::what(); -} - -const char * EDAMNotFoundException::what() const throw() -{ - if (m_error.isEmpty()) - { - m_error = "EDAMNotFoundException: "; - - if (identifier.isSet()) { - m_error += " identifier=" + identifier->toUtf8(); - } - - if (key.isSet()) { - m_error += " key=" + key->toUtf8(); - } - } - - return EvernoteException::what(); -} - -ThriftException readThriftException(ThriftBinaryBufferReader & reader) -{ - QString name; - ThriftFieldType::type fieldType; - qint16 fieldId; - - reader.readStructBegin(name); - QString error; - ThriftException::Type::type type = ThriftException::Type::UNKNOWN; - - while(true) - { - reader.readFieldBegin(name, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) { - break; - } - - switch(fieldId) - { - case 1: - if (fieldType == ThriftFieldType::T_STRING) { - QString str; - reader.readString(str); - error = str; - } - else { - reader.skip(fieldType); - } - break; - case 2: - if (fieldType == ThriftFieldType::T_I32) { - qint32 t; - reader.readI32(t); - type = static_cast(t); - } - else { - reader.skip(fieldType); - } - break; - default: - reader.skip(fieldType); - break; - } - - reader.readFieldEnd(); - } - - reader.readStructEnd(); - - return ThriftException(type, error); -} - -QSharedPointer EDAMInvalidContactsException::exceptionData() const -{ - return QSharedPointer(new EDAMInvalidContactsExceptionData(this->contacts, this->parameter, this->reasons)); -} - -EDAMInvalidContactsExceptionData::EDAMInvalidContactsExceptionData(QList contacts, Optional parameter, - Optional > reasons) : - EvernoteExceptionData(QStringLiteral("EDAMInvalidContactsExceptionData")), - m_contacts(contacts), - m_parameter(parameter), - m_reasons(reasons) -{} - -const char * EDAMInvalidContactsException::what() const throw() -{ - return "EDAMInvalidContactsException"; -} - -void EDAMInvalidContactsExceptionData::throwException() const -{ - EDAMInvalidContactsException exception; - exception.contacts = m_contacts; - exception.parameter = m_parameter; - exception.reasons = m_reasons; - throw exception; -} - -QSharedPointer EDAMUserException::exceptionData() const -{ - return QSharedPointer(new EDAMUserExceptionData(QString::fromUtf8(what()), this->errorCode, this->parameter)); -} - -void EDAMUserExceptionData::throwException() const -{ - EDAMUserException exception; - exception.errorCode = m_errorCode; - exception.parameter = m_parameter; - throw exception; -} - -QSharedPointer EDAMSystemException::exceptionData() const -{ - return QSharedPointer(new EDAMSystemExceptionData(QString::fromUtf8(what()), this->errorCode, this->message, - this->rateLimitDuration)); -} - -EDAMSystemExceptionData::EDAMSystemExceptionData(QString error, EDAMErrorCode::type errorCode, Optional message, - Optional rateLimitDuration) : - EvernoteExceptionData(error), - m_errorCode(errorCode), - m_message(message), - m_rateLimitDuration(rateLimitDuration) -{} - -void EDAMSystemExceptionData::throwException() const -{ - EDAMSystemException exception; - exception.errorCode = m_errorCode; - exception.message = m_message; - exception.rateLimitDuration = m_rateLimitDuration; - throw exception; -} - -EDAMSystemExceptionRateLimitReachedData::EDAMSystemExceptionRateLimitReachedData(QString error, EDAMErrorCode::type errorCode, - Optional message, - Optional rateLimitDuration) : - EDAMSystemExceptionData(error, errorCode, message, rateLimitDuration) -{} - -void EDAMSystemExceptionRateLimitReachedData::throwException() const -{ - EDAMSystemExceptionRateLimitReached exception; - exception.errorCode = m_errorCode; - exception.message = m_message; - exception.rateLimitDuration = m_rateLimitDuration; - throw exception; -} - -QSharedPointer EDAMNotFoundException::exceptionData() const -{ - return QSharedPointer(new EDAMNotFoundExceptionData(QString::fromUtf8(what()), identifier, key)); -} - -EDAMNotFoundExceptionData::EDAMNotFoundExceptionData(QString error, Optional identifier, Optional key) : - EvernoteExceptionData(error), - m_identifier(identifier), - m_key(key) -{} - -void EDAMNotFoundExceptionData::throwException() const -{ - EDAMNotFoundException exception; - exception.identifier = m_identifier; - exception.key = m_key; - throw exception; -} - -const char * ThriftException::what() const throw() -{ - if (m_error.isEmpty()) - { - switch (m_type) - { - case Type::UNKNOWN: - return "ThriftException: Unknown application exception"; - case Type::UNKNOWN_METHOD: - return "ThriftException: Unknown method"; - case Type::INVALID_MESSAGE_TYPE: - return "ThriftException: Invalid message type"; - case Type::WRONG_METHOD_NAME: - return "ThriftException: Wrong method name"; - case Type::BAD_SEQUENCE_ID: - return "ThriftException: Bad sequence identifier"; - case Type::MISSING_RESULT: - return "ThriftException: Missing result"; - case Type::INVALID_DATA: - return "ThriftException: Invalid data"; - default: - return "ThriftException: (Invalid exception type)"; - }; - } - else - { - return m_error.constData(); - } -} - -void throwEDAMSystemException(const EDAMSystemException & baseException) -{ - if (baseException.errorCode == EDAMErrorCode::AUTH_EXPIRED) { - EDAMSystemExceptionAuthExpired exception; - exception.errorCode = exception.errorCode; - exception.message = exception.message; - exception.rateLimitDuration = exception.rateLimitDuration; - throw exception; - } - - if (baseException.errorCode == EDAMErrorCode::RATE_LIMIT_REACHED) { - EDAMSystemExceptionRateLimitReached exception; - exception.errorCode = exception.errorCode; - exception.message = exception.message; - exception.rateLimitDuration = exception.rateLimitDuration; - throw exception; - } - - throw baseException; -} - -QSharedPointer EDAMSystemExceptionRateLimitReached::exceptionData() const -{ - return QSharedPointer(new EDAMSystemExceptionRateLimitReachedData(QString::fromUtf8(what()), this->errorCode, - this->message, - this->rateLimitDuration)); -} - -QSharedPointer EDAMSystemExceptionAuthExpired::exceptionData() const -{ - return QSharedPointer(new EDAMSystemExceptionAuthExpiredData(QString::fromUtf8(what()), this->errorCode, - this->message, - this->rateLimitDuration)); -} - -EDAMSystemExceptionAuthExpiredData::EDAMSystemExceptionAuthExpiredData(QString error, EDAMErrorCode::type errorCode, - Optional message, - Optional rateLimitDuration) : - EDAMSystemExceptionData(error, errorCode, message, rateLimitDuration) -{} - -void EDAMSystemExceptionAuthExpiredData::throwException() const -{ - EDAMSystemExceptionAuthExpired exception; - exception.errorCode = m_errorCode; - exception.message = m_message; - exception.rateLimitDuration = m_rateLimitDuration; - throw exception; -} - -ThriftExceptionData::ThriftExceptionData(QString error, ThriftException::Type::type type) : - EverCloudExceptionData(error), - m_type(type) -{} - -void ThriftExceptionData::throwException() const -{ - throw ThriftException(m_type, errorMessage); -} - -EDAMUserExceptionData::EDAMUserExceptionData(QString error, EDAMErrorCode::type errorCode, Optional parameter) : - EvernoteExceptionData(error), - m_errorCode(errorCode), - m_parameter(parameter) -{} - -} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/generated/constants.cpp b/src/qevercloud/QEverCloud/src/generated/Constants.cpp similarity index 71% rename from src/qevercloud/QEverCloud/src/generated/constants.cpp rename to src/qevercloud/QEverCloud/src/generated/Constants.cpp index 114fe51d..011191f3 100644 --- a/src/qevercloud/QEverCloud/src/generated/constants.cpp +++ b/src/qevercloud/QEverCloud/src/generated/Constants.cpp @@ -1,232 +1,672 @@ /** * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: * https://opensource.org/licenses/MIT * * This file was generated from Evernote Thrift API */ - -#include -#include "../impl.h" -#include +#include +#include "../Impl.h" +#include namespace qevercloud { +//////////////////////////////////////////////////////////////////////////////// + // Limits.thrift const qint32 EDAM_ATTRIBUTE_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_ATTRIBUTE_LEN_MAX = 4096; +// Limits.thrift + const QString EDAM_ATTRIBUTE_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Zl}\\p{Zp}]{1,4096}$"); +// Limits.thrift + const qint32 EDAM_ATTRIBUTE_LIST_MAX = 100; +// Limits.thrift + const qint32 EDAM_ATTRIBUTE_MAP_MAX = 100; +// Limits.thrift + const qint32 EDAM_GUID_LEN_MIN = 36; +// Limits.thrift + const qint32 EDAM_GUID_LEN_MAX = 36; +// Limits.thrift + const QString EDAM_GUID_REGEX = QStringLiteral("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"); +// Limits.thrift + const qint32 EDAM_EMAIL_LEN_MIN = 6; +// Limits.thrift + const qint32 EDAM_EMAIL_LEN_MAX = 255; +// Limits.thrift + const QString EDAM_EMAIL_LOCAL_REGEX = QStringLiteral("^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*$"); +// Limits.thrift + const QString EDAM_EMAIL_DOMAIN_REGEX = QStringLiteral("^[A-Za-z0-9-]*[A-Za-z0-9](\\.[A-Za-z0-9-]*[A-Za-z0-9])*\\.([A-Za-z]{2,})$"); +// Limits.thrift + const QString EDAM_EMAIL_REGEX = QStringLiteral("^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@[A-Za-z0-9-]*[A-Za-z0-9](\\.[A-Za-z0-9-]*[A-Za-z0-9])*\\.([A-Za-z]{2,})$"); +// Limits.thrift + const QString EDAM_VAT_REGEX = QStringLiteral("^(AT)?U[0-9]{8}$|^(BE)?0?[0-9]{9}$|^(BG)?[0-9]{9,10}$|^(CY)?[0-9]{8}L$|^(CZ)?[0-9]{8,10}$|^(DE)?[0-9]{9}$|^(DK)?[0-9]{8}$|^(EE)?[0-9]{9}$|^(EL|GR)?[0-9]{9}$|^(ES)?[0-9A-Z][0-9]{7}[0-9A-Z]$|^(FI)?[0-9]{8}$|^(FR)?[0-9A-Z]{2}[0-9]{9}$|^(GB)?([0-9]{9}([0-9]{3})?|[A-Z]{2}[0-9]{3})$|^(HU)?[0-9]{8}$|^(IE)?[0-9]{7}[A-Z]{1,2}$|^(IT)?[0-9]{11}$|^(LT)?([0-9]{9}|[0-9]{12})$|^(LU)?[0-9]{8}$|^(LV)?[0-9]{11}$|^(MT)?[0-9]{8}$|^(NL)?[0-9]{9}B[0-9]{2}$|^(PL)?[0-9]{10}$|^(PT)?[0-9]{9}$|^(RO)?[0-9]{2,10}$|^(SE)?[0-9]{12}$|^(SI)?[0-9]{8}$|^(SK)?[0-9]{10}$|^[0-9]{9}MVA$|^[0-9]{6}$|^CHE[0-9]{9}(TVA|MWST|IVA)$"); +// Limits.thrift + const qint32 EDAM_TIMEZONE_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_TIMEZONE_LEN_MAX = 32; +// Limits.thrift + const QString EDAM_TIMEZONE_REGEX = QStringLiteral("^([A-Za-z_-]+(/[A-Za-z_-]+)*)|(GMT(-|\\+)[0-9]{1,2}(:[0-9]{2})?)$"); +// Limits.thrift + const qint32 EDAM_MIME_LEN_MIN = 3; +// Limits.thrift + const qint32 EDAM_MIME_LEN_MAX = 255; +// Limits.thrift + const QString EDAM_MIME_REGEX = QStringLiteral("^[A-Za-z]+/[A-Za-z0-9._+-]+$"); +// Limits.thrift + const QString EDAM_MIME_TYPE_GIF = QStringLiteral("image/gif"); +// Limits.thrift + const QString EDAM_MIME_TYPE_JPEG = QStringLiteral("image/jpeg"); +// Limits.thrift + const QString EDAM_MIME_TYPE_PNG = QStringLiteral("image/png"); +// Limits.thrift + const QString EDAM_MIME_TYPE_TIFF = QStringLiteral("image/tiff"); +// Limits.thrift + const QString EDAM_MIME_TYPE_BMP = QStringLiteral("image/bmp"); +// Limits.thrift + const QString EDAM_MIME_TYPE_WAV = QStringLiteral("audio/wav"); +// Limits.thrift + const QString EDAM_MIME_TYPE_MP3 = QStringLiteral("audio/mpeg"); +// Limits.thrift + const QString EDAM_MIME_TYPE_AMR = QStringLiteral("audio/amr"); +// Limits.thrift + const QString EDAM_MIME_TYPE_AAC = QStringLiteral("audio/aac"); +// Limits.thrift + const QString EDAM_MIME_TYPE_M4A = QStringLiteral("audio/mp4"); +// Limits.thrift + const QString EDAM_MIME_TYPE_MP4_VIDEO = QStringLiteral("video/mp4"); +// Limits.thrift + const QString EDAM_MIME_TYPE_INK = QStringLiteral("application/vnd.evernote.ink"); +// Limits.thrift + const QString EDAM_MIME_TYPE_PDF = QStringLiteral("application/pdf"); +// Limits.thrift + const QString EDAM_MIME_TYPE_DEFAULT = QStringLiteral("application/octet-stream"); -const QSet< QString > EDAM_MIME_TYPES = QSet< QString >() << EDAM_MIME_TYPE_GIF << EDAM_MIME_TYPE_JPEG << EDAM_MIME_TYPE_PNG << EDAM_MIME_TYPE_WAV << EDAM_MIME_TYPE_MP3 << EDAM_MIME_TYPE_AMR << EDAM_MIME_TYPE_INK << EDAM_MIME_TYPE_PDF << EDAM_MIME_TYPE_MP4_VIDEO << EDAM_MIME_TYPE_AAC << EDAM_MIME_TYPE_M4A; -const QSet< QString > EDAM_INDEXABLE_RESOURCE_MIME_TYPES = QSet< QString >() << QStringLiteral("application/msword") << QStringLiteral("application/mspowerpoint") << QStringLiteral("application/excel") << QStringLiteral("application/vnd.ms-word") << QStringLiteral("application/vnd.ms-powerpoint") << QStringLiteral("application/vnd.ms-excel") << QStringLiteral("application/vnd.openxmlformats-officedocument.wordprocessingml.document") << QStringLiteral("application/vnd.openxmlformats-officedocument.presentationml.presentation") << QStringLiteral("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") << QStringLiteral("application/vnd.apple.pages") << QStringLiteral("application/vnd.apple.numbers") << QStringLiteral("application/vnd.apple.keynote") << QStringLiteral("application/x-iwork-pages-sffpages") << QStringLiteral("application/x-iwork-numbers-sffnumbers") << QStringLiteral("application/x-iwork-keynote-sffkey"); -const QSet< QString > EDAM_INDEXABLE_PLAINTEXT_MIME_TYPES = QSet< QString >() << QStringLiteral("application/x-sh") << QStringLiteral("application/x-bsh") << QStringLiteral("application/sql") << QStringLiteral("application/x-sql"); +// Limits.thrift + +const QSet EDAM_MIME_TYPES = QSet() + << EDAM_MIME_TYPE_GIF + << EDAM_MIME_TYPE_JPEG + << EDAM_MIME_TYPE_PNG + << EDAM_MIME_TYPE_WAV + << EDAM_MIME_TYPE_MP3 + << EDAM_MIME_TYPE_AMR + << EDAM_MIME_TYPE_INK + << EDAM_MIME_TYPE_PDF + << EDAM_MIME_TYPE_MP4_VIDEO + << EDAM_MIME_TYPE_AAC + << EDAM_MIME_TYPE_M4A +; +// Limits.thrift + +const QSet EDAM_INDEXABLE_RESOURCE_MIME_TYPES = QSet() + << QStringLiteral("application/msword") + << QStringLiteral("application/mspowerpoint") + << QStringLiteral("application/excel") + << QStringLiteral("application/vnd.ms-word") + << QStringLiteral("application/vnd.ms-powerpoint") + << QStringLiteral("application/vnd.ms-excel") + << QStringLiteral("application/vnd.openxmlformats-officedocument.wordprocessingml.document") + << QStringLiteral("application/vnd.openxmlformats-officedocument.presentationml.presentation") + << QStringLiteral("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") + << QStringLiteral("application/vnd.apple.pages") + << QStringLiteral("application/vnd.apple.numbers") + << QStringLiteral("application/vnd.apple.keynote") + << QStringLiteral("application/x-iwork-pages-sffpages") + << QStringLiteral("application/x-iwork-numbers-sffnumbers") + << QStringLiteral("application/x-iwork-keynote-sffkey") +; +// Limits.thrift + +const QSet EDAM_INDEXABLE_PLAINTEXT_MIME_TYPES = QSet() + << QStringLiteral("application/x-sh") + << QStringLiteral("application/x-bsh") + << QStringLiteral("application/sql") + << QStringLiteral("application/x-sql") +; +// Limits.thrift + const qint32 EDAM_SEARCH_QUERY_LEN_MIN = 0; +// Limits.thrift + const qint32 EDAM_SEARCH_QUERY_LEN_MAX = 1024; +// Limits.thrift + const QString EDAM_SEARCH_QUERY_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Zl}\\p{Zp}]{0,1024}$"); +// Limits.thrift + const qint32 EDAM_HASH_LEN = 16; +// Limits.thrift + const qint32 EDAM_USER_USERNAME_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_USER_USERNAME_LEN_MAX = 64; +// Limits.thrift + const QString EDAM_USER_USERNAME_REGEX = QStringLiteral("^[a-z0-9]([a-z0-9_-]{0,62}[a-z0-9])?$"); +// Limits.thrift + const qint32 EDAM_USER_NAME_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_USER_NAME_LEN_MAX = 255; +// Limits.thrift + const QString EDAM_USER_NAME_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Zl}\\p{Zp}]{1,255}$"); +// Limits.thrift + const qint32 EDAM_TAG_NAME_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_TAG_NAME_LEN_MAX = 100; +// Limits.thrift + const QString EDAM_TAG_NAME_REGEX = QStringLiteral("^[^,\\p{Cc}\\p{Z}]([^,\\p{Cc}\\p{Zl}\\p{Zp}]{0,98}[^,\\p{Cc}\\p{Z}])?$"); +// Limits.thrift + const qint32 EDAM_NOTE_TITLE_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_NOTE_TITLE_LEN_MAX = 255; +// Limits.thrift + const QString EDAM_NOTE_TITLE_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Z}]([^\\p{Cc}\\p{Zl}\\p{Zp}]{0,253}[^\\p{Cc}\\p{Z}])?$"); +// Limits.thrift + const qint32 EDAM_NOTE_CONTENT_LEN_MIN = 0; +// Limits.thrift + const qint32 EDAM_NOTE_CONTENT_LEN_MAX = 5242880; +// Limits.thrift + const qint32 EDAM_APPLICATIONDATA_NAME_LEN_MIN = 3; +// Limits.thrift + const qint32 EDAM_APPLICATIONDATA_NAME_LEN_MAX = 32; +// Limits.thrift + const qint32 EDAM_APPLICATIONDATA_VALUE_LEN_MIN = 0; +// Limits.thrift + const qint32 EDAM_APPLICATIONDATA_VALUE_LEN_MAX = 4092; +// Limits.thrift + const qint32 EDAM_APPLICATIONDATA_ENTRY_LEN_MAX = 4095; +// Limits.thrift + const QString EDAM_APPLICATIONDATA_NAME_REGEX = QStringLiteral("^[A-Za-z0-9_.-]{3,32}$"); +// Limits.thrift + const QString EDAM_APPLICATIONDATA_VALUE_REGEX = QStringLiteral("^[\\p{Space}[^\\p{Cc}]]{0,4092}$"); +// Limits.thrift + const qint32 EDAM_NOTEBOOK_NAME_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_NOTEBOOK_NAME_LEN_MAX = 100; +// Limits.thrift + const QString EDAM_NOTEBOOK_NAME_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Z}]([^\\p{Cc}\\p{Zl}\\p{Zp}]{0,98}[^\\p{Cc}\\p{Z}])?$"); +// Limits.thrift + const qint32 EDAM_NOTEBOOK_STACK_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_NOTEBOOK_STACK_LEN_MAX = 100; +// Limits.thrift + const QString EDAM_NOTEBOOK_STACK_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Z}]([^\\p{Cc}\\p{Zl}\\p{Zp}]{0,98}[^\\p{Cc}\\p{Z}])?$"); +// Limits.thrift + const qint32 EDAM_WORKSPACE_NAME_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_WORKSPACE_NAME_LEN_MAX = 100; +// Limits.thrift + const qint32 EDAM_WORKSPACE_DESCRIPTION_LEN_MAX = 600; +// Limits.thrift + const QString EDAM_WORKSPACE_NAME_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Z}]([^\\p{Cc}\\p{Zl}\\p{Zp}]{0,98}[^\\p{Cc}\\p{Z}])?$"); +// Limits.thrift + const qint32 EDAM_PUBLISHING_URI_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_PUBLISHING_URI_LEN_MAX = 255; +// Limits.thrift + const QString EDAM_PUBLISHING_URI_REGEX = QStringLiteral("^[a-zA-Z0-9.~_+-]{1,255}$"); -const QSet< QString > EDAM_PUBLISHING_URI_PROHIBITED = QSet< QString >() << QStringLiteral(".") << QStringLiteral(".."); +// Limits.thrift + +const QSet EDAM_PUBLISHING_URI_PROHIBITED = QSet() + << QStringLiteral(".") + << QStringLiteral("..") +; +// Limits.thrift + const qint32 EDAM_PUBLISHING_DESCRIPTION_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_PUBLISHING_DESCRIPTION_LEN_MAX = 200; +// Limits.thrift + const QString EDAM_PUBLISHING_DESCRIPTION_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Z}]([^\\p{Cc}\\p{Zl}\\p{Zp}]{0,198}[^\\p{Cc}\\p{Z}])?$"); +// Limits.thrift + const qint32 EDAM_SAVED_SEARCH_NAME_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_SAVED_SEARCH_NAME_LEN_MAX = 100; +// Limits.thrift + const QString EDAM_SAVED_SEARCH_NAME_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Z}]([^\\p{Cc}\\p{Zl}\\p{Zp}]{0,98}[^\\p{Cc}\\p{Z}])?$"); +// Limits.thrift + const qint32 EDAM_USER_PASSWORD_LEN_MIN = 6; +// Limits.thrift + const qint32 EDAM_USER_PASSWORD_LEN_MAX = 64; +// Limits.thrift + const QString EDAM_USER_PASSWORD_REGEX = QStringLiteral("^[A-Za-z0-9!#$%&'()*+,./:;<=>?@^_`{|}~\\[\\]\\\\-]{6,64}$"); +// Limits.thrift + const qint32 EDAM_BUSINESS_URI_LEN_MAX = 32; +// Limits.thrift + const QString EDAM_BUSINESS_MARKETING_CODE_REGEX_PATTERN = QStringLiteral("[A-Za-z0-9-]{1,128}"); +// Limits.thrift + const qint32 EDAM_NOTE_TAGS_MAX = 100; +// Limits.thrift + const qint32 EDAM_NOTE_RESOURCES_MAX = 1000; +// Limits.thrift + const qint32 EDAM_USER_TAGS_MAX = 100000; +// Limits.thrift + const qint32 EDAM_BUSINESS_TAGS_MAX = 100000; +// Limits.thrift + const qint32 EDAM_USER_SAVED_SEARCHES_MAX = 100; +// Limits.thrift + const qint32 EDAM_USER_NOTES_MAX = 100000; +// Limits.thrift + const qint32 EDAM_BUSINESS_NOTES_MAX = 500000; +// Limits.thrift + const qint32 EDAM_USER_NOTEBOOKS_MAX = 250; +// Limits.thrift + const qint32 EDAM_USER_WORKSPACES_MAX = 0; +// Limits.thrift + const qint32 EDAM_BUSINESS_NOTEBOOKS_MAX = 10000; +// Limits.thrift + const qint32 EDAM_BUSINESS_WORKSPACES_MAX = 1000; +// Limits.thrift + const qint32 EDAM_USER_RECENT_MAILED_ADDRESSES_MAX = 10; +// Limits.thrift + const qint32 EDAM_USER_MAIL_LIMIT_DAILY_FREE = 50; +// Limits.thrift + const qint32 EDAM_USER_MAIL_LIMIT_DAILY_PREMIUM = 200; +// Limits.thrift + const qint64 EDAM_USER_UPLOAD_LIMIT_FREE = 62914560; +// Limits.thrift + const qint64 EDAM_USER_UPLOAD_LIMIT_PREMIUM = 10737418240; +// Limits.thrift + const qint64 EDAM_USER_UPLOAD_LIMIT_BUSINESS_FIRST_MONTH = 53687091200; +// Limits.thrift + const qint64 EDAM_USER_UPLOAD_LIMIT_BUSINESS_NEXT_MONTH = 21474836480; +// Limits.thrift + const qint64 EDAM_USER_UPLOAD_LIMIT_PLUS = 1073741824; +// Limits.thrift + const qint64 EDAM_USER_UPLOAD_SURVEY_THRESHOLD = 5368709120; +// Limits.thrift + const qint64 EDAM_USER_UPLOAD_LIMIT_BUSINESS = 10737418240; +// Limits.thrift + const qint64 EDAM_USER_UPLOAD_LIMIT_BUSINESS_PER_USER = 2147483647; +// Limits.thrift + const qint32 EDAM_NOTE_SIZE_MAX_FREE = 26214400; +// Limits.thrift + const qint32 EDAM_NOTE_SIZE_MAX_PREMIUM = 209715200; +// Limits.thrift + const qint32 EDAM_RESOURCE_SIZE_MAX_FREE = 26214400; +// Limits.thrift + const qint32 EDAM_RESOURCE_SIZE_MAX_PREMIUM = 209715200; +// Limits.thrift + const qint32 EDAM_USER_LINKED_NOTEBOOK_MAX = 100; +// Limits.thrift + const qint32 EDAM_USER_LINKED_NOTEBOOK_MAX_PREMIUM = 500; +// Limits.thrift + const qint32 EDAM_NOTEBOOK_BUSINESS_SHARED_NOTEBOOK_MAX = 5000; +// Limits.thrift + const qint32 EDAM_NOTEBOOK_PERSONAL_SHARED_NOTEBOOK_MAX = 500; +// Limits.thrift + const qint32 EDAM_NOTE_BUSINESS_SHARED_NOTE_MAX = 1000; +// Limits.thrift + const qint32 EDAM_NOTE_PERSONAL_SHARED_NOTE_MAX = 100; +// Limits.thrift + const qint32 EDAM_NOTE_CONTENT_CLASS_LEN_MIN = 3; +// Limits.thrift + const qint32 EDAM_NOTE_CONTENT_CLASS_LEN_MAX = 32; +// Limits.thrift + const QString EDAM_NOTE_CONTENT_CLASS_REGEX = QStringLiteral("^[A-Za-z0-9_.-]{3,32}$"); +// Limits.thrift + const QString EDAM_HELLO_APP_CONTENT_CLASS_PREFIX = QStringLiteral("evernote.hello."); +// Limits.thrift + const QString EDAM_FOOD_APP_CONTENT_CLASS_PREFIX = QStringLiteral("evernote.food."); +// Limits.thrift + const QString EDAM_CONTENT_CLASS_HELLO_ENCOUNTER = QStringLiteral("evernote.hello.encounter"); +// Limits.thrift + const QString EDAM_CONTENT_CLASS_HELLO_PROFILE = QStringLiteral("evernote.hello.profile"); +// Limits.thrift + const QString EDAM_CONTENT_CLASS_FOOD_MEAL = QStringLiteral("evernote.food.meal"); +// Limits.thrift + const QString EDAM_CONTENT_CLASS_SKITCH_PREFIX = QStringLiteral("evernote.skitch"); +// Limits.thrift + const QString EDAM_CONTENT_CLASS_SKITCH = QStringLiteral("evernote.skitch"); +// Limits.thrift + const QString EDAM_CONTENT_CLASS_SKITCH_PDF = QStringLiteral("evernote.skitch.pdf"); +// Limits.thrift + const QString EDAM_CONTENT_CLASS_PENULTIMATE_PREFIX = QStringLiteral("evernote.penultimate."); +// Limits.thrift + const QString EDAM_CONTENT_CLASS_PENULTIMATE_NOTEBOOK = QStringLiteral("evernote.penultimate.notebook"); +// Limits.thrift + const QString EDAM_SOURCE_APPLICATION_POSTIT = QStringLiteral("postit"); +// Limits.thrift + const QString EDAM_SOURCE_APPLICATION_MOLESKINE = QStringLiteral("moleskine"); +// Limits.thrift + const QString EDAM_SOURCE_APPLICATION_EN_SCANSNAP = QStringLiteral("scanner.scansnap.evernote"); +// Limits.thrift + const QString EDAM_SOURCE_APPLICATION_EWC = QStringLiteral("clipncite.web"); +// Limits.thrift + const QString EDAM_SOURCE_APPLICATION_ANDROID_SHARE_EXTENSION = QStringLiteral("android.clipper.evernote"); +// Limits.thrift + const QString EDAM_SOURCE_APPLICATION_IOS_SHARE_EXTENSION = QStringLiteral("ios.clipper.evernote"); +// Limits.thrift + const QString EDAM_SOURCE_APPLICATION_WEB_CLIPPER = QStringLiteral("webclipper.evernote"); +// Limits.thrift + const QString EDAM_SOURCE_OUTLOOK_CLIPPER = QStringLiteral("app.ms.outlook"); +// Limits.thrift + const qint32 EDAM_NOTE_TITLE_QUALITY_UNTITLED = 0; +// Limits.thrift + const qint32 EDAM_NOTE_TITLE_QUALITY_LOW = 1; +// Limits.thrift + const qint32 EDAM_NOTE_TITLE_QUALITY_MEDIUM = 2; +// Limits.thrift + const qint32 EDAM_NOTE_TITLE_QUALITY_HIGH = 3; +// Limits.thrift + const qint32 EDAM_RELATED_PLAINTEXT_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_RELATED_PLAINTEXT_LEN_MAX = 131072; +// Limits.thrift + const qint32 EDAM_RELATED_MAX_NOTES = 25; +// Limits.thrift + const qint32 EDAM_RELATED_MAX_NOTEBOOKS = 1; +// Limits.thrift + const qint32 EDAM_RELATED_MAX_TAGS = 25; +// Limits.thrift + const qint32 EDAM_RELATED_MAX_EXPERTS = 10; +// Limits.thrift + const qint32 EDAM_RELATED_MAX_RELATED_CONTENT = 10; +// Limits.thrift + const qint32 EDAM_BUSINESS_NOTEBOOK_DESCRIPTION_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_BUSINESS_NOTEBOOK_DESCRIPTION_LEN_MAX = 200; +// Limits.thrift + const QString EDAM_BUSINESS_NOTEBOOK_DESCRIPTION_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Z}]([^\\p{Cc}\\p{Zl}\\p{Zp}]{0,198}[^\\p{Cc}\\p{Z}])?$"); +// Limits.thrift + const qint32 EDAM_BUSINESS_PHONE_NUMBER_LEN_MAX = 20; +// Limits.thrift + const qint32 EDAM_PREFERENCE_NAME_LEN_MIN = 3; +// Limits.thrift + const qint32 EDAM_PREFERENCE_NAME_LEN_MAX = 32; +// Limits.thrift + const qint32 EDAM_PREFERENCE_VALUE_LEN_MIN = 1; +// Limits.thrift + const qint32 EDAM_PREFERENCE_VALUE_LEN_MAX = 1024; +// Limits.thrift + const qint32 EDAM_MAX_PREFERENCES = 100; +// Limits.thrift + const qint32 EDAM_MAX_VALUES_PER_PREFERENCE = 256; +// Limits.thrift + const qint32 EDAM_PREFERENCE_ONLY_ONE_VALUE_LEN_MAX = 16384; +// Limits.thrift + const QString EDAM_PREFERENCE_NAME_REGEX = QStringLiteral("^[A-Za-z0-9_.-]{3,32}$"); +// Limits.thrift + const QString EDAM_PREFERENCE_VALUE_REGEX = QStringLiteral("^[^\\p{Cc}]{1,1024}$"); +// Limits.thrift + const QString EDAM_PREFERENCE_ONLY_ONE_VALUE_REGEX = QStringLiteral("^[^\\p{Cc}]{1,16384}$"); +// Limits.thrift + const QString EDAM_PREFERENCE_SHORTCUTS = QStringLiteral("evernote.shortcuts"); +// Limits.thrift + const QString EDAM_PREFERENCE_BUSINESS_DEFAULT_NOTEBOOK = QStringLiteral("evernote.business.notebook"); +// Limits.thrift + const QString EDAM_PREFERENCE_BUSINESS_QUICKNOTE = QStringLiteral("evernote.business.quicknote"); +// Limits.thrift + const qint32 EDAM_PREFERENCE_SHORTCUTS_MAX_VALUES = 250; +// Limits.thrift + const qint32 EDAM_DEVICE_ID_LEN_MAX = 32; +// Limits.thrift + const QString EDAM_DEVICE_ID_REGEX = QStringLiteral("^[^\\p{Cc}]{1,32}$"); +// Limits.thrift + const qint32 EDAM_DEVICE_DESCRIPTION_LEN_MAX = 64; +// Limits.thrift + const QString EDAM_DEVICE_DESCRIPTION_REGEX = QStringLiteral("^[^\\p{Cc}]{1,64}$"); +// Limits.thrift + const qint32 EDAM_SEARCH_SUGGESTIONS_MAX = 10; +// Limits.thrift + const qint32 EDAM_SEARCH_SUGGESTIONS_PREFIX_LEN_MAX = 1024; +// Limits.thrift + const qint32 EDAM_SEARCH_SUGGESTIONS_PREFIX_LEN_MIN = 2; +// Limits.thrift + const qint32 EDAM_FIND_CONTACT_DEFAULT_MAX_RESULTS = 100; +// Limits.thrift + const qint32 EDAM_FIND_CONTACT_MAX_RESULTS = 256; +// Limits.thrift + const qint32 EDAM_NOTE_LOCK_VIEWERS_NOTES_MAX = 150; +// Limits.thrift + const qint32 EDAM_GET_ORDERS_MAX_RESULTS = 2000; +// Limits.thrift + const qint32 EDAM_MESSAGE_BODY_LEN_MAX = 2048; +// Limits.thrift + const QString EDAM_MESSAGE_BODY_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Z}]([^\\p{Cc}\\p{Zl}\\p{Zp}]{0,2046}[^\\p{Cc}\\p{Z}])?$"); +// Limits.thrift + const qint32 EDAM_MESSAGE_RECIPIENTS_MAX = 50; +// Limits.thrift + const qint32 EDAM_MESSAGE_ATTACHMENTS_MAX = 100; +// Limits.thrift + const qint32 EDAM_MESSAGE_ATTACHMENT_TITLE_LEN_MAX = 255; +// Limits.thrift + const QString EDAM_MESSAGE_ATTACHMENT_TITLE_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Z}]([^\\p{Cc}\\p{Zl}\\p{Zp}]{0,253}[^\\p{Cc}\\p{Z}])?$"); +// Limits.thrift + const qint32 EDAM_MESSAGE_ATTACHMENT_SNIPPET_LEN_MAX = 2048; +// Limits.thrift + const QString EDAM_MESSAGE_ATTACHMENT_SNIPPET_REGEX = QStringLiteral("^[^\\p{Cc}\\p{Z}]([\\n[^\\p{Cc}\\p{Zl}\\p{Zp}]]{0,2046}[^\\p{Cc}\\p{Z}])?$"); +// Limits.thrift + const qint32 EDAM_USER_PROFILE_PHOTO_MAX_BYTES = 716800; +// Limits.thrift + const qint32 EDAM_PROMOTION_ID_LEN_MAX = 32; +// Limits.thrift + const QString EDAM_PROMOTION_ID_REGEX = QStringLiteral("^[A-Za-z0-9_.-]{1,32}$"); +// Limits.thrift + const qint16 EDAM_APP_RATING_MIN = 1; +// Limits.thrift + const qint16 EDAM_APP_RATING_MAX = 5; +// Limits.thrift + const qint32 EDAM_SNIPPETS_NOTES_MAX = 24; +// Limits.thrift + const qint32 EDAM_CONNECTED_IDENTITY_REQUEST_MAX = 100; -const qint32 EDAM_OPEN_ID_ACCESS_TOKEN_MAX = 1000; +// Limits.thrift +const qint32 EDAM_OPEN_ID_ACCESS_TOKEN_MAX = 1000; // Types.thrift const QString CLASSIFICATION_RECIPE_USER_NON_RECIPE = QStringLiteral("000"); +// Types.thrift + const QString CLASSIFICATION_RECIPE_USER_RECIPE = QStringLiteral("001"); +// Types.thrift + const QString CLASSIFICATION_RECIPE_SERVICE_RECIPE = QStringLiteral("002"); +// Types.thrift + const QString EDAM_NOTE_SOURCE_WEB_CLIP = QStringLiteral("web.clip"); +// Types.thrift + const QString EDAM_NOTE_SOURCE_WEB_CLIP_SIMPLIFIED = QStringLiteral("Clearly"); +// Types.thrift + const QString EDAM_NOTE_SOURCE_MAIL_CLIP = QStringLiteral("mail.clip"); -const QString EDAM_NOTE_SOURCE_MAIL_SMTP_GATEWAY = QStringLiteral("mail.smtp"); +// Types.thrift +const QString EDAM_NOTE_SOURCE_MAIL_SMTP_GATEWAY = QStringLiteral("mail.smtp"); // UserStore.thrift const qint16 EDAM_VERSION_MAJOR = 1; +// UserStore.thrift + const qint16 EDAM_VERSION_MINOR = 28; } // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/generated/EDAMErrorCode.cpp b/src/qevercloud/QEverCloud/src/generated/EDAMErrorCode.cpp new file mode 100644 index 00000000..e8c64c7d --- /dev/null +++ b/src/qevercloud/QEverCloud/src/generated/EDAMErrorCode.cpp @@ -0,0 +1,1303 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + * + * This file was generated from Evernote Thrift API + */ + +#include +#include "../Impl.h" + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const EDAMErrorCode value) +{ + switch(value) + { + case EDAMErrorCode::UNKNOWN: + out << "EDAMErrorCode::UNKNOWN"; + break; + case EDAMErrorCode::BAD_DATA_FORMAT: + out << "EDAMErrorCode::BAD_DATA_FORMAT"; + break; + case EDAMErrorCode::PERMISSION_DENIED: + out << "EDAMErrorCode::PERMISSION_DENIED"; + break; + case EDAMErrorCode::INTERNAL_ERROR: + out << "EDAMErrorCode::INTERNAL_ERROR"; + break; + case EDAMErrorCode::DATA_REQUIRED: + out << "EDAMErrorCode::DATA_REQUIRED"; + break; + case EDAMErrorCode::LIMIT_REACHED: + out << "EDAMErrorCode::LIMIT_REACHED"; + break; + case EDAMErrorCode::QUOTA_REACHED: + out << "EDAMErrorCode::QUOTA_REACHED"; + break; + case EDAMErrorCode::INVALID_AUTH: + out << "EDAMErrorCode::INVALID_AUTH"; + break; + case EDAMErrorCode::AUTH_EXPIRED: + out << "EDAMErrorCode::AUTH_EXPIRED"; + break; + case EDAMErrorCode::DATA_CONFLICT: + out << "EDAMErrorCode::DATA_CONFLICT"; + break; + case EDAMErrorCode::ENML_VALIDATION: + out << "EDAMErrorCode::ENML_VALIDATION"; + break; + case EDAMErrorCode::SHARD_UNAVAILABLE: + out << "EDAMErrorCode::SHARD_UNAVAILABLE"; + break; + case EDAMErrorCode::LEN_TOO_SHORT: + out << "EDAMErrorCode::LEN_TOO_SHORT"; + break; + case EDAMErrorCode::LEN_TOO_LONG: + out << "EDAMErrorCode::LEN_TOO_LONG"; + break; + case EDAMErrorCode::TOO_FEW: + out << "EDAMErrorCode::TOO_FEW"; + break; + case EDAMErrorCode::TOO_MANY: + out << "EDAMErrorCode::TOO_MANY"; + break; + case EDAMErrorCode::UNSUPPORTED_OPERATION: + out << "EDAMErrorCode::UNSUPPORTED_OPERATION"; + break; + case EDAMErrorCode::TAKEN_DOWN: + out << "EDAMErrorCode::TAKEN_DOWN"; + break; + case EDAMErrorCode::RATE_LIMIT_REACHED: + out << "EDAMErrorCode::RATE_LIMIT_REACHED"; + break; + case EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED: + out << "EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED"; + break; + case EDAMErrorCode::DEVICE_LIMIT_REACHED: + out << "EDAMErrorCode::DEVICE_LIMIT_REACHED"; + break; + case EDAMErrorCode::OPENID_ALREADY_TAKEN: + out << "EDAMErrorCode::OPENID_ALREADY_TAKEN"; + break; + case EDAMErrorCode::INVALID_OPENID_TOKEN: + out << "EDAMErrorCode::INVALID_OPENID_TOKEN"; + break; + case EDAMErrorCode::USER_NOT_ASSOCIATED: + out << "EDAMErrorCode::USER_NOT_ASSOCIATED"; + break; + case EDAMErrorCode::USER_NOT_REGISTERED: + out << "EDAMErrorCode::USER_NOT_REGISTERED"; + break; + case EDAMErrorCode::USER_ALREADY_ASSOCIATED: + out << "EDAMErrorCode::USER_ALREADY_ASSOCIATED"; + break; + case EDAMErrorCode::ACCOUNT_CLEAR: + out << "EDAMErrorCode::ACCOUNT_CLEAR"; + break; + case EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED: + out << "EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const EDAMErrorCode value) +{ + switch(value) + { + case EDAMErrorCode::UNKNOWN: + out << "EDAMErrorCode::UNKNOWN"; + break; + case EDAMErrorCode::BAD_DATA_FORMAT: + out << "EDAMErrorCode::BAD_DATA_FORMAT"; + break; + case EDAMErrorCode::PERMISSION_DENIED: + out << "EDAMErrorCode::PERMISSION_DENIED"; + break; + case EDAMErrorCode::INTERNAL_ERROR: + out << "EDAMErrorCode::INTERNAL_ERROR"; + break; + case EDAMErrorCode::DATA_REQUIRED: + out << "EDAMErrorCode::DATA_REQUIRED"; + break; + case EDAMErrorCode::LIMIT_REACHED: + out << "EDAMErrorCode::LIMIT_REACHED"; + break; + case EDAMErrorCode::QUOTA_REACHED: + out << "EDAMErrorCode::QUOTA_REACHED"; + break; + case EDAMErrorCode::INVALID_AUTH: + out << "EDAMErrorCode::INVALID_AUTH"; + break; + case EDAMErrorCode::AUTH_EXPIRED: + out << "EDAMErrorCode::AUTH_EXPIRED"; + break; + case EDAMErrorCode::DATA_CONFLICT: + out << "EDAMErrorCode::DATA_CONFLICT"; + break; + case EDAMErrorCode::ENML_VALIDATION: + out << "EDAMErrorCode::ENML_VALIDATION"; + break; + case EDAMErrorCode::SHARD_UNAVAILABLE: + out << "EDAMErrorCode::SHARD_UNAVAILABLE"; + break; + case EDAMErrorCode::LEN_TOO_SHORT: + out << "EDAMErrorCode::LEN_TOO_SHORT"; + break; + case EDAMErrorCode::LEN_TOO_LONG: + out << "EDAMErrorCode::LEN_TOO_LONG"; + break; + case EDAMErrorCode::TOO_FEW: + out << "EDAMErrorCode::TOO_FEW"; + break; + case EDAMErrorCode::TOO_MANY: + out << "EDAMErrorCode::TOO_MANY"; + break; + case EDAMErrorCode::UNSUPPORTED_OPERATION: + out << "EDAMErrorCode::UNSUPPORTED_OPERATION"; + break; + case EDAMErrorCode::TAKEN_DOWN: + out << "EDAMErrorCode::TAKEN_DOWN"; + break; + case EDAMErrorCode::RATE_LIMIT_REACHED: + out << "EDAMErrorCode::RATE_LIMIT_REACHED"; + break; + case EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED: + out << "EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED"; + break; + case EDAMErrorCode::DEVICE_LIMIT_REACHED: + out << "EDAMErrorCode::DEVICE_LIMIT_REACHED"; + break; + case EDAMErrorCode::OPENID_ALREADY_TAKEN: + out << "EDAMErrorCode::OPENID_ALREADY_TAKEN"; + break; + case EDAMErrorCode::INVALID_OPENID_TOKEN: + out << "EDAMErrorCode::INVALID_OPENID_TOKEN"; + break; + case EDAMErrorCode::USER_NOT_ASSOCIATED: + out << "EDAMErrorCode::USER_NOT_ASSOCIATED"; + break; + case EDAMErrorCode::USER_NOT_REGISTERED: + out << "EDAMErrorCode::USER_NOT_REGISTERED"; + break; + case EDAMErrorCode::USER_ALREADY_ASSOCIATED: + out << "EDAMErrorCode::USER_ALREADY_ASSOCIATED"; + break; + case EDAMErrorCode::ACCOUNT_CLEAR: + out << "EDAMErrorCode::ACCOUNT_CLEAR"; + break; + case EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED: + out << "EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const EDAMInvalidContactReason value) +{ + switch(value) + { + case EDAMInvalidContactReason::BAD_ADDRESS: + out << "EDAMInvalidContactReason::BAD_ADDRESS"; + break; + case EDAMInvalidContactReason::DUPLICATE_CONTACT: + out << "EDAMInvalidContactReason::DUPLICATE_CONTACT"; + break; + case EDAMInvalidContactReason::NO_CONNECTION: + out << "EDAMInvalidContactReason::NO_CONNECTION"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const EDAMInvalidContactReason value) +{ + switch(value) + { + case EDAMInvalidContactReason::BAD_ADDRESS: + out << "EDAMInvalidContactReason::BAD_ADDRESS"; + break; + case EDAMInvalidContactReason::DUPLICATE_CONTACT: + out << "EDAMInvalidContactReason::DUPLICATE_CONTACT"; + break; + case EDAMInvalidContactReason::NO_CONNECTION: + out << "EDAMInvalidContactReason::NO_CONNECTION"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const ShareRelationshipPrivilegeLevel value) +{ + switch(value) + { + case ShareRelationshipPrivilegeLevel::READ_NOTEBOOK: + out << "ShareRelationshipPrivilegeLevel::READ_NOTEBOOK"; + break; + case ShareRelationshipPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY: + out << "ShareRelationshipPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY"; + break; + case ShareRelationshipPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY: + out << "ShareRelationshipPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY"; + break; + case ShareRelationshipPrivilegeLevel::FULL_ACCESS: + out << "ShareRelationshipPrivilegeLevel::FULL_ACCESS"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const ShareRelationshipPrivilegeLevel value) +{ + switch(value) + { + case ShareRelationshipPrivilegeLevel::READ_NOTEBOOK: + out << "ShareRelationshipPrivilegeLevel::READ_NOTEBOOK"; + break; + case ShareRelationshipPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY: + out << "ShareRelationshipPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY"; + break; + case ShareRelationshipPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY: + out << "ShareRelationshipPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY"; + break; + case ShareRelationshipPrivilegeLevel::FULL_ACCESS: + out << "ShareRelationshipPrivilegeLevel::FULL_ACCESS"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const PrivilegeLevel value) +{ + switch(value) + { + case PrivilegeLevel::NORMAL: + out << "PrivilegeLevel::NORMAL"; + break; + case PrivilegeLevel::PREMIUM: + out << "PrivilegeLevel::PREMIUM"; + break; + case PrivilegeLevel::VIP: + out << "PrivilegeLevel::VIP"; + break; + case PrivilegeLevel::MANAGER: + out << "PrivilegeLevel::MANAGER"; + break; + case PrivilegeLevel::SUPPORT: + out << "PrivilegeLevel::SUPPORT"; + break; + case PrivilegeLevel::ADMIN: + out << "PrivilegeLevel::ADMIN"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const PrivilegeLevel value) +{ + switch(value) + { + case PrivilegeLevel::NORMAL: + out << "PrivilegeLevel::NORMAL"; + break; + case PrivilegeLevel::PREMIUM: + out << "PrivilegeLevel::PREMIUM"; + break; + case PrivilegeLevel::VIP: + out << "PrivilegeLevel::VIP"; + break; + case PrivilegeLevel::MANAGER: + out << "PrivilegeLevel::MANAGER"; + break; + case PrivilegeLevel::SUPPORT: + out << "PrivilegeLevel::SUPPORT"; + break; + case PrivilegeLevel::ADMIN: + out << "PrivilegeLevel::ADMIN"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const ServiceLevel value) +{ + switch(value) + { + case ServiceLevel::BASIC: + out << "ServiceLevel::BASIC"; + break; + case ServiceLevel::PLUS: + out << "ServiceLevel::PLUS"; + break; + case ServiceLevel::PREMIUM: + out << "ServiceLevel::PREMIUM"; + break; + case ServiceLevel::BUSINESS: + out << "ServiceLevel::BUSINESS"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const ServiceLevel value) +{ + switch(value) + { + case ServiceLevel::BASIC: + out << "ServiceLevel::BASIC"; + break; + case ServiceLevel::PLUS: + out << "ServiceLevel::PLUS"; + break; + case ServiceLevel::PREMIUM: + out << "ServiceLevel::PREMIUM"; + break; + case ServiceLevel::BUSINESS: + out << "ServiceLevel::BUSINESS"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const QueryFormat value) +{ + switch(value) + { + case QueryFormat::USER: + out << "QueryFormat::USER"; + break; + case QueryFormat::SEXP: + out << "QueryFormat::SEXP"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const QueryFormat value) +{ + switch(value) + { + case QueryFormat::USER: + out << "QueryFormat::USER"; + break; + case QueryFormat::SEXP: + out << "QueryFormat::SEXP"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const NoteSortOrder value) +{ + switch(value) + { + case NoteSortOrder::CREATED: + out << "NoteSortOrder::CREATED"; + break; + case NoteSortOrder::UPDATED: + out << "NoteSortOrder::UPDATED"; + break; + case NoteSortOrder::RELEVANCE: + out << "NoteSortOrder::RELEVANCE"; + break; + case NoteSortOrder::UPDATE_SEQUENCE_NUMBER: + out << "NoteSortOrder::UPDATE_SEQUENCE_NUMBER"; + break; + case NoteSortOrder::TITLE: + out << "NoteSortOrder::TITLE"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const NoteSortOrder value) +{ + switch(value) + { + case NoteSortOrder::CREATED: + out << "NoteSortOrder::CREATED"; + break; + case NoteSortOrder::UPDATED: + out << "NoteSortOrder::UPDATED"; + break; + case NoteSortOrder::RELEVANCE: + out << "NoteSortOrder::RELEVANCE"; + break; + case NoteSortOrder::UPDATE_SEQUENCE_NUMBER: + out << "NoteSortOrder::UPDATE_SEQUENCE_NUMBER"; + break; + case NoteSortOrder::TITLE: + out << "NoteSortOrder::TITLE"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const PremiumOrderStatus value) +{ + switch(value) + { + case PremiumOrderStatus::NONE: + out << "PremiumOrderStatus::NONE"; + break; + case PremiumOrderStatus::PENDING: + out << "PremiumOrderStatus::PENDING"; + break; + case PremiumOrderStatus::ACTIVE: + out << "PremiumOrderStatus::ACTIVE"; + break; + case PremiumOrderStatus::FAILED: + out << "PremiumOrderStatus::FAILED"; + break; + case PremiumOrderStatus::CANCELLATION_PENDING: + out << "PremiumOrderStatus::CANCELLATION_PENDING"; + break; + case PremiumOrderStatus::CANCELED: + out << "PremiumOrderStatus::CANCELED"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const PremiumOrderStatus value) +{ + switch(value) + { + case PremiumOrderStatus::NONE: + out << "PremiumOrderStatus::NONE"; + break; + case PremiumOrderStatus::PENDING: + out << "PremiumOrderStatus::PENDING"; + break; + case PremiumOrderStatus::ACTIVE: + out << "PremiumOrderStatus::ACTIVE"; + break; + case PremiumOrderStatus::FAILED: + out << "PremiumOrderStatus::FAILED"; + break; + case PremiumOrderStatus::CANCELLATION_PENDING: + out << "PremiumOrderStatus::CANCELLATION_PENDING"; + break; + case PremiumOrderStatus::CANCELED: + out << "PremiumOrderStatus::CANCELED"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const SharedNotebookPrivilegeLevel value) +{ + switch(value) + { + case SharedNotebookPrivilegeLevel::READ_NOTEBOOK: + out << "SharedNotebookPrivilegeLevel::READ_NOTEBOOK"; + break; + case SharedNotebookPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY: + out << "SharedNotebookPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY"; + break; + case SharedNotebookPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY: + out << "SharedNotebookPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY"; + break; + case SharedNotebookPrivilegeLevel::GROUP: + out << "SharedNotebookPrivilegeLevel::GROUP"; + break; + case SharedNotebookPrivilegeLevel::FULL_ACCESS: + out << "SharedNotebookPrivilegeLevel::FULL_ACCESS"; + break; + case SharedNotebookPrivilegeLevel::BUSINESS_FULL_ACCESS: + out << "SharedNotebookPrivilegeLevel::BUSINESS_FULL_ACCESS"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const SharedNotebookPrivilegeLevel value) +{ + switch(value) + { + case SharedNotebookPrivilegeLevel::READ_NOTEBOOK: + out << "SharedNotebookPrivilegeLevel::READ_NOTEBOOK"; + break; + case SharedNotebookPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY: + out << "SharedNotebookPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY"; + break; + case SharedNotebookPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY: + out << "SharedNotebookPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY"; + break; + case SharedNotebookPrivilegeLevel::GROUP: + out << "SharedNotebookPrivilegeLevel::GROUP"; + break; + case SharedNotebookPrivilegeLevel::FULL_ACCESS: + out << "SharedNotebookPrivilegeLevel::FULL_ACCESS"; + break; + case SharedNotebookPrivilegeLevel::BUSINESS_FULL_ACCESS: + out << "SharedNotebookPrivilegeLevel::BUSINESS_FULL_ACCESS"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const SharedNotePrivilegeLevel value) +{ + switch(value) + { + case SharedNotePrivilegeLevel::READ_NOTE: + out << "SharedNotePrivilegeLevel::READ_NOTE"; + break; + case SharedNotePrivilegeLevel::MODIFY_NOTE: + out << "SharedNotePrivilegeLevel::MODIFY_NOTE"; + break; + case SharedNotePrivilegeLevel::FULL_ACCESS: + out << "SharedNotePrivilegeLevel::FULL_ACCESS"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const SharedNotePrivilegeLevel value) +{ + switch(value) + { + case SharedNotePrivilegeLevel::READ_NOTE: + out << "SharedNotePrivilegeLevel::READ_NOTE"; + break; + case SharedNotePrivilegeLevel::MODIFY_NOTE: + out << "SharedNotePrivilegeLevel::MODIFY_NOTE"; + break; + case SharedNotePrivilegeLevel::FULL_ACCESS: + out << "SharedNotePrivilegeLevel::FULL_ACCESS"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const SponsoredGroupRole value) +{ + switch(value) + { + case SponsoredGroupRole::GROUP_MEMBER: + out << "SponsoredGroupRole::GROUP_MEMBER"; + break; + case SponsoredGroupRole::GROUP_ADMIN: + out << "SponsoredGroupRole::GROUP_ADMIN"; + break; + case SponsoredGroupRole::GROUP_OWNER: + out << "SponsoredGroupRole::GROUP_OWNER"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const SponsoredGroupRole value) +{ + switch(value) + { + case SponsoredGroupRole::GROUP_MEMBER: + out << "SponsoredGroupRole::GROUP_MEMBER"; + break; + case SponsoredGroupRole::GROUP_ADMIN: + out << "SponsoredGroupRole::GROUP_ADMIN"; + break; + case SponsoredGroupRole::GROUP_OWNER: + out << "SponsoredGroupRole::GROUP_OWNER"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const BusinessUserRole value) +{ + switch(value) + { + case BusinessUserRole::ADMIN: + out << "BusinessUserRole::ADMIN"; + break; + case BusinessUserRole::NORMAL: + out << "BusinessUserRole::NORMAL"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const BusinessUserRole value) +{ + switch(value) + { + case BusinessUserRole::ADMIN: + out << "BusinessUserRole::ADMIN"; + break; + case BusinessUserRole::NORMAL: + out << "BusinessUserRole::NORMAL"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const BusinessUserStatus value) +{ + switch(value) + { + case BusinessUserStatus::ACTIVE: + out << "BusinessUserStatus::ACTIVE"; + break; + case BusinessUserStatus::DEACTIVATED: + out << "BusinessUserStatus::DEACTIVATED"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const BusinessUserStatus value) +{ + switch(value) + { + case BusinessUserStatus::ACTIVE: + out << "BusinessUserStatus::ACTIVE"; + break; + case BusinessUserStatus::DEACTIVATED: + out << "BusinessUserStatus::DEACTIVATED"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const SharedNotebookInstanceRestrictions value) +{ + switch(value) + { + case SharedNotebookInstanceRestrictions::ASSIGNED: + out << "SharedNotebookInstanceRestrictions::ASSIGNED"; + break; + case SharedNotebookInstanceRestrictions::NO_SHARED_NOTEBOOKS: + out << "SharedNotebookInstanceRestrictions::NO_SHARED_NOTEBOOKS"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const SharedNotebookInstanceRestrictions value) +{ + switch(value) + { + case SharedNotebookInstanceRestrictions::ASSIGNED: + out << "SharedNotebookInstanceRestrictions::ASSIGNED"; + break; + case SharedNotebookInstanceRestrictions::NO_SHARED_NOTEBOOKS: + out << "SharedNotebookInstanceRestrictions::NO_SHARED_NOTEBOOKS"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const ReminderEmailConfig value) +{ + switch(value) + { + case ReminderEmailConfig::DO_NOT_SEND: + out << "ReminderEmailConfig::DO_NOT_SEND"; + break; + case ReminderEmailConfig::SEND_DAILY_EMAIL: + out << "ReminderEmailConfig::SEND_DAILY_EMAIL"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const ReminderEmailConfig value) +{ + switch(value) + { + case ReminderEmailConfig::DO_NOT_SEND: + out << "ReminderEmailConfig::DO_NOT_SEND"; + break; + case ReminderEmailConfig::SEND_DAILY_EMAIL: + out << "ReminderEmailConfig::SEND_DAILY_EMAIL"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const BusinessInvitationStatus value) +{ + switch(value) + { + case BusinessInvitationStatus::APPROVED: + out << "BusinessInvitationStatus::APPROVED"; + break; + case BusinessInvitationStatus::REQUESTED: + out << "BusinessInvitationStatus::REQUESTED"; + break; + case BusinessInvitationStatus::REDEEMED: + out << "BusinessInvitationStatus::REDEEMED"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const BusinessInvitationStatus value) +{ + switch(value) + { + case BusinessInvitationStatus::APPROVED: + out << "BusinessInvitationStatus::APPROVED"; + break; + case BusinessInvitationStatus::REQUESTED: + out << "BusinessInvitationStatus::REQUESTED"; + break; + case BusinessInvitationStatus::REDEEMED: + out << "BusinessInvitationStatus::REDEEMED"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const ContactType value) +{ + switch(value) + { + case ContactType::EVERNOTE: + out << "ContactType::EVERNOTE"; + break; + case ContactType::SMS: + out << "ContactType::SMS"; + break; + case ContactType::FACEBOOK: + out << "ContactType::FACEBOOK"; + break; + case ContactType::EMAIL: + out << "ContactType::EMAIL"; + break; + case ContactType::TWITTER: + out << "ContactType::TWITTER"; + break; + case ContactType::LINKEDIN: + out << "ContactType::LINKEDIN"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const ContactType value) +{ + switch(value) + { + case ContactType::EVERNOTE: + out << "ContactType::EVERNOTE"; + break; + case ContactType::SMS: + out << "ContactType::SMS"; + break; + case ContactType::FACEBOOK: + out << "ContactType::FACEBOOK"; + break; + case ContactType::EMAIL: + out << "ContactType::EMAIL"; + break; + case ContactType::TWITTER: + out << "ContactType::TWITTER"; + break; + case ContactType::LINKEDIN: + out << "ContactType::LINKEDIN"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const EntityType value) +{ + switch(value) + { + case EntityType::NOTE: + out << "EntityType::NOTE"; + break; + case EntityType::NOTEBOOK: + out << "EntityType::NOTEBOOK"; + break; + case EntityType::WORKSPACE: + out << "EntityType::WORKSPACE"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const EntityType value) +{ + switch(value) + { + case EntityType::NOTE: + out << "EntityType::NOTE"; + break; + case EntityType::NOTEBOOK: + out << "EntityType::NOTEBOOK"; + break; + case EntityType::WORKSPACE: + out << "EntityType::WORKSPACE"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const RecipientStatus value) +{ + switch(value) + { + case RecipientStatus::NOT_IN_MY_LIST: + out << "RecipientStatus::NOT_IN_MY_LIST"; + break; + case RecipientStatus::IN_MY_LIST: + out << "RecipientStatus::IN_MY_LIST"; + break; + case RecipientStatus::IN_MY_LIST_AND_DEFAULT_NOTEBOOK: + out << "RecipientStatus::IN_MY_LIST_AND_DEFAULT_NOTEBOOK"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const RecipientStatus value) +{ + switch(value) + { + case RecipientStatus::NOT_IN_MY_LIST: + out << "RecipientStatus::NOT_IN_MY_LIST"; + break; + case RecipientStatus::IN_MY_LIST: + out << "RecipientStatus::IN_MY_LIST"; + break; + case RecipientStatus::IN_MY_LIST_AND_DEFAULT_NOTEBOOK: + out << "RecipientStatus::IN_MY_LIST_AND_DEFAULT_NOTEBOOK"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const CanMoveToContainerStatus value) +{ + switch(value) + { + case CanMoveToContainerStatus::CAN_BE_MOVED: + out << "CanMoveToContainerStatus::CAN_BE_MOVED"; + break; + case CanMoveToContainerStatus::INSUFFICIENT_ENTITY_PRIVILEGE: + out << "CanMoveToContainerStatus::INSUFFICIENT_ENTITY_PRIVILEGE"; + break; + case CanMoveToContainerStatus::INSUFFICIENT_CONTAINER_PRIVILEGE: + out << "CanMoveToContainerStatus::INSUFFICIENT_CONTAINER_PRIVILEGE"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const CanMoveToContainerStatus value) +{ + switch(value) + { + case CanMoveToContainerStatus::CAN_BE_MOVED: + out << "CanMoveToContainerStatus::CAN_BE_MOVED"; + break; + case CanMoveToContainerStatus::INSUFFICIENT_ENTITY_PRIVILEGE: + out << "CanMoveToContainerStatus::INSUFFICIENT_ENTITY_PRIVILEGE"; + break; + case CanMoveToContainerStatus::INSUFFICIENT_CONTAINER_PRIVILEGE: + out << "CanMoveToContainerStatus::INSUFFICIENT_CONTAINER_PRIVILEGE"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const RelatedContentType value) +{ + switch(value) + { + case RelatedContentType::NEWS_ARTICLE: + out << "RelatedContentType::NEWS_ARTICLE"; + break; + case RelatedContentType::PROFILE_PERSON: + out << "RelatedContentType::PROFILE_PERSON"; + break; + case RelatedContentType::PROFILE_ORGANIZATION: + out << "RelatedContentType::PROFILE_ORGANIZATION"; + break; + case RelatedContentType::REFERENCE_MATERIAL: + out << "RelatedContentType::REFERENCE_MATERIAL"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const RelatedContentType value) +{ + switch(value) + { + case RelatedContentType::NEWS_ARTICLE: + out << "RelatedContentType::NEWS_ARTICLE"; + break; + case RelatedContentType::PROFILE_PERSON: + out << "RelatedContentType::PROFILE_PERSON"; + break; + case RelatedContentType::PROFILE_ORGANIZATION: + out << "RelatedContentType::PROFILE_ORGANIZATION"; + break; + case RelatedContentType::REFERENCE_MATERIAL: + out << "RelatedContentType::REFERENCE_MATERIAL"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const RelatedContentAccess value) +{ + switch(value) + { + case RelatedContentAccess::NOT_ACCESSIBLE: + out << "RelatedContentAccess::NOT_ACCESSIBLE"; + break; + case RelatedContentAccess::DIRECT_LINK_ACCESS_OK: + out << "RelatedContentAccess::DIRECT_LINK_ACCESS_OK"; + break; + case RelatedContentAccess::DIRECT_LINK_LOGIN_REQUIRED: + out << "RelatedContentAccess::DIRECT_LINK_LOGIN_REQUIRED"; + break; + case RelatedContentAccess::DIRECT_LINK_EMBEDDED_VIEW: + out << "RelatedContentAccess::DIRECT_LINK_EMBEDDED_VIEW"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const RelatedContentAccess value) +{ + switch(value) + { + case RelatedContentAccess::NOT_ACCESSIBLE: + out << "RelatedContentAccess::NOT_ACCESSIBLE"; + break; + case RelatedContentAccess::DIRECT_LINK_ACCESS_OK: + out << "RelatedContentAccess::DIRECT_LINK_ACCESS_OK"; + break; + case RelatedContentAccess::DIRECT_LINK_LOGIN_REQUIRED: + out << "RelatedContentAccess::DIRECT_LINK_LOGIN_REQUIRED"; + break; + case RelatedContentAccess::DIRECT_LINK_EMBEDDED_VIEW: + out << "RelatedContentAccess::DIRECT_LINK_EMBEDDED_VIEW"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QTextStream & operator<<( + QTextStream & out, const UserIdentityType value) +{ + switch(value) + { + case UserIdentityType::EVERNOTE_USERID: + out << "UserIdentityType::EVERNOTE_USERID"; + break; + case UserIdentityType::EMAIL: + out << "UserIdentityType::EMAIL"; + break; + case UserIdentityType::IDENTITYID: + out << "UserIdentityType::IDENTITYID"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +//////////////////////////////////////////////////////////////////////////////// + +QDebug & operator<<( + QDebug & out, const UserIdentityType value) +{ + switch(value) + { + case UserIdentityType::EVERNOTE_USERID: + out << "UserIdentityType::EVERNOTE_USERID"; + break; + case UserIdentityType::EMAIL: + out << "UserIdentityType::EMAIL"; + break; + case UserIdentityType::IDENTITYID: + out << "UserIdentityType::IDENTITYID"; + break; + default: + out << "Unknown (" << static_cast(value) << ")"; + break; + } + return out; +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/generated/Servers.cpp b/src/qevercloud/QEverCloud/src/generated/Servers.cpp new file mode 100644 index 00000000..9def15a1 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/generated/Servers.cpp @@ -0,0 +1,18029 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + * + * This file was generated from Evernote Thrift API + */ + +#include +#include "../Impl.h" +#include "../Thrift.h" +#include "Types_io.h" +#include + +namespace qevercloud { + +namespace { + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetSyncStateParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getSyncState_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetFilteredSyncChunkParams( + ThriftBinaryBufferReader & reader, + qint32 & afterUSN, + qint32 & maxEntries, + SyncChunkFilter & filter, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getFilteredSyncChunk_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + afterUSN = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + maxEntries = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + SyncChunkFilter v; + readSyncChunkFilter(reader, v); + filter = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetLinkedNotebookSyncStateParams( + ThriftBinaryBufferReader & reader, + LinkedNotebook & linkedNotebook, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getLinkedNotebookSyncState_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + LinkedNotebook v; + readLinkedNotebook(reader, v); + linkedNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetLinkedNotebookSyncChunkParams( + ThriftBinaryBufferReader & reader, + LinkedNotebook & linkedNotebook, + qint32 & afterUSN, + qint32 & maxEntries, + bool & fullSyncOnly, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getLinkedNotebookSyncChunk_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + LinkedNotebook v; + readLinkedNotebook(reader, v); + linkedNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + afterUSN = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + maxEntries = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 5) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + fullSyncOnly = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreListNotebooksParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_listNotebooks_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreListAccessibleBusinessNotebooksParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_listAccessibleBusinessNotebooks_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetNotebookParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetDefaultNotebookParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getDefaultNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreCreateNotebookParams( + ThriftBinaryBufferReader & reader, + Notebook & notebook, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_createNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + Notebook v; + readNotebook(reader, v); + notebook = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreUpdateNotebookParams( + ThriftBinaryBufferReader & reader, + Notebook & notebook, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_updateNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + Notebook v; + readNotebook(reader, v); + notebook = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreExpungeNotebookParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_expungeNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreListTagsParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_listTags_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreListTagsByNotebookParams( + ThriftBinaryBufferReader & reader, + Guid & notebookGuid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_listTagsByNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + notebookGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetTagParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getTag_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreCreateTagParams( + ThriftBinaryBufferReader & reader, + Tag & tag, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_createTag_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + Tag v; + readTag(reader, v); + tag = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreUpdateTagParams( + ThriftBinaryBufferReader & reader, + Tag & tag, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_updateTag_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + Tag v; + readTag(reader, v); + tag = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreUntagAllParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_untagAll_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreExpungeTagParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_expungeTag_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreListSearchesParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_listSearches_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetSearchParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getSearch_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreCreateSearchParams( + ThriftBinaryBufferReader & reader, + SavedSearch & search, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_createSearch_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + SavedSearch v; + readSavedSearch(reader, v); + search = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreUpdateSearchParams( + ThriftBinaryBufferReader & reader, + SavedSearch & search, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_updateSearch_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + SavedSearch v; + readSavedSearch(reader, v); + search = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreExpungeSearchParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_expungeSearch_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreFindNoteOffsetParams( + ThriftBinaryBufferReader & reader, + NoteFilter & filter, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_findNoteOffset_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + NoteFilter v; + readNoteFilter(reader, v); + filter = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreFindNotesMetadataParams( + ThriftBinaryBufferReader & reader, + NoteFilter & filter, + qint32 & offset, + qint32 & maxNotes, + NotesMetadataResultSpec & resultSpec, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_findNotesMetadata_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + NoteFilter v; + readNoteFilter(reader, v); + filter = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + offset = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + maxNotes = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 5) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + NotesMetadataResultSpec v; + readNotesMetadataResultSpec(reader, v); + resultSpec = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreFindNoteCountsParams( + ThriftBinaryBufferReader & reader, + NoteFilter & filter, + bool & withTrash, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_findNoteCounts_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + NoteFilter v; + readNoteFilter(reader, v); + filter = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withTrash = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetNoteWithResultSpecParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + NoteResultSpec & resultSpec, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getNoteWithResultSpec_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + NoteResultSpec v; + readNoteResultSpec(reader, v); + resultSpec = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetNoteParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + bool & withContent, + bool & withResourcesData, + bool & withResourcesRecognition, + bool & withResourcesAlternateData, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getNote_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withContent = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withResourcesData = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 5) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withResourcesRecognition = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 6) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withResourcesAlternateData = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetNoteApplicationDataParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getNoteApplicationData_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetNoteApplicationDataEntryParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + QString & key, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getNoteApplicationDataEntry_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + key = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreSetNoteApplicationDataEntryParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + QString & key, + QString & value, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_setNoteApplicationDataEntry_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + key = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + value = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreUnsetNoteApplicationDataEntryParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + QString & key, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_unsetNoteApplicationDataEntry_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + key = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetNoteContentParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getNoteContent_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetNoteSearchTextParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + bool & noteOnly, + bool & tokenizeForIndexing, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getNoteSearchText_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + noteOnly = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + tokenizeForIndexing = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetResourceSearchTextParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getResourceSearchText_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetNoteTagNamesParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getNoteTagNames_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreCreateNoteParams( + ThriftBinaryBufferReader & reader, + Note & note, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_createNote_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + Note v; + readNote(reader, v); + note = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreUpdateNoteParams( + ThriftBinaryBufferReader & reader, + Note & note, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_updateNote_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + Note v; + readNote(reader, v); + note = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreDeleteNoteParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_deleteNote_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreExpungeNoteParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_expungeNote_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreCopyNoteParams( + ThriftBinaryBufferReader & reader, + Guid & noteGuid, + Guid & toNotebookGuid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_copyNote_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + noteGuid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + toNotebookGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreListNoteVersionsParams( + ThriftBinaryBufferReader & reader, + Guid & noteGuid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_listNoteVersions_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + noteGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetNoteVersionParams( + ThriftBinaryBufferReader & reader, + Guid & noteGuid, + qint32 & updateSequenceNum, + bool & withResourcesData, + bool & withResourcesRecognition, + bool & withResourcesAlternateData, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getNoteVersion_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + noteGuid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + updateSequenceNum = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withResourcesData = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 5) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withResourcesRecognition = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 6) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withResourcesAlternateData = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetResourceParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + bool & withData, + bool & withRecognition, + bool & withAttributes, + bool & withAlternateData, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getResource_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withData = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withRecognition = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 5) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withAttributes = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 6) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withAlternateData = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetResourceApplicationDataParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getResourceApplicationData_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetResourceApplicationDataEntryParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + QString & key, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getResourceApplicationDataEntry_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + key = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreSetResourceApplicationDataEntryParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + QString & key, + QString & value, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_setResourceApplicationDataEntry_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + key = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + value = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreUnsetResourceApplicationDataEntryParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + QString & key, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_unsetResourceApplicationDataEntry_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + key = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreUpdateResourceParams( + ThriftBinaryBufferReader & reader, + Resource & resource, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_updateResource_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + Resource v; + readResource(reader, v); + resource = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetResourceDataParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getResourceData_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetResourceByHashParams( + ThriftBinaryBufferReader & reader, + Guid & noteGuid, + QByteArray & contentHash, + bool & withData, + bool & withRecognition, + bool & withAlternateData, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getResourceByHash_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + noteGuid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + QByteArray v; + reader.readBinary(v); + contentHash = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withData = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 5) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withRecognition = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 6) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + withAlternateData = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetResourceRecognitionParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getResourceRecognition_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetResourceAlternateDataParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getResourceAlternateData_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetResourceAttributesParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getResourceAttributes_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetPublicNotebookParams( + ThriftBinaryBufferReader & reader, + UserID & userId, + QString & publicUri, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + + QString fname = + QStringLiteral("NoteStore_getPublicNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + userId = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + publicUri = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreShareNotebookParams( + ThriftBinaryBufferReader & reader, + SharedNotebook & sharedNotebook, + QString & message, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_shareNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + SharedNotebook v; + readSharedNotebook(reader, v); + sharedNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + message = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreCreateOrUpdateNotebookSharesParams( + ThriftBinaryBufferReader & reader, + NotebookShareTemplate & shareTemplate, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_createOrUpdateNotebookShares_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + NotebookShareTemplate v; + readNotebookShareTemplate(reader, v); + shareTemplate = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreUpdateSharedNotebookParams( + ThriftBinaryBufferReader & reader, + SharedNotebook & sharedNotebook, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_updateSharedNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + SharedNotebook v; + readSharedNotebook(reader, v); + sharedNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreSetNotebookRecipientSettingsParams( + ThriftBinaryBufferReader & reader, + QString & notebookGuid, + NotebookRecipientSettings & recipientSettings, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_setNotebookRecipientSettings_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + notebookGuid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + NotebookRecipientSettings v; + readNotebookRecipientSettings(reader, v); + recipientSettings = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreListSharedNotebooksParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_listSharedNotebooks_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreCreateLinkedNotebookParams( + ThriftBinaryBufferReader & reader, + LinkedNotebook & linkedNotebook, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_createLinkedNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + LinkedNotebook v; + readLinkedNotebook(reader, v); + linkedNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreUpdateLinkedNotebookParams( + ThriftBinaryBufferReader & reader, + LinkedNotebook & linkedNotebook, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_updateLinkedNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + LinkedNotebook v; + readLinkedNotebook(reader, v); + linkedNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreListLinkedNotebooksParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_listLinkedNotebooks_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreExpungeLinkedNotebookParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_expungeLinkedNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreAuthenticateToSharedNotebookParams( + ThriftBinaryBufferReader & reader, + QString & shareKeyOrGlobalId, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_authenticateToSharedNotebook_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + shareKeyOrGlobalId = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetSharedNotebookByAuthParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getSharedNotebookByAuth_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreEmailNoteParams( + ThriftBinaryBufferReader & reader, + NoteEmailParameters & parameters, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_emailNote_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + NoteEmailParameters v; + readNoteEmailParameters(reader, v); + parameters = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreShareNoteParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_shareNote_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreStopSharingNoteParams( + ThriftBinaryBufferReader & reader, + Guid & guid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_stopSharingNote_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreAuthenticateToSharedNoteParams( + ThriftBinaryBufferReader & reader, + QString & guid, + QString & noteKey, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_authenticateToSharedNote_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + guid = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + noteKey = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreFindRelatedParams( + ThriftBinaryBufferReader & reader, + RelatedQuery & query, + RelatedResultSpec & resultSpec, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_findRelated_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + RelatedQuery v; + readRelatedQuery(reader, v); + query = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + RelatedResultSpec v; + readRelatedResultSpec(reader, v); + resultSpec = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreUpdateNoteIfUsnMatchesParams( + ThriftBinaryBufferReader & reader, + Note & note, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_updateNoteIfUsnMatches_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + Note v; + readNote(reader, v); + note = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreManageNotebookSharesParams( + ThriftBinaryBufferReader & reader, + ManageNotebookSharesParameters & parameters, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_manageNotebookShares_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + ManageNotebookSharesParameters v; + readManageNotebookSharesParameters(reader, v); + parameters = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseNoteStoreGetNotebookSharesParams( + ThriftBinaryBufferReader & reader, + QString & notebookGuid, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("NoteStore_getNotebookShares_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + notebookGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreCheckVersionParams( + ThriftBinaryBufferReader & reader, + QString & clientName, + qint16 & edamVersionMajor, + qint16 & edamVersionMinor, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + + QString fname = + QStringLiteral("UserStore_checkVersion_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + clientName = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_I16) { + qint16 v; + reader.readI16(v); + edamVersionMajor = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_I16) { + qint16 v; + reader.readI16(v); + edamVersionMinor = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreGetBootstrapInfoParams( + ThriftBinaryBufferReader & reader, + QString & locale, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + + QString fname = + QStringLiteral("UserStore_getBootstrapInfo_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + locale = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreAuthenticateLongSessionParams( + ThriftBinaryBufferReader & reader, + QString & username, + QString & password, + QString & consumerKey, + QString & consumerSecret, + QString & deviceIdentifier, + QString & deviceDescription, + bool & supportsTwoFactor, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + + QString fname = + QStringLiteral("UserStore_authenticateLongSession_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + username = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + password = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + consumerKey = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + consumerSecret = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 5) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + deviceIdentifier = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 6) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + deviceDescription = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 7) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + supportsTwoFactor = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreCompleteTwoFactorAuthenticationParams( + ThriftBinaryBufferReader & reader, + QString & oneTimeCode, + QString & deviceIdentifier, + QString & deviceDescription, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("UserStore_completeTwoFactorAuthentication_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + oneTimeCode = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + deviceIdentifier = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + deviceDescription = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreRevokeLongSessionParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("UserStore_revokeLongSession_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreAuthenticateToBusinessParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("UserStore_authenticateToBusiness_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreGetUserParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("UserStore_getUser_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreGetPublicUserInfoParams( + ThriftBinaryBufferReader & reader, + QString & username, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + + QString fname = + QStringLiteral("UserStore_getPublicUserInfo_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + username = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreGetUserUrlsParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("UserStore_getUserUrls_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreInviteToBusinessParams( + ThriftBinaryBufferReader & reader, + QString & emailAddress, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("UserStore_inviteToBusiness_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + emailAddress = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreRemoveFromBusinessParams( + ThriftBinaryBufferReader & reader, + QString & emailAddress, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("UserStore_removeFromBusiness_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + emailAddress = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreUpdateBusinessUserIdentifierParams( + ThriftBinaryBufferReader & reader, + QString & oldEmailAddress, + QString & newEmailAddress, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("UserStore_updateBusinessUserIdentifier_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + oldEmailAddress = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + newEmailAddress = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreListBusinessUsersParams( + ThriftBinaryBufferReader & reader, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("UserStore_listBusinessUsers_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreListBusinessInvitationsParams( + ThriftBinaryBufferReader & reader, + bool & includeRequestedInvitations, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + QString authenticationToken; + + QString fname = + QStringLiteral("UserStore_listBusinessInvitations_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + includeRequestedInvitations = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(authenticationToken); +} + +//////////////////////////////////////////////////////////////////////////////// + +void parseUserStoreGetAccountLimitsParams( + ThriftBinaryBufferReader & reader, + ServiceLevel & serviceLevel, + IRequestContextPtr & ctx) +{ + ThriftFieldType fieldType; + qint16 fieldId; + + QString fname = + QStringLiteral("UserStore_getAccountLimits_pargs"); + + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_I32) { + ServiceLevel v; + readEnumServiceLevel(reader, v); + serviceLevel = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + ctx = newRequestContext(); +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// + +NoteStoreServer::NoteStoreServer(QObject * parent) : + QObject(parent) +{} + +void NoteStoreServer::onRequest(QByteArray data) +{ + ThriftBinaryBufferReader reader(data); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + + if (mtype != ThriftMessageType::T_CALL) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + + if (fname == QStringLiteral("getSyncState")) + { + IRequestContextPtr ctx; + + parseNoteStoreGetSyncStateParams( + reader, + ctx); + + Q_EMIT getSyncStateRequest( + ctx); + } + else if (fname == QStringLiteral("getFilteredSyncChunk")) + { + qint32 afterUSN = 0; + qint32 maxEntries = 0; + SyncChunkFilter filter; + IRequestContextPtr ctx; + + parseNoteStoreGetFilteredSyncChunkParams( + reader, + afterUSN, + maxEntries, + filter, + ctx); + + Q_EMIT getFilteredSyncChunkRequest( + afterUSN, + maxEntries, + filter, + ctx); + } + else if (fname == QStringLiteral("getLinkedNotebookSyncState")) + { + LinkedNotebook linkedNotebook; + IRequestContextPtr ctx; + + parseNoteStoreGetLinkedNotebookSyncStateParams( + reader, + linkedNotebook, + ctx); + + Q_EMIT getLinkedNotebookSyncStateRequest( + linkedNotebook, + ctx); + } + else if (fname == QStringLiteral("getLinkedNotebookSyncChunk")) + { + LinkedNotebook linkedNotebook; + qint32 afterUSN = 0; + qint32 maxEntries = 0; + bool fullSyncOnly = false; + IRequestContextPtr ctx; + + parseNoteStoreGetLinkedNotebookSyncChunkParams( + reader, + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + + Q_EMIT getLinkedNotebookSyncChunkRequest( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + } + else if (fname == QStringLiteral("listNotebooks")) + { + IRequestContextPtr ctx; + + parseNoteStoreListNotebooksParams( + reader, + ctx); + + Q_EMIT listNotebooksRequest( + ctx); + } + else if (fname == QStringLiteral("listAccessibleBusinessNotebooks")) + { + IRequestContextPtr ctx; + + parseNoteStoreListAccessibleBusinessNotebooksParams( + reader, + ctx); + + Q_EMIT listAccessibleBusinessNotebooksRequest( + ctx); + } + else if (fname == QStringLiteral("getNotebook")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreGetNotebookParams( + reader, + guid, + ctx); + + Q_EMIT getNotebookRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("getDefaultNotebook")) + { + IRequestContextPtr ctx; + + parseNoteStoreGetDefaultNotebookParams( + reader, + ctx); + + Q_EMIT getDefaultNotebookRequest( + ctx); + } + else if (fname == QStringLiteral("createNotebook")) + { + Notebook notebook; + IRequestContextPtr ctx; + + parseNoteStoreCreateNotebookParams( + reader, + notebook, + ctx); + + Q_EMIT createNotebookRequest( + notebook, + ctx); + } + else if (fname == QStringLiteral("updateNotebook")) + { + Notebook notebook; + IRequestContextPtr ctx; + + parseNoteStoreUpdateNotebookParams( + reader, + notebook, + ctx); + + Q_EMIT updateNotebookRequest( + notebook, + ctx); + } + else if (fname == QStringLiteral("expungeNotebook")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreExpungeNotebookParams( + reader, + guid, + ctx); + + Q_EMIT expungeNotebookRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("listTags")) + { + IRequestContextPtr ctx; + + parseNoteStoreListTagsParams( + reader, + ctx); + + Q_EMIT listTagsRequest( + ctx); + } + else if (fname == QStringLiteral("listTagsByNotebook")) + { + Guid notebookGuid; + IRequestContextPtr ctx; + + parseNoteStoreListTagsByNotebookParams( + reader, + notebookGuid, + ctx); + + Q_EMIT listTagsByNotebookRequest( + notebookGuid, + ctx); + } + else if (fname == QStringLiteral("getTag")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreGetTagParams( + reader, + guid, + ctx); + + Q_EMIT getTagRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("createTag")) + { + Tag tag; + IRequestContextPtr ctx; + + parseNoteStoreCreateTagParams( + reader, + tag, + ctx); + + Q_EMIT createTagRequest( + tag, + ctx); + } + else if (fname == QStringLiteral("updateTag")) + { + Tag tag; + IRequestContextPtr ctx; + + parseNoteStoreUpdateTagParams( + reader, + tag, + ctx); + + Q_EMIT updateTagRequest( + tag, + ctx); + } + else if (fname == QStringLiteral("untagAll")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreUntagAllParams( + reader, + guid, + ctx); + + Q_EMIT untagAllRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("expungeTag")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreExpungeTagParams( + reader, + guid, + ctx); + + Q_EMIT expungeTagRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("listSearches")) + { + IRequestContextPtr ctx; + + parseNoteStoreListSearchesParams( + reader, + ctx); + + Q_EMIT listSearchesRequest( + ctx); + } + else if (fname == QStringLiteral("getSearch")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreGetSearchParams( + reader, + guid, + ctx); + + Q_EMIT getSearchRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("createSearch")) + { + SavedSearch search; + IRequestContextPtr ctx; + + parseNoteStoreCreateSearchParams( + reader, + search, + ctx); + + Q_EMIT createSearchRequest( + search, + ctx); + } + else if (fname == QStringLiteral("updateSearch")) + { + SavedSearch search; + IRequestContextPtr ctx; + + parseNoteStoreUpdateSearchParams( + reader, + search, + ctx); + + Q_EMIT updateSearchRequest( + search, + ctx); + } + else if (fname == QStringLiteral("expungeSearch")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreExpungeSearchParams( + reader, + guid, + ctx); + + Q_EMIT expungeSearchRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("findNoteOffset")) + { + NoteFilter filter; + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreFindNoteOffsetParams( + reader, + filter, + guid, + ctx); + + Q_EMIT findNoteOffsetRequest( + filter, + guid, + ctx); + } + else if (fname == QStringLiteral("findNotesMetadata")) + { + NoteFilter filter; + qint32 offset = 0; + qint32 maxNotes = 0; + NotesMetadataResultSpec resultSpec; + IRequestContextPtr ctx; + + parseNoteStoreFindNotesMetadataParams( + reader, + filter, + offset, + maxNotes, + resultSpec, + ctx); + + Q_EMIT findNotesMetadataRequest( + filter, + offset, + maxNotes, + resultSpec, + ctx); + } + else if (fname == QStringLiteral("findNoteCounts")) + { + NoteFilter filter; + bool withTrash = false; + IRequestContextPtr ctx; + + parseNoteStoreFindNoteCountsParams( + reader, + filter, + withTrash, + ctx); + + Q_EMIT findNoteCountsRequest( + filter, + withTrash, + ctx); + } + else if (fname == QStringLiteral("getNoteWithResultSpec")) + { + Guid guid; + NoteResultSpec resultSpec; + IRequestContextPtr ctx; + + parseNoteStoreGetNoteWithResultSpecParams( + reader, + guid, + resultSpec, + ctx); + + Q_EMIT getNoteWithResultSpecRequest( + guid, + resultSpec, + ctx); + } + else if (fname == QStringLiteral("getNote")) + { + Guid guid; + bool withContent = false; + bool withResourcesData = false; + bool withResourcesRecognition = false; + bool withResourcesAlternateData = false; + IRequestContextPtr ctx; + + parseNoteStoreGetNoteParams( + reader, + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + Q_EMIT getNoteRequest( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + } + else if (fname == QStringLiteral("getNoteApplicationData")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreGetNoteApplicationDataParams( + reader, + guid, + ctx); + + Q_EMIT getNoteApplicationDataRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("getNoteApplicationDataEntry")) + { + Guid guid; + QString key; + IRequestContextPtr ctx; + + parseNoteStoreGetNoteApplicationDataEntryParams( + reader, + guid, + key, + ctx); + + Q_EMIT getNoteApplicationDataEntryRequest( + guid, + key, + ctx); + } + else if (fname == QStringLiteral("setNoteApplicationDataEntry")) + { + Guid guid; + QString key; + QString value; + IRequestContextPtr ctx; + + parseNoteStoreSetNoteApplicationDataEntryParams( + reader, + guid, + key, + value, + ctx); + + Q_EMIT setNoteApplicationDataEntryRequest( + guid, + key, + value, + ctx); + } + else if (fname == QStringLiteral("unsetNoteApplicationDataEntry")) + { + Guid guid; + QString key; + IRequestContextPtr ctx; + + parseNoteStoreUnsetNoteApplicationDataEntryParams( + reader, + guid, + key, + ctx); + + Q_EMIT unsetNoteApplicationDataEntryRequest( + guid, + key, + ctx); + } + else if (fname == QStringLiteral("getNoteContent")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreGetNoteContentParams( + reader, + guid, + ctx); + + Q_EMIT getNoteContentRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("getNoteSearchText")) + { + Guid guid; + bool noteOnly = false; + bool tokenizeForIndexing = false; + IRequestContextPtr ctx; + + parseNoteStoreGetNoteSearchTextParams( + reader, + guid, + noteOnly, + tokenizeForIndexing, + ctx); + + Q_EMIT getNoteSearchTextRequest( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + } + else if (fname == QStringLiteral("getResourceSearchText")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreGetResourceSearchTextParams( + reader, + guid, + ctx); + + Q_EMIT getResourceSearchTextRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("getNoteTagNames")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreGetNoteTagNamesParams( + reader, + guid, + ctx); + + Q_EMIT getNoteTagNamesRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("createNote")) + { + Note note; + IRequestContextPtr ctx; + + parseNoteStoreCreateNoteParams( + reader, + note, + ctx); + + Q_EMIT createNoteRequest( + note, + ctx); + } + else if (fname == QStringLiteral("updateNote")) + { + Note note; + IRequestContextPtr ctx; + + parseNoteStoreUpdateNoteParams( + reader, + note, + ctx); + + Q_EMIT updateNoteRequest( + note, + ctx); + } + else if (fname == QStringLiteral("deleteNote")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreDeleteNoteParams( + reader, + guid, + ctx); + + Q_EMIT deleteNoteRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("expungeNote")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreExpungeNoteParams( + reader, + guid, + ctx); + + Q_EMIT expungeNoteRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("copyNote")) + { + Guid noteGuid; + Guid toNotebookGuid; + IRequestContextPtr ctx; + + parseNoteStoreCopyNoteParams( + reader, + noteGuid, + toNotebookGuid, + ctx); + + Q_EMIT copyNoteRequest( + noteGuid, + toNotebookGuid, + ctx); + } + else if (fname == QStringLiteral("listNoteVersions")) + { + Guid noteGuid; + IRequestContextPtr ctx; + + parseNoteStoreListNoteVersionsParams( + reader, + noteGuid, + ctx); + + Q_EMIT listNoteVersionsRequest( + noteGuid, + ctx); + } + else if (fname == QStringLiteral("getNoteVersion")) + { + Guid noteGuid; + qint32 updateSequenceNum = 0; + bool withResourcesData = false; + bool withResourcesRecognition = false; + bool withResourcesAlternateData = false; + IRequestContextPtr ctx; + + parseNoteStoreGetNoteVersionParams( + reader, + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + Q_EMIT getNoteVersionRequest( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + } + else if (fname == QStringLiteral("getResource")) + { + Guid guid; + bool withData = false; + bool withRecognition = false; + bool withAttributes = false; + bool withAlternateData = false; + IRequestContextPtr ctx; + + parseNoteStoreGetResourceParams( + reader, + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + + Q_EMIT getResourceRequest( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + } + else if (fname == QStringLiteral("getResourceApplicationData")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreGetResourceApplicationDataParams( + reader, + guid, + ctx); + + Q_EMIT getResourceApplicationDataRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("getResourceApplicationDataEntry")) + { + Guid guid; + QString key; + IRequestContextPtr ctx; + + parseNoteStoreGetResourceApplicationDataEntryParams( + reader, + guid, + key, + ctx); + + Q_EMIT getResourceApplicationDataEntryRequest( + guid, + key, + ctx); + } + else if (fname == QStringLiteral("setResourceApplicationDataEntry")) + { + Guid guid; + QString key; + QString value; + IRequestContextPtr ctx; + + parseNoteStoreSetResourceApplicationDataEntryParams( + reader, + guid, + key, + value, + ctx); + + Q_EMIT setResourceApplicationDataEntryRequest( + guid, + key, + value, + ctx); + } + else if (fname == QStringLiteral("unsetResourceApplicationDataEntry")) + { + Guid guid; + QString key; + IRequestContextPtr ctx; + + parseNoteStoreUnsetResourceApplicationDataEntryParams( + reader, + guid, + key, + ctx); + + Q_EMIT unsetResourceApplicationDataEntryRequest( + guid, + key, + ctx); + } + else if (fname == QStringLiteral("updateResource")) + { + Resource resource; + IRequestContextPtr ctx; + + parseNoteStoreUpdateResourceParams( + reader, + resource, + ctx); + + Q_EMIT updateResourceRequest( + resource, + ctx); + } + else if (fname == QStringLiteral("getResourceData")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreGetResourceDataParams( + reader, + guid, + ctx); + + Q_EMIT getResourceDataRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("getResourceByHash")) + { + Guid noteGuid; + QByteArray contentHash; + bool withData = false; + bool withRecognition = false; + bool withAlternateData = false; + IRequestContextPtr ctx; + + parseNoteStoreGetResourceByHashParams( + reader, + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + + Q_EMIT getResourceByHashRequest( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + } + else if (fname == QStringLiteral("getResourceRecognition")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreGetResourceRecognitionParams( + reader, + guid, + ctx); + + Q_EMIT getResourceRecognitionRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("getResourceAlternateData")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreGetResourceAlternateDataParams( + reader, + guid, + ctx); + + Q_EMIT getResourceAlternateDataRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("getResourceAttributes")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreGetResourceAttributesParams( + reader, + guid, + ctx); + + Q_EMIT getResourceAttributesRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("getPublicNotebook")) + { + UserID userId; + QString publicUri; + IRequestContextPtr ctx; + + parseNoteStoreGetPublicNotebookParams( + reader, + userId, + publicUri, + ctx); + + Q_EMIT getPublicNotebookRequest( + userId, + publicUri, + ctx); + } + else if (fname == QStringLiteral("shareNotebook")) + { + SharedNotebook sharedNotebook; + QString message; + IRequestContextPtr ctx; + + parseNoteStoreShareNotebookParams( + reader, + sharedNotebook, + message, + ctx); + + Q_EMIT shareNotebookRequest( + sharedNotebook, + message, + ctx); + } + else if (fname == QStringLiteral("createOrUpdateNotebookShares")) + { + NotebookShareTemplate shareTemplate; + IRequestContextPtr ctx; + + parseNoteStoreCreateOrUpdateNotebookSharesParams( + reader, + shareTemplate, + ctx); + + Q_EMIT createOrUpdateNotebookSharesRequest( + shareTemplate, + ctx); + } + else if (fname == QStringLiteral("updateSharedNotebook")) + { + SharedNotebook sharedNotebook; + IRequestContextPtr ctx; + + parseNoteStoreUpdateSharedNotebookParams( + reader, + sharedNotebook, + ctx); + + Q_EMIT updateSharedNotebookRequest( + sharedNotebook, + ctx); + } + else if (fname == QStringLiteral("setNotebookRecipientSettings")) + { + QString notebookGuid; + NotebookRecipientSettings recipientSettings; + IRequestContextPtr ctx; + + parseNoteStoreSetNotebookRecipientSettingsParams( + reader, + notebookGuid, + recipientSettings, + ctx); + + Q_EMIT setNotebookRecipientSettingsRequest( + notebookGuid, + recipientSettings, + ctx); + } + else if (fname == QStringLiteral("listSharedNotebooks")) + { + IRequestContextPtr ctx; + + parseNoteStoreListSharedNotebooksParams( + reader, + ctx); + + Q_EMIT listSharedNotebooksRequest( + ctx); + } + else if (fname == QStringLiteral("createLinkedNotebook")) + { + LinkedNotebook linkedNotebook; + IRequestContextPtr ctx; + + parseNoteStoreCreateLinkedNotebookParams( + reader, + linkedNotebook, + ctx); + + Q_EMIT createLinkedNotebookRequest( + linkedNotebook, + ctx); + } + else if (fname == QStringLiteral("updateLinkedNotebook")) + { + LinkedNotebook linkedNotebook; + IRequestContextPtr ctx; + + parseNoteStoreUpdateLinkedNotebookParams( + reader, + linkedNotebook, + ctx); + + Q_EMIT updateLinkedNotebookRequest( + linkedNotebook, + ctx); + } + else if (fname == QStringLiteral("listLinkedNotebooks")) + { + IRequestContextPtr ctx; + + parseNoteStoreListLinkedNotebooksParams( + reader, + ctx); + + Q_EMIT listLinkedNotebooksRequest( + ctx); + } + else if (fname == QStringLiteral("expungeLinkedNotebook")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreExpungeLinkedNotebookParams( + reader, + guid, + ctx); + + Q_EMIT expungeLinkedNotebookRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("authenticateToSharedNotebook")) + { + QString shareKeyOrGlobalId; + IRequestContextPtr ctx; + + parseNoteStoreAuthenticateToSharedNotebookParams( + reader, + shareKeyOrGlobalId, + ctx); + + Q_EMIT authenticateToSharedNotebookRequest( + shareKeyOrGlobalId, + ctx); + } + else if (fname == QStringLiteral("getSharedNotebookByAuth")) + { + IRequestContextPtr ctx; + + parseNoteStoreGetSharedNotebookByAuthParams( + reader, + ctx); + + Q_EMIT getSharedNotebookByAuthRequest( + ctx); + } + else if (fname == QStringLiteral("emailNote")) + { + NoteEmailParameters parameters; + IRequestContextPtr ctx; + + parseNoteStoreEmailNoteParams( + reader, + parameters, + ctx); + + Q_EMIT emailNoteRequest( + parameters, + ctx); + } + else if (fname == QStringLiteral("shareNote")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreShareNoteParams( + reader, + guid, + ctx); + + Q_EMIT shareNoteRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("stopSharingNote")) + { + Guid guid; + IRequestContextPtr ctx; + + parseNoteStoreStopSharingNoteParams( + reader, + guid, + ctx); + + Q_EMIT stopSharingNoteRequest( + guid, + ctx); + } + else if (fname == QStringLiteral("authenticateToSharedNote")) + { + QString guid; + QString noteKey; + IRequestContextPtr ctx; + + parseNoteStoreAuthenticateToSharedNoteParams( + reader, + guid, + noteKey, + ctx); + + Q_EMIT authenticateToSharedNoteRequest( + guid, + noteKey, + ctx); + } + else if (fname == QStringLiteral("findRelated")) + { + RelatedQuery query; + RelatedResultSpec resultSpec; + IRequestContextPtr ctx; + + parseNoteStoreFindRelatedParams( + reader, + query, + resultSpec, + ctx); + + Q_EMIT findRelatedRequest( + query, + resultSpec, + ctx); + } + else if (fname == QStringLiteral("updateNoteIfUsnMatches")) + { + Note note; + IRequestContextPtr ctx; + + parseNoteStoreUpdateNoteIfUsnMatchesParams( + reader, + note, + ctx); + + Q_EMIT updateNoteIfUsnMatchesRequest( + note, + ctx); + } + else if (fname == QStringLiteral("manageNotebookShares")) + { + ManageNotebookSharesParameters parameters; + IRequestContextPtr ctx; + + parseNoteStoreManageNotebookSharesParams( + reader, + parameters, + ctx); + + Q_EMIT manageNotebookSharesRequest( + parameters, + ctx); + } + else if (fname == QStringLiteral("getNotebookShares")) + { + QString notebookGuid; + IRequestContextPtr ctx; + + parseNoteStoreGetNotebookSharesParams( + reader, + notebookGuid, + ctx); + + Q_EMIT getNotebookSharesRequest( + notebookGuid, + ctx); + } +} + +void NoteStoreServer::onGetSyncStateRequestReady( + SyncState value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getSyncState"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getSyncStateRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getSyncState"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getSyncState")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getSyncStateRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getSyncStateRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getSyncState"), + ThriftFieldType::T_STRUCT, + 0); + writeSyncState(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getSyncStateRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetFilteredSyncChunkRequestReady( + SyncChunk value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getFilteredSyncChunk"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getFilteredSyncChunkRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getFilteredSyncChunk"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getFilteredSyncChunk")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getFilteredSyncChunkRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getFilteredSyncChunkRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getFilteredSyncChunk"), + ThriftFieldType::T_STRUCT, + 0); + writeSyncChunk(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getFilteredSyncChunkRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetLinkedNotebookSyncStateRequestReady( + SyncState value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getLinkedNotebookSyncState"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getLinkedNotebookSyncStateRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getLinkedNotebookSyncState"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getLinkedNotebookSyncState")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getLinkedNotebookSyncStateRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getLinkedNotebookSyncStateRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getLinkedNotebookSyncStateRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getLinkedNotebookSyncState"), + ThriftFieldType::T_STRUCT, + 0); + writeSyncState(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getLinkedNotebookSyncStateRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetLinkedNotebookSyncChunkRequestReady( + SyncChunk value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getLinkedNotebookSyncChunk"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getLinkedNotebookSyncChunkRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getLinkedNotebookSyncChunk"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getLinkedNotebookSyncChunk")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getLinkedNotebookSyncChunkRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getLinkedNotebookSyncChunkRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getLinkedNotebookSyncChunkRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getLinkedNotebookSyncChunk"), + ThriftFieldType::T_STRUCT, + 0); + writeSyncChunk(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getLinkedNotebookSyncChunkRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onListNotebooksRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("listNotebooks"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT listNotebooksRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("listNotebooks"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("listNotebooks")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listNotebooksRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listNotebooksRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("listNotebooks"), + ThriftFieldType::T_LIST, + 0); + writer.writeListBegin(ThriftFieldType::T_STRUCT, value.size()); + for(const auto & v: qAsConst(value)) { + writeNotebook(writer, v); + } + writer.writeListEnd(); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listNotebooksRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onListAccessibleBusinessNotebooksRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("listAccessibleBusinessNotebooks"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT listAccessibleBusinessNotebooksRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("listAccessibleBusinessNotebooks"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("listAccessibleBusinessNotebooks")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listAccessibleBusinessNotebooksRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listAccessibleBusinessNotebooksRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("listAccessibleBusinessNotebooks"), + ThriftFieldType::T_LIST, + 0); + writer.writeListBegin(ThriftFieldType::T_STRUCT, value.size()); + for(const auto & v: qAsConst(value)) { + writeNotebook(writer, v); + } + writer.writeListEnd(); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listAccessibleBusinessNotebooksRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetNotebookRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getNotebook"), + ThriftFieldType::T_STRUCT, + 0); + writeNotebook(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetDefaultNotebookRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getDefaultNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getDefaultNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getDefaultNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getDefaultNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getDefaultNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getDefaultNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getDefaultNotebook"), + ThriftFieldType::T_STRUCT, + 0); + writeNotebook(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getDefaultNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onCreateNotebookRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("createNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT createNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("createNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("createNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("createNotebook"), + ThriftFieldType::T_STRUCT, + 0); + writeNotebook(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onUpdateNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("updateNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT updateNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("updateNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("updateNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("updateNotebook"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onExpungeNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("expungeNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT expungeNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("expungeNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("expungeNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("expungeNotebook"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onListTagsRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("listTags"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT listTagsRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("listTags"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("listTags")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listTagsRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listTagsRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("listTags"), + ThriftFieldType::T_LIST, + 0); + writer.writeListBegin(ThriftFieldType::T_STRUCT, value.size()); + for(const auto & v: qAsConst(value)) { + writeTag(writer, v); + } + writer.writeListEnd(); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listTagsRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onListTagsByNotebookRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("listTagsByNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT listTagsByNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("listTagsByNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("listTagsByNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listTagsByNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listTagsByNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listTagsByNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("listTagsByNotebook"), + ThriftFieldType::T_LIST, + 0); + writer.writeListBegin(ThriftFieldType::T_STRUCT, value.size()); + for(const auto & v: qAsConst(value)) { + writeTag(writer, v); + } + writer.writeListEnd(); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listTagsByNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetTagRequestReady( + Tag value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getTag"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getTagRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getTag"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getTag")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getTagRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getTagRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getTagRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getTag"), + ThriftFieldType::T_STRUCT, + 0); + writeTag(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getTagRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onCreateTagRequestReady( + Tag value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("createTag"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT createTagRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("createTag"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("createTag")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createTagRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createTagRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createTagRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("createTag"), + ThriftFieldType::T_STRUCT, + 0); + writeTag(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createTagRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onUpdateTagRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("updateTag"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT updateTagRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("updateTag"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("updateTag")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateTagRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateTagRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateTagRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("updateTag"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateTagRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onUntagAllRequestReady( + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("untagAll"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT untagAllRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("untagAll"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("untagAll")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT untagAllRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT untagAllRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT untagAllRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("untagAll"), + ThriftFieldType::T_VOID, + 0); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT untagAllRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onExpungeTagRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("expungeTag"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT expungeTagRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("expungeTag"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("expungeTag")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeTagRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeTagRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeTagRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("expungeTag"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeTagRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onListSearchesRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("listSearches"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT listSearchesRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("listSearches"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("listSearches")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listSearchesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listSearchesRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("listSearches"), + ThriftFieldType::T_LIST, + 0); + writer.writeListBegin(ThriftFieldType::T_STRUCT, value.size()); + for(const auto & v: qAsConst(value)) { + writeSavedSearch(writer, v); + } + writer.writeListEnd(); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listSearchesRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetSearchRequestReady( + SavedSearch value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getSearch"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getSearchRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getSearch"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getSearch")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getSearchRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getSearchRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getSearchRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getSearch"), + ThriftFieldType::T_STRUCT, + 0); + writeSavedSearch(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getSearchRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onCreateSearchRequestReady( + SavedSearch value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("createSearch"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT createSearchRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("createSearch"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("createSearch")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createSearchRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createSearchRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("createSearch"), + ThriftFieldType::T_STRUCT, + 0); + writeSavedSearch(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createSearchRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onUpdateSearchRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("updateSearch"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT updateSearchRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("updateSearch"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("updateSearch")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateSearchRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateSearchRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateSearchRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("updateSearch"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateSearchRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onExpungeSearchRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("expungeSearch"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT expungeSearchRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("expungeSearch"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("expungeSearch")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeSearchRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeSearchRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeSearchRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("expungeSearch"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeSearchRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onFindNoteOffsetRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("findNoteOffset"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT findNoteOffsetRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("findNoteOffset"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("findNoteOffset")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findNoteOffsetRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findNoteOffsetRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findNoteOffsetRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("findNoteOffset"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findNoteOffsetRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onFindNotesMetadataRequestReady( + NotesMetadataList value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("findNotesMetadata"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT findNotesMetadataRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("findNotesMetadata"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("findNotesMetadata")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findNotesMetadataRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findNotesMetadataRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findNotesMetadataRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("findNotesMetadata"), + ThriftFieldType::T_STRUCT, + 0); + writeNotesMetadataList(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findNotesMetadataRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onFindNoteCountsRequestReady( + NoteCollectionCounts value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("findNoteCounts"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT findNoteCountsRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("findNoteCounts"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("findNoteCounts")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findNoteCountsRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findNoteCountsRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findNoteCountsRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("findNoteCounts"), + ThriftFieldType::T_STRUCT, + 0); + writeNoteCollectionCounts(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findNoteCountsRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetNoteWithResultSpecRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getNoteWithResultSpec"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getNoteWithResultSpecRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getNoteWithResultSpec"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getNoteWithResultSpec")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteWithResultSpecRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteWithResultSpecRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteWithResultSpecRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getNoteWithResultSpec"), + ThriftFieldType::T_STRUCT, + 0); + writeNote(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteWithResultSpecRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetNoteRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getNote"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getNoteRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getNote"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getNote")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getNote"), + ThriftFieldType::T_STRUCT, + 0); + writeNote(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetNoteApplicationDataRequestReady( + LazyMap value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getNoteApplicationData"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getNoteApplicationDataRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getNoteApplicationData"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getNoteApplicationData")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteApplicationDataRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteApplicationDataRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteApplicationDataRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getNoteApplicationData"), + ThriftFieldType::T_STRUCT, + 0); + writeLazyMap(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteApplicationDataRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetNoteApplicationDataEntryRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getNoteApplicationDataEntry"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getNoteApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getNoteApplicationDataEntry"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getNoteApplicationDataEntry")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getNoteApplicationDataEntry"), + ThriftFieldType::T_STRING, + 0); + writer.writeString(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteApplicationDataEntryRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onSetNoteApplicationDataEntryRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("setNoteApplicationDataEntry"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT setNoteApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("setNoteApplicationDataEntry"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("setNoteApplicationDataEntry")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT setNoteApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT setNoteApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT setNoteApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("setNoteApplicationDataEntry"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT setNoteApplicationDataEntryRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onUnsetNoteApplicationDataEntryRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("unsetNoteApplicationDataEntry"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT unsetNoteApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("unsetNoteApplicationDataEntry"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("unsetNoteApplicationDataEntry")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT unsetNoteApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT unsetNoteApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT unsetNoteApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("unsetNoteApplicationDataEntry"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT unsetNoteApplicationDataEntryRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetNoteContentRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getNoteContent"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getNoteContentRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getNoteContent"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getNoteContent")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteContentRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteContentRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteContentRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getNoteContent"), + ThriftFieldType::T_STRING, + 0); + writer.writeString(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteContentRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetNoteSearchTextRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getNoteSearchText"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getNoteSearchTextRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getNoteSearchText"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getNoteSearchText")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteSearchTextRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteSearchTextRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteSearchTextRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getNoteSearchText"), + ThriftFieldType::T_STRING, + 0); + writer.writeString(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteSearchTextRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetResourceSearchTextRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getResourceSearchText"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getResourceSearchTextRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getResourceSearchText"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getResourceSearchText")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceSearchTextRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceSearchTextRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceSearchTextRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getResourceSearchText"), + ThriftFieldType::T_STRING, + 0); + writer.writeString(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceSearchTextRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetNoteTagNamesRequestReady( + QStringList value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getNoteTagNames"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getNoteTagNamesRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getNoteTagNames"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getNoteTagNames")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteTagNamesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteTagNamesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteTagNamesRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getNoteTagNames"), + ThriftFieldType::T_LIST, + 0); + writer.writeListBegin(ThriftFieldType::T_STRING, value.size()); + for(const auto & v: qAsConst(value)) { + writer.writeString(v); + } + writer.writeListEnd(); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteTagNamesRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onCreateNoteRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("createNote"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT createNoteRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("createNote"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("createNote")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createNoteRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("createNote"), + ThriftFieldType::T_STRUCT, + 0); + writeNote(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createNoteRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onUpdateNoteRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("updateNote"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT updateNoteRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("updateNote"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("updateNote")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateNoteRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("updateNote"), + ThriftFieldType::T_STRUCT, + 0); + writeNote(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateNoteRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onDeleteNoteRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("deleteNote"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT deleteNoteRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("deleteNote"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("deleteNote")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT deleteNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT deleteNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT deleteNoteRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("deleteNote"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT deleteNoteRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onExpungeNoteRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("expungeNote"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT expungeNoteRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("expungeNote"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("expungeNote")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeNoteRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("expungeNote"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeNoteRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onCopyNoteRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("copyNote"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT copyNoteRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("copyNote"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("copyNote")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT copyNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT copyNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT copyNoteRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("copyNote"), + ThriftFieldType::T_STRUCT, + 0); + writeNote(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT copyNoteRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onListNoteVersionsRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("listNoteVersions"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT listNoteVersionsRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("listNoteVersions"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("listNoteVersions")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listNoteVersionsRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listNoteVersionsRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listNoteVersionsRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("listNoteVersions"), + ThriftFieldType::T_LIST, + 0); + writer.writeListBegin(ThriftFieldType::T_STRUCT, value.size()); + for(const auto & v: qAsConst(value)) { + writeNoteVersionId(writer, v); + } + writer.writeListEnd(); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listNoteVersionsRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetNoteVersionRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getNoteVersion"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getNoteVersionRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getNoteVersion"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getNoteVersion")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteVersionRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteVersionRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteVersionRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getNoteVersion"), + ThriftFieldType::T_STRUCT, + 0); + writeNote(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNoteVersionRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetResourceRequestReady( + Resource value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getResource"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getResourceRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getResource"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getResource")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getResource"), + ThriftFieldType::T_STRUCT, + 0); + writeResource(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetResourceApplicationDataRequestReady( + LazyMap value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getResourceApplicationData"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getResourceApplicationDataRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getResourceApplicationData"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getResourceApplicationData")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceApplicationDataRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceApplicationDataRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceApplicationDataRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getResourceApplicationData"), + ThriftFieldType::T_STRUCT, + 0); + writeLazyMap(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceApplicationDataRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetResourceApplicationDataEntryRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getResourceApplicationDataEntry"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getResourceApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getResourceApplicationDataEntry"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getResourceApplicationDataEntry")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getResourceApplicationDataEntry"), + ThriftFieldType::T_STRING, + 0); + writer.writeString(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceApplicationDataEntryRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onSetResourceApplicationDataEntryRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("setResourceApplicationDataEntry"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT setResourceApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("setResourceApplicationDataEntry"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("setResourceApplicationDataEntry")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT setResourceApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT setResourceApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT setResourceApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("setResourceApplicationDataEntry"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT setResourceApplicationDataEntryRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onUnsetResourceApplicationDataEntryRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("unsetResourceApplicationDataEntry"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT unsetResourceApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("unsetResourceApplicationDataEntry"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("unsetResourceApplicationDataEntry")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT unsetResourceApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT unsetResourceApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT unsetResourceApplicationDataEntryRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("unsetResourceApplicationDataEntry"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT unsetResourceApplicationDataEntryRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onUpdateResourceRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("updateResource"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT updateResourceRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("updateResource"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("updateResource")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateResourceRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateResourceRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateResourceRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("updateResource"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateResourceRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetResourceDataRequestReady( + QByteArray value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getResourceData"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getResourceDataRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getResourceData"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getResourceData")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceDataRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceDataRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceDataRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getResourceData"), + ThriftFieldType::T_STRING, + 0); + writer.writeBinary(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceDataRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetResourceByHashRequestReady( + Resource value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getResourceByHash"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getResourceByHashRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getResourceByHash"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getResourceByHash")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceByHashRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceByHashRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceByHashRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getResourceByHash"), + ThriftFieldType::T_STRUCT, + 0); + writeResource(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceByHashRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetResourceRecognitionRequestReady( + QByteArray value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getResourceRecognition"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getResourceRecognitionRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getResourceRecognition"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getResourceRecognition")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceRecognitionRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceRecognitionRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceRecognitionRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getResourceRecognition"), + ThriftFieldType::T_STRING, + 0); + writer.writeBinary(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceRecognitionRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetResourceAlternateDataRequestReady( + QByteArray value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getResourceAlternateData"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getResourceAlternateDataRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getResourceAlternateData"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getResourceAlternateData")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceAlternateDataRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceAlternateDataRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceAlternateDataRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getResourceAlternateData"), + ThriftFieldType::T_STRING, + 0); + writer.writeBinary(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceAlternateDataRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetResourceAttributesRequestReady( + ResourceAttributes value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getResourceAttributes"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getResourceAttributesRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getResourceAttributes"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getResourceAttributes")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceAttributesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceAttributesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceAttributesRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getResourceAttributes"), + ThriftFieldType::T_STRUCT, + 0); + writeResourceAttributes(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getResourceAttributesRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetPublicNotebookRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getPublicNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getPublicNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getPublicNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getPublicNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getPublicNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getPublicNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getPublicNotebook"), + ThriftFieldType::T_STRUCT, + 0); + writeNotebook(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getPublicNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onShareNotebookRequestReady( + SharedNotebook value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("shareNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT shareNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("shareNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("shareNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT shareNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT shareNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT shareNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("shareNotebook"), + ThriftFieldType::T_STRUCT, + 0); + writeSharedNotebook(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT shareNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady( + CreateOrUpdateNotebookSharesResult value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("createOrUpdateNotebookShares"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT createOrUpdateNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("createOrUpdateNotebookShares"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("createOrUpdateNotebookShares")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createOrUpdateNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createOrUpdateNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createOrUpdateNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMInvalidContactsException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMInvalidContactsException"), + ThriftFieldType::T_STRUCT, + 4); + + writeEDAMInvalidContactsException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createOrUpdateNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("createOrUpdateNotebookShares"), + ThriftFieldType::T_STRUCT, + 0); + writeCreateOrUpdateNotebookSharesResult(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createOrUpdateNotebookSharesRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onUpdateSharedNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("updateSharedNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT updateSharedNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("updateSharedNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("updateSharedNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateSharedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateSharedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateSharedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("updateSharedNotebook"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateSharedNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onSetNotebookRecipientSettingsRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("setNotebookRecipientSettings"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT setNotebookRecipientSettingsRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("setNotebookRecipientSettings"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("setNotebookRecipientSettings")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT setNotebookRecipientSettingsRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT setNotebookRecipientSettingsRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT setNotebookRecipientSettingsRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("setNotebookRecipientSettings"), + ThriftFieldType::T_STRUCT, + 0); + writeNotebook(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT setNotebookRecipientSettingsRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onListSharedNotebooksRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("listSharedNotebooks"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT listSharedNotebooksRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("listSharedNotebooks"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("listSharedNotebooks")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listSharedNotebooksRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listSharedNotebooksRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listSharedNotebooksRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("listSharedNotebooks"), + ThriftFieldType::T_LIST, + 0); + writer.writeListBegin(ThriftFieldType::T_STRUCT, value.size()); + for(const auto & v: qAsConst(value)) { + writeSharedNotebook(writer, v); + } + writer.writeListEnd(); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listSharedNotebooksRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onCreateLinkedNotebookRequestReady( + LinkedNotebook value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("createLinkedNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT createLinkedNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("createLinkedNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("createLinkedNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createLinkedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createLinkedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createLinkedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("createLinkedNotebook"), + ThriftFieldType::T_STRUCT, + 0); + writeLinkedNotebook(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT createLinkedNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onUpdateLinkedNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("updateLinkedNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT updateLinkedNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("updateLinkedNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("updateLinkedNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateLinkedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateLinkedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateLinkedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("updateLinkedNotebook"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateLinkedNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onListLinkedNotebooksRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("listLinkedNotebooks"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT listLinkedNotebooksRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("listLinkedNotebooks"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("listLinkedNotebooks")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listLinkedNotebooksRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listLinkedNotebooksRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listLinkedNotebooksRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("listLinkedNotebooks"), + ThriftFieldType::T_LIST, + 0); + writer.writeListBegin(ThriftFieldType::T_STRUCT, value.size()); + for(const auto & v: qAsConst(value)) { + writeLinkedNotebook(writer, v); + } + writer.writeListEnd(); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listLinkedNotebooksRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onExpungeLinkedNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("expungeLinkedNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT expungeLinkedNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("expungeLinkedNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("expungeLinkedNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeLinkedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeLinkedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeLinkedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("expungeLinkedNotebook"), + ThriftFieldType::T_I32, + 0); + writer.writeI32(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT expungeLinkedNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onAuthenticateToSharedNotebookRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("authenticateToSharedNotebook"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT authenticateToSharedNotebookRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("authenticateToSharedNotebook"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("authenticateToSharedNotebook")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateToSharedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateToSharedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateToSharedNotebookRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("authenticateToSharedNotebook"), + ThriftFieldType::T_STRUCT, + 0); + writeAuthenticationResult(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateToSharedNotebookRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetSharedNotebookByAuthRequestReady( + SharedNotebook value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getSharedNotebookByAuth"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getSharedNotebookByAuthRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getSharedNotebookByAuth"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getSharedNotebookByAuth")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getSharedNotebookByAuthRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getSharedNotebookByAuthRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getSharedNotebookByAuthRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getSharedNotebookByAuth"), + ThriftFieldType::T_STRUCT, + 0); + writeSharedNotebook(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getSharedNotebookByAuthRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onEmailNoteRequestReady( + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("emailNote"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT emailNoteRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("emailNote"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("emailNote")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT emailNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT emailNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT emailNoteRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("emailNote"), + ThriftFieldType::T_VOID, + 0); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT emailNoteRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onShareNoteRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("shareNote"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT shareNoteRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("shareNote"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("shareNote")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT shareNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT shareNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT shareNoteRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("shareNote"), + ThriftFieldType::T_STRING, + 0); + writer.writeString(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT shareNoteRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onStopSharingNoteRequestReady( + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("stopSharingNote"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT stopSharingNoteRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("stopSharingNote"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("stopSharingNote")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT stopSharingNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT stopSharingNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT stopSharingNoteRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("stopSharingNote"), + ThriftFieldType::T_VOID, + 0); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT stopSharingNoteRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onAuthenticateToSharedNoteRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("authenticateToSharedNote"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT authenticateToSharedNoteRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("authenticateToSharedNote"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("authenticateToSharedNote")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateToSharedNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateToSharedNoteRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateToSharedNoteRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("authenticateToSharedNote"), + ThriftFieldType::T_STRUCT, + 0); + writeAuthenticationResult(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateToSharedNoteRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onFindRelatedRequestReady( + RelatedResult value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("findRelated"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT findRelatedRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("findRelated"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("findRelated")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findRelatedRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findRelatedRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findRelatedRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("findRelated"), + ThriftFieldType::T_STRUCT, + 0); + writeRelatedResult(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT findRelatedRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onUpdateNoteIfUsnMatchesRequestReady( + UpdateNoteIfUsnMatchesResult value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("updateNoteIfUsnMatches"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT updateNoteIfUsnMatchesRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("updateNoteIfUsnMatches"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("updateNoteIfUsnMatches")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateNoteIfUsnMatchesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateNoteIfUsnMatchesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateNoteIfUsnMatchesRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("updateNoteIfUsnMatches"), + ThriftFieldType::T_STRUCT, + 0); + writeUpdateNoteIfUsnMatchesResult(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateNoteIfUsnMatchesRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onManageNotebookSharesRequestReady( + ManageNotebookSharesResult value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("manageNotebookShares"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT manageNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("manageNotebookShares"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("manageNotebookShares")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT manageNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT manageNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT manageNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("manageNotebookShares"), + ThriftFieldType::T_STRUCT, + 0); + writeManageNotebookSharesResult(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT manageNotebookSharesRequestReady( + writer.buffer()); +} + +void NoteStoreServer::onGetNotebookSharesRequestReady( + ShareRelationships value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getNotebookShares"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getNotebookShares"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getNotebookShares")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNotebookSharesRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getNotebookShares"), + ThriftFieldType::T_STRUCT, + 0); + writeShareRelationships(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getNotebookSharesRequestReady( + writer.buffer()); +} + +//////////////////////////////////////////////////////////////////////////////// + +UserStoreServer::UserStoreServer(QObject * parent) : + QObject(parent) +{} + +void UserStoreServer::onRequest(QByteArray data) +{ + ThriftBinaryBufferReader reader(data); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + + if (mtype != ThriftMessageType::T_CALL) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + + if (fname == QStringLiteral("checkVersion")) + { + QString clientName; + qint16 edamVersionMajor = 0; + qint16 edamVersionMinor = 0; + IRequestContextPtr ctx; + + parseUserStoreCheckVersionParams( + reader, + clientName, + edamVersionMajor, + edamVersionMinor, + ctx); + + Q_EMIT checkVersionRequest( + clientName, + edamVersionMajor, + edamVersionMinor, + ctx); + } + else if (fname == QStringLiteral("getBootstrapInfo")) + { + QString locale; + IRequestContextPtr ctx; + + parseUserStoreGetBootstrapInfoParams( + reader, + locale, + ctx); + + Q_EMIT getBootstrapInfoRequest( + locale, + ctx); + } + else if (fname == QStringLiteral("authenticateLongSession")) + { + QString username; + QString password; + QString consumerKey; + QString consumerSecret; + QString deviceIdentifier; + QString deviceDescription; + bool supportsTwoFactor = false; + IRequestContextPtr ctx; + + parseUserStoreAuthenticateLongSessionParams( + reader, + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + + Q_EMIT authenticateLongSessionRequest( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + } + else if (fname == QStringLiteral("completeTwoFactorAuthentication")) + { + QString oneTimeCode; + QString deviceIdentifier; + QString deviceDescription; + IRequestContextPtr ctx; + + parseUserStoreCompleteTwoFactorAuthenticationParams( + reader, + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + + Q_EMIT completeTwoFactorAuthenticationRequest( + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + } + else if (fname == QStringLiteral("revokeLongSession")) + { + IRequestContextPtr ctx; + + parseUserStoreRevokeLongSessionParams( + reader, + ctx); + + Q_EMIT revokeLongSessionRequest( + ctx); + } + else if (fname == QStringLiteral("authenticateToBusiness")) + { + IRequestContextPtr ctx; + + parseUserStoreAuthenticateToBusinessParams( + reader, + ctx); + + Q_EMIT authenticateToBusinessRequest( + ctx); + } + else if (fname == QStringLiteral("getUser")) + { + IRequestContextPtr ctx; + + parseUserStoreGetUserParams( + reader, + ctx); + + Q_EMIT getUserRequest( + ctx); + } + else if (fname == QStringLiteral("getPublicUserInfo")) + { + QString username; + IRequestContextPtr ctx; + + parseUserStoreGetPublicUserInfoParams( + reader, + username, + ctx); + + Q_EMIT getPublicUserInfoRequest( + username, + ctx); + } + else if (fname == QStringLiteral("getUserUrls")) + { + IRequestContextPtr ctx; + + parseUserStoreGetUserUrlsParams( + reader, + ctx); + + Q_EMIT getUserUrlsRequest( + ctx); + } + else if (fname == QStringLiteral("inviteToBusiness")) + { + QString emailAddress; + IRequestContextPtr ctx; + + parseUserStoreInviteToBusinessParams( + reader, + emailAddress, + ctx); + + Q_EMIT inviteToBusinessRequest( + emailAddress, + ctx); + } + else if (fname == QStringLiteral("removeFromBusiness")) + { + QString emailAddress; + IRequestContextPtr ctx; + + parseUserStoreRemoveFromBusinessParams( + reader, + emailAddress, + ctx); + + Q_EMIT removeFromBusinessRequest( + emailAddress, + ctx); + } + else if (fname == QStringLiteral("updateBusinessUserIdentifier")) + { + QString oldEmailAddress; + QString newEmailAddress; + IRequestContextPtr ctx; + + parseUserStoreUpdateBusinessUserIdentifierParams( + reader, + oldEmailAddress, + newEmailAddress, + ctx); + + Q_EMIT updateBusinessUserIdentifierRequest( + oldEmailAddress, + newEmailAddress, + ctx); + } + else if (fname == QStringLiteral("listBusinessUsers")) + { + IRequestContextPtr ctx; + + parseUserStoreListBusinessUsersParams( + reader, + ctx); + + Q_EMIT listBusinessUsersRequest( + ctx); + } + else if (fname == QStringLiteral("listBusinessInvitations")) + { + bool includeRequestedInvitations = false; + IRequestContextPtr ctx; + + parseUserStoreListBusinessInvitationsParams( + reader, + includeRequestedInvitations, + ctx); + + Q_EMIT listBusinessInvitationsRequest( + includeRequestedInvitations, + ctx); + } + else if (fname == QStringLiteral("getAccountLimits")) + { + ServiceLevel serviceLevel; + IRequestContextPtr ctx; + + parseUserStoreGetAccountLimitsParams( + reader, + serviceLevel, + ctx); + + Q_EMIT getAccountLimitsRequest( + serviceLevel, + ctx); + } +} + +void UserStoreServer::onCheckVersionRequestReady( + bool value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("checkVersion"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT checkVersionRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("checkVersion"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("checkVersion")); + + writer.writeFieldBegin( + QStringLiteral("checkVersion"), + ThriftFieldType::T_BOOL, + 0); + writer.writeBool(value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT checkVersionRequestReady( + writer.buffer()); +} + +void UserStoreServer::onGetBootstrapInfoRequestReady( + BootstrapInfo value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getBootstrapInfo"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getBootstrapInfoRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getBootstrapInfo"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getBootstrapInfo")); + + writer.writeFieldBegin( + QStringLiteral("getBootstrapInfo"), + ThriftFieldType::T_STRUCT, + 0); + writeBootstrapInfo(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getBootstrapInfoRequestReady( + writer.buffer()); +} + +void UserStoreServer::onAuthenticateLongSessionRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("authenticateLongSession"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT authenticateLongSessionRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("authenticateLongSession"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("authenticateLongSession")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateLongSessionRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateLongSessionRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("authenticateLongSession"), + ThriftFieldType::T_STRUCT, + 0); + writeAuthenticationResult(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateLongSessionRequestReady( + writer.buffer()); +} + +void UserStoreServer::onCompleteTwoFactorAuthenticationRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("completeTwoFactorAuthentication"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT completeTwoFactorAuthenticationRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("completeTwoFactorAuthentication"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("completeTwoFactorAuthentication")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT completeTwoFactorAuthenticationRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT completeTwoFactorAuthenticationRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("completeTwoFactorAuthentication"), + ThriftFieldType::T_STRUCT, + 0); + writeAuthenticationResult(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT completeTwoFactorAuthenticationRequestReady( + writer.buffer()); +} + +void UserStoreServer::onRevokeLongSessionRequestReady( + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("revokeLongSession"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT revokeLongSessionRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("revokeLongSession"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("revokeLongSession")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT revokeLongSessionRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT revokeLongSessionRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("revokeLongSession"), + ThriftFieldType::T_VOID, + 0); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT revokeLongSessionRequestReady( + writer.buffer()); +} + +void UserStoreServer::onAuthenticateToBusinessRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("authenticateToBusiness"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT authenticateToBusinessRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("authenticateToBusiness"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("authenticateToBusiness")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateToBusinessRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateToBusinessRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("authenticateToBusiness"), + ThriftFieldType::T_STRUCT, + 0); + writeAuthenticationResult(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT authenticateToBusinessRequestReady( + writer.buffer()); +} + +void UserStoreServer::onGetUserRequestReady( + User value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getUser"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getUserRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getUser"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getUser")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getUserRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getUserRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getUser"), + ThriftFieldType::T_STRUCT, + 0); + writeUser(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getUserRequestReady( + writer.buffer()); +} + +void UserStoreServer::onGetPublicUserInfoRequestReady( + PublicUserInfo value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getPublicUserInfo"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getPublicUserInfoRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getPublicUserInfo"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getPublicUserInfo")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getPublicUserInfoRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getPublicUserInfoRequestReady( + writer.buffer()); + return; + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getPublicUserInfoRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getPublicUserInfo"), + ThriftFieldType::T_STRUCT, + 0); + writePublicUserInfo(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getPublicUserInfoRequestReady( + writer.buffer()); +} + +void UserStoreServer::onGetUserUrlsRequestReady( + UserUrls value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getUserUrls"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getUserUrlsRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getUserUrls"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getUserUrls")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getUserUrlsRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getUserUrlsRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getUserUrls"), + ThriftFieldType::T_STRUCT, + 0); + writeUserUrls(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getUserUrlsRequestReady( + writer.buffer()); +} + +void UserStoreServer::onInviteToBusinessRequestReady( + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("inviteToBusiness"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT inviteToBusinessRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("inviteToBusiness"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("inviteToBusiness")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT inviteToBusinessRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT inviteToBusinessRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("inviteToBusiness"), + ThriftFieldType::T_VOID, + 0); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT inviteToBusinessRequestReady( + writer.buffer()); +} + +void UserStoreServer::onRemoveFromBusinessRequestReady( + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("removeFromBusiness"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT removeFromBusinessRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("removeFromBusiness"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("removeFromBusiness")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT removeFromBusinessRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT removeFromBusinessRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT removeFromBusinessRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("removeFromBusiness"), + ThriftFieldType::T_VOID, + 0); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT removeFromBusinessRequestReady( + writer.buffer()); +} + +void UserStoreServer::onUpdateBusinessUserIdentifierRequestReady( + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("updateBusinessUserIdentifier"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT updateBusinessUserIdentifierRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("updateBusinessUserIdentifier"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("updateBusinessUserIdentifier")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateBusinessUserIdentifierRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateBusinessUserIdentifierRequestReady( + writer.buffer()); + return; + } + catch(const EDAMNotFoundException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMNotFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateBusinessUserIdentifierRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("updateBusinessUserIdentifier"), + ThriftFieldType::T_VOID, + 0); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT updateBusinessUserIdentifierRequestReady( + writer.buffer()); +} + +void UserStoreServer::onListBusinessUsersRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("listBusinessUsers"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT listBusinessUsersRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("listBusinessUsers"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("listBusinessUsers")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listBusinessUsersRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listBusinessUsersRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("listBusinessUsers"), + ThriftFieldType::T_LIST, + 0); + writer.writeListBegin(ThriftFieldType::T_STRUCT, value.size()); + for(const auto & v: qAsConst(value)) { + writeUserProfile(writer, v); + } + writer.writeListEnd(); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listBusinessUsersRequestReady( + writer.buffer()); +} + +void UserStoreServer::onListBusinessInvitationsRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("listBusinessInvitations"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT listBusinessInvitationsRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("listBusinessInvitations"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("listBusinessInvitations")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listBusinessInvitationsRequestReady( + writer.buffer()); + return; + } + catch(const EDAMSystemException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMSystemException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMSystemException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listBusinessInvitationsRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("listBusinessInvitations"), + ThriftFieldType::T_LIST, + 0); + writer.writeListBegin(ThriftFieldType::T_STRUCT, value.size()); + for(const auto & v: qAsConst(value)) { + writeBusinessInvitation(writer, v); + } + writer.writeListEnd(); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT listBusinessInvitationsRequestReady( + writer.buffer()); +} + +void UserStoreServer::onGetAccountLimitsRequestReady( + AccountLimits value, + EverCloudExceptionDataPtr exceptionData) +{ + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const ThriftException & exception) + { + writer.writeMessageBegin( + QStringLiteral("getAccountLimits"), + ThriftMessageType::T_EXCEPTION, + cseqid); + writeThriftException(writer, exception); + writer.writeMessageEnd(); + + Q_EMIT getAccountLimitsRequestReady( + writer.buffer()); + return; + } + catch(...) + { + // Will be handled below + } + } + + writer.writeMessageBegin( + QStringLiteral("getAccountLimits"), + ThriftMessageType::T_REPLY, + cseqid); + + writer.writeStructBegin( + QStringLiteral("getAccountLimits")); + + if (exceptionData) + { + try + { + exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + writer.writeFieldBegin( + QStringLiteral("EDAMUserException"), + ThriftFieldType::T_STRUCT, + 1); + + writeEDAMUserException(writer, e); + writer.writeFieldEnd(); + + // Finalize message and return immediately + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getAccountLimitsRequestReady( + writer.buffer()); + return; + } + catch(const std::exception & e) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception: " << e.what()); + } + catch(...) + { + // TODO: more proper error handling + QEC_ERROR("server", "Unknown exception"); + } + } + + writer.writeFieldBegin( + QStringLiteral("getAccountLimits"), + ThriftFieldType::T_STRUCT, + 0); + writeAccountLimits(writer, value); + writer.writeFieldEnd(); + + writer.writeFieldBegin(QString(), ThriftFieldType::T_STOP, 0); + writer.writeFieldEnd(); + + writer.writeStructEnd(); + writer.writeMessageEnd(); + + Q_EMIT getAccountLimitsRequestReady( + writer.buffer()); +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/generated/Services.cpp b/src/qevercloud/QEverCloud/src/generated/Services.cpp new file mode 100644 index 00000000..3d74b649 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/generated/Services.cpp @@ -0,0 +1,26197 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + * + * This file was generated from Evernote Thrift API + */ + +#include +#include "../Impl.h" +#include "../Impl.h" +#include "Types_io.h" +#include +#include +#include +#include +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +class Q_DECL_HIDDEN NoteStore: public INoteStore +{ + Q_OBJECT + Q_DISABLE_COPY(NoteStore) +public: + explicit NoteStore( + QString noteStoreUrl = {}, + IRequestContextPtr ctx = {}, + QObject * parent = nullptr) : + INoteStore(parent), + m_url(std::move(noteStoreUrl)), + m_ctx(std::move(ctx)) + { + if (!m_ctx) { + m_ctx = newRequestContext(); + } + } + + explicit NoteStore(QObject * parent) : + INoteStore(parent) + { + m_ctx = newRequestContext(); + } + + virtual void setNoteStoreUrl(QString noteStoreUrl) override + { + m_url = std::move(noteStoreUrl); + } + + virtual QString noteStoreUrl() const override + { + return m_url; + } + + virtual SyncState getSyncState( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getSyncStateAsync( + IRequestContextPtr ctx = {}) override; + + virtual SyncChunk getFilteredSyncChunk( + qint32 afterUSN, + qint32 maxEntries, + const SyncChunkFilter & filter, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getFilteredSyncChunkAsync( + qint32 afterUSN, + qint32 maxEntries, + const SyncChunkFilter & filter, + IRequestContextPtr ctx = {}) override; + + virtual SyncState getLinkedNotebookSyncState( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getLinkedNotebookSyncStateAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual SyncChunk getLinkedNotebookSyncChunk( + const LinkedNotebook & linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getLinkedNotebookSyncChunkAsync( + const LinkedNotebook & linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly, + IRequestContextPtr ctx = {}) override; + + virtual QList listNotebooks( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listNotebooksAsync( + IRequestContextPtr ctx = {}) override; + + virtual QList listAccessibleBusinessNotebooks( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listAccessibleBusinessNotebooksAsync( + IRequestContextPtr ctx = {}) override; + + virtual Notebook getNotebook( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNotebookAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual Notebook getDefaultNotebook( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getDefaultNotebookAsync( + IRequestContextPtr ctx = {}) override; + + virtual Notebook createNotebook( + const Notebook & notebook, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * createNotebookAsync( + const Notebook & notebook, + IRequestContextPtr ctx = {}) override; + + virtual qint32 updateNotebook( + const Notebook & notebook, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateNotebookAsync( + const Notebook & notebook, + IRequestContextPtr ctx = {}) override; + + virtual qint32 expungeNotebook( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * expungeNotebookAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QList listTags( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listTagsAsync( + IRequestContextPtr ctx = {}) override; + + virtual QList listTagsByNotebook( + Guid notebookGuid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listTagsByNotebookAsync( + Guid notebookGuid, + IRequestContextPtr ctx = {}) override; + + virtual Tag getTag( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getTagAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual Tag createTag( + const Tag & tag, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * createTagAsync( + const Tag & tag, + IRequestContextPtr ctx = {}) override; + + virtual qint32 updateTag( + const Tag & tag, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateTagAsync( + const Tag & tag, + IRequestContextPtr ctx = {}) override; + + virtual void untagAll( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * untagAllAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual qint32 expungeTag( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * expungeTagAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QList listSearches( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listSearchesAsync( + IRequestContextPtr ctx = {}) override; + + virtual SavedSearch getSearch( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getSearchAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual SavedSearch createSearch( + const SavedSearch & search, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * createSearchAsync( + const SavedSearch & search, + IRequestContextPtr ctx = {}) override; + + virtual qint32 updateSearch( + const SavedSearch & search, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateSearchAsync( + const SavedSearch & search, + IRequestContextPtr ctx = {}) override; + + virtual qint32 expungeSearch( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * expungeSearchAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual qint32 findNoteOffset( + const NoteFilter & filter, + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * findNoteOffsetAsync( + const NoteFilter & filter, + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual NotesMetadataList findNotesMetadata( + const NoteFilter & filter, + qint32 offset, + qint32 maxNotes, + const NotesMetadataResultSpec & resultSpec, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * findNotesMetadataAsync( + const NoteFilter & filter, + qint32 offset, + qint32 maxNotes, + const NotesMetadataResultSpec & resultSpec, + IRequestContextPtr ctx = {}) override; + + virtual NoteCollectionCounts findNoteCounts( + const NoteFilter & filter, + bool withTrash, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * findNoteCountsAsync( + const NoteFilter & filter, + bool withTrash, + IRequestContextPtr ctx = {}) override; + + virtual Note getNoteWithResultSpec( + Guid guid, + const NoteResultSpec & resultSpec, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteWithResultSpecAsync( + Guid guid, + const NoteResultSpec & resultSpec, + IRequestContextPtr ctx = {}) override; + + virtual Note getNote( + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteAsync( + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual LazyMap getNoteApplicationData( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteApplicationDataAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QString getNoteApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual qint32 setNoteApplicationDataEntry( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * setNoteApplicationDataEntryAsync( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx = {}) override; + + virtual qint32 unsetNoteApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * unsetNoteApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual QString getNoteContent( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteContentAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QString getNoteSearchText( + Guid guid, + bool noteOnly, + bool tokenizeForIndexing, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteSearchTextAsync( + Guid guid, + bool noteOnly, + bool tokenizeForIndexing, + IRequestContextPtr ctx = {}) override; + + virtual QString getResourceSearchText( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceSearchTextAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QStringList getNoteTagNames( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteTagNamesAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual Note createNote( + const Note & note, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * createNoteAsync( + const Note & note, + IRequestContextPtr ctx = {}) override; + + virtual Note updateNote( + const Note & note, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateNoteAsync( + const Note & note, + IRequestContextPtr ctx = {}) override; + + virtual qint32 deleteNote( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * deleteNoteAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual qint32 expungeNote( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * expungeNoteAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual Note copyNote( + Guid noteGuid, + Guid toNotebookGuid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * copyNoteAsync( + Guid noteGuid, + Guid toNotebookGuid, + IRequestContextPtr ctx = {}) override; + + virtual QList listNoteVersions( + Guid noteGuid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listNoteVersionsAsync( + Guid noteGuid, + IRequestContextPtr ctx = {}) override; + + virtual Note getNoteVersion( + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteVersionAsync( + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual Resource getResource( + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceAsync( + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual LazyMap getResourceApplicationData( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceApplicationDataAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QString getResourceApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual qint32 setResourceApplicationDataEntry( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * setResourceApplicationDataEntryAsync( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx = {}) override; + + virtual qint32 unsetResourceApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * unsetResourceApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual qint32 updateResource( + const Resource & resource, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateResourceAsync( + const Resource & resource, + IRequestContextPtr ctx = {}) override; + + virtual QByteArray getResourceData( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceDataAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual Resource getResourceByHash( + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceByHashAsync( + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual QByteArray getResourceRecognition( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceRecognitionAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QByteArray getResourceAlternateData( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceAlternateDataAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual ResourceAttributes getResourceAttributes( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceAttributesAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual Notebook getPublicNotebook( + UserID userId, + QString publicUri, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getPublicNotebookAsync( + UserID userId, + QString publicUri, + IRequestContextPtr ctx = {}) override; + + virtual SharedNotebook shareNotebook( + const SharedNotebook & sharedNotebook, + QString message, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * shareNotebookAsync( + const SharedNotebook & sharedNotebook, + QString message, + IRequestContextPtr ctx = {}) override; + + virtual CreateOrUpdateNotebookSharesResult createOrUpdateNotebookShares( + const NotebookShareTemplate & shareTemplate, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * createOrUpdateNotebookSharesAsync( + const NotebookShareTemplate & shareTemplate, + IRequestContextPtr ctx = {}) override; + + virtual qint32 updateSharedNotebook( + const SharedNotebook & sharedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateSharedNotebookAsync( + const SharedNotebook & sharedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual Notebook setNotebookRecipientSettings( + QString notebookGuid, + const NotebookRecipientSettings & recipientSettings, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * setNotebookRecipientSettingsAsync( + QString notebookGuid, + const NotebookRecipientSettings & recipientSettings, + IRequestContextPtr ctx = {}) override; + + virtual QList listSharedNotebooks( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listSharedNotebooksAsync( + IRequestContextPtr ctx = {}) override; + + virtual LinkedNotebook createLinkedNotebook( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * createLinkedNotebookAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual qint32 updateLinkedNotebook( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateLinkedNotebookAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual QList listLinkedNotebooks( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listLinkedNotebooksAsync( + IRequestContextPtr ctx = {}) override; + + virtual qint32 expungeLinkedNotebook( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * expungeLinkedNotebookAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AuthenticationResult authenticateToSharedNotebook( + QString shareKeyOrGlobalId, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * authenticateToSharedNotebookAsync( + QString shareKeyOrGlobalId, + IRequestContextPtr ctx = {}) override; + + virtual SharedNotebook getSharedNotebookByAuth( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getSharedNotebookByAuthAsync( + IRequestContextPtr ctx = {}) override; + + virtual void emailNote( + const NoteEmailParameters & parameters, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * emailNoteAsync( + const NoteEmailParameters & parameters, + IRequestContextPtr ctx = {}) override; + + virtual QString shareNote( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * shareNoteAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual void stopSharingNote( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * stopSharingNoteAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AuthenticationResult authenticateToSharedNote( + QString guid, + QString noteKey, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * authenticateToSharedNoteAsync( + QString guid, + QString noteKey, + IRequestContextPtr ctx = {}) override; + + virtual RelatedResult findRelated( + const RelatedQuery & query, + const RelatedResultSpec & resultSpec, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * findRelatedAsync( + const RelatedQuery & query, + const RelatedResultSpec & resultSpec, + IRequestContextPtr ctx = {}) override; + + virtual UpdateNoteIfUsnMatchesResult updateNoteIfUsnMatches( + const Note & note, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateNoteIfUsnMatchesAsync( + const Note & note, + IRequestContextPtr ctx = {}) override; + + virtual ManageNotebookSharesResult manageNotebookShares( + const ManageNotebookSharesParameters & parameters, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * manageNotebookSharesAsync( + const ManageNotebookSharesParameters & parameters, + IRequestContextPtr ctx = {}) override; + + virtual ShareRelationships getNotebookShares( + QString notebookGuid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNotebookSharesAsync( + QString notebookGuid, + IRequestContextPtr ctx = {}) override; + +private: + QString m_url; + IRequestContextPtr m_ctx; +}; + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetSyncStatePrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("note_store", "NoteStoreGetSyncStatePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getSyncState"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getSyncState_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +SyncState NoteStoreGetSyncStateReadReply(QByteArray reply) +{ + bool resultIsSet = false; + SyncState result = SyncState(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getSyncState")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + SyncState v; + readSyncState(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getSyncState: missing result")); + } + + return result; +} + +QVariant NoteStoreGetSyncStateReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetSyncStateReadReply(reply)); +} + +} // namespace + +SyncState NoteStore::getSyncState( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getSyncState: request id = " + << ctx->requestId()); + + QByteArray params = NoteStoreGetSyncStatePrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetSyncStateReadReply(reply); +} + +AsyncResult * NoteStore::getSyncStateAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getSyncStateAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetSyncStatePrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetSyncStateReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetFilteredSyncChunkPrepareParams( + QString authenticationToken, + qint32 afterUSN, + qint32 maxEntries, + const SyncChunkFilter & filter) +{ + QEC_DEBUG("note_store", "NoteStoreGetFilteredSyncChunkPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getFilteredSyncChunk"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getFilteredSyncChunk_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("afterUSN"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(afterUSN); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("maxEntries"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(maxEntries); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("filter"), + ThriftFieldType::T_STRUCT, + 4); + + writeSyncChunkFilter(writer, filter); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +SyncChunk NoteStoreGetFilteredSyncChunkReadReply(QByteArray reply) +{ + bool resultIsSet = false; + SyncChunk result = SyncChunk(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getFilteredSyncChunk")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + SyncChunk v; + readSyncChunk(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getFilteredSyncChunk: missing result")); + } + + return result; +} + +QVariant NoteStoreGetFilteredSyncChunkReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetFilteredSyncChunkReadReply(reply)); +} + +} // namespace + +SyncChunk NoteStore::getFilteredSyncChunk( + qint32 afterUSN, + qint32 maxEntries, + const SyncChunkFilter & filter, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getFilteredSyncChunk: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " afterUSN = " << afterUSN << "\n" + << " maxEntries = " << maxEntries << "\n" + << " filter = " << filter); + + QByteArray params = NoteStoreGetFilteredSyncChunkPrepareParams( + ctx->authenticationToken(), + afterUSN, + maxEntries, + filter); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetFilteredSyncChunkReadReply(reply); +} + +AsyncResult * NoteStore::getFilteredSyncChunkAsync( + qint32 afterUSN, + qint32 maxEntries, + const SyncChunkFilter & filter, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getFilteredSyncChunkAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " afterUSN = " << afterUSN << "\n" + << " maxEntries = " << maxEntries << "\n" + << " filter = " << filter); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetFilteredSyncChunkPrepareParams( + ctx->authenticationToken(), + afterUSN, + maxEntries, + filter); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetFilteredSyncChunkReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetLinkedNotebookSyncStatePrepareParams( + QString authenticationToken, + const LinkedNotebook & linkedNotebook) +{ + QEC_DEBUG("note_store", "NoteStoreGetLinkedNotebookSyncStatePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getLinkedNotebookSyncState"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getLinkedNotebookSyncState_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("linkedNotebook"), + ThriftFieldType::T_STRUCT, + 2); + + writeLinkedNotebook(writer, linkedNotebook); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +SyncState NoteStoreGetLinkedNotebookSyncStateReadReply(QByteArray reply) +{ + bool resultIsSet = false; + SyncState result = SyncState(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getLinkedNotebookSyncState")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + SyncState v; + readSyncState(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getLinkedNotebookSyncState: missing result")); + } + + return result; +} + +QVariant NoteStoreGetLinkedNotebookSyncStateReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetLinkedNotebookSyncStateReadReply(reply)); +} + +} // namespace + +SyncState NoteStore::getLinkedNotebookSyncState( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getLinkedNotebookSyncState: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " linkedNotebook = " << linkedNotebook); + + QByteArray params = NoteStoreGetLinkedNotebookSyncStatePrepareParams( + ctx->authenticationToken(), + linkedNotebook); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetLinkedNotebookSyncStateReadReply(reply); +} + +AsyncResult * NoteStore::getLinkedNotebookSyncStateAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getLinkedNotebookSyncStateAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " linkedNotebook = " << linkedNotebook); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetLinkedNotebookSyncStatePrepareParams( + ctx->authenticationToken(), + linkedNotebook); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetLinkedNotebookSyncStateReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetLinkedNotebookSyncChunkPrepareParams( + QString authenticationToken, + const LinkedNotebook & linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly) +{ + QEC_DEBUG("note_store", "NoteStoreGetLinkedNotebookSyncChunkPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getLinkedNotebookSyncChunk"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getLinkedNotebookSyncChunk_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("linkedNotebook"), + ThriftFieldType::T_STRUCT, + 2); + + writeLinkedNotebook(writer, linkedNotebook); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("afterUSN"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(afterUSN); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("maxEntries"), + ThriftFieldType::T_I32, + 4); + + writer.writeI32(maxEntries); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("fullSyncOnly"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(fullSyncOnly); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +SyncChunk NoteStoreGetLinkedNotebookSyncChunkReadReply(QByteArray reply) +{ + bool resultIsSet = false; + SyncChunk result = SyncChunk(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getLinkedNotebookSyncChunk")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + SyncChunk v; + readSyncChunk(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getLinkedNotebookSyncChunk: missing result")); + } + + return result; +} + +QVariant NoteStoreGetLinkedNotebookSyncChunkReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetLinkedNotebookSyncChunkReadReply(reply)); +} + +} // namespace + +SyncChunk NoteStore::getLinkedNotebookSyncChunk( + const LinkedNotebook & linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getLinkedNotebookSyncChunk: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " linkedNotebook = " << linkedNotebook << "\n" + << " afterUSN = " << afterUSN << "\n" + << " maxEntries = " << maxEntries << "\n" + << " fullSyncOnly = " << fullSyncOnly); + + QByteArray params = NoteStoreGetLinkedNotebookSyncChunkPrepareParams( + ctx->authenticationToken(), + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetLinkedNotebookSyncChunkReadReply(reply); +} + +AsyncResult * NoteStore::getLinkedNotebookSyncChunkAsync( + const LinkedNotebook & linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getLinkedNotebookSyncChunkAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " linkedNotebook = " << linkedNotebook << "\n" + << " afterUSN = " << afterUSN << "\n" + << " maxEntries = " << maxEntries << "\n" + << " fullSyncOnly = " << fullSyncOnly); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetLinkedNotebookSyncChunkPrepareParams( + ctx->authenticationToken(), + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetLinkedNotebookSyncChunkReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreListNotebooksPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("note_store", "NoteStoreListNotebooksPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("listNotebooks"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_listNotebooks_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QList NoteStoreListNotebooksReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QList result = QList(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("listNotebooks")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_LIST) { + resultIsSet = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (listNotebooks.result)")); + } + for(qint32 i = 0; i < size; i++) { + Notebook elem; + readNotebook(reader, elem); + v.append(elem); + } + reader.readListEnd(); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("listNotebooks: missing result")); + } + + return result; +} + +QVariant NoteStoreListNotebooksReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreListNotebooksReadReply(reply)); +} + +} // namespace + +QList NoteStore::listNotebooks( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::listNotebooks: request id = " + << ctx->requestId()); + + QByteArray params = NoteStoreListNotebooksPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreListNotebooksReadReply(reply); +} + +AsyncResult * NoteStore::listNotebooksAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::listNotebooksAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreListNotebooksPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreListNotebooksReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreListAccessibleBusinessNotebooksPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("note_store", "NoteStoreListAccessibleBusinessNotebooksPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("listAccessibleBusinessNotebooks"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_listAccessibleBusinessNotebooks_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QList NoteStoreListAccessibleBusinessNotebooksReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QList result = QList(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("listAccessibleBusinessNotebooks")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_LIST) { + resultIsSet = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (listAccessibleBusinessNotebooks.result)")); + } + for(qint32 i = 0; i < size; i++) { + Notebook elem; + readNotebook(reader, elem); + v.append(elem); + } + reader.readListEnd(); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("listAccessibleBusinessNotebooks: missing result")); + } + + return result; +} + +QVariant NoteStoreListAccessibleBusinessNotebooksReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreListAccessibleBusinessNotebooksReadReply(reply)); +} + +} // namespace + +QList NoteStore::listAccessibleBusinessNotebooks( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::listAccessibleBusinessNotebooks: request id = " + << ctx->requestId()); + + QByteArray params = NoteStoreListAccessibleBusinessNotebooksPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreListAccessibleBusinessNotebooksReadReply(reply); +} + +AsyncResult * NoteStore::listAccessibleBusinessNotebooksAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::listAccessibleBusinessNotebooksAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreListAccessibleBusinessNotebooksPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreListAccessibleBusinessNotebooksReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetNotebookPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreGetNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Notebook NoteStoreGetNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Notebook result = Notebook(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Notebook v; + readNotebook(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreGetNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetNotebookReadReply(reply)); +} + +} // namespace + +Notebook NoteStore::getNotebook( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getNotebook: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreGetNotebookPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetNotebookReadReply(reply); +} + +AsyncResult * NoteStore::getNotebookAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getNotebookAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetNotebookPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetDefaultNotebookPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("note_store", "NoteStoreGetDefaultNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getDefaultNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getDefaultNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Notebook NoteStoreGetDefaultNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Notebook result = Notebook(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getDefaultNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Notebook v; + readNotebook(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getDefaultNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreGetDefaultNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetDefaultNotebookReadReply(reply)); +} + +} // namespace + +Notebook NoteStore::getDefaultNotebook( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getDefaultNotebook: request id = " + << ctx->requestId()); + + QByteArray params = NoteStoreGetDefaultNotebookPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetDefaultNotebookReadReply(reply); +} + +AsyncResult * NoteStore::getDefaultNotebookAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getDefaultNotebookAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetDefaultNotebookPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetDefaultNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreCreateNotebookPrepareParams( + QString authenticationToken, + const Notebook & notebook) +{ + QEC_DEBUG("note_store", "NoteStoreCreateNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("createNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_createNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("notebook"), + ThriftFieldType::T_STRUCT, + 2); + + writeNotebook(writer, notebook); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Notebook NoteStoreCreateNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Notebook result = Notebook(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("createNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Notebook v; + readNotebook(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("createNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreCreateNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreCreateNotebookReadReply(reply)); +} + +} // namespace + +Notebook NoteStore::createNotebook( + const Notebook & notebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::createNotebook: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " notebook = " << notebook); + + QByteArray params = NoteStoreCreateNotebookPrepareParams( + ctx->authenticationToken(), + notebook); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreCreateNotebookReadReply(reply); +} + +AsyncResult * NoteStore::createNotebookAsync( + const Notebook & notebook, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::createNotebookAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " notebook = " << notebook); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreCreateNotebookPrepareParams( + ctx->authenticationToken(), + notebook); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreCreateNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreUpdateNotebookPrepareParams( + QString authenticationToken, + const Notebook & notebook) +{ + QEC_DEBUG("note_store", "NoteStoreUpdateNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("updateNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_updateNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("notebook"), + ThriftFieldType::T_STRUCT, + 2); + + writeNotebook(writer, notebook); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreUpdateNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("updateNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("updateNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreUpdateNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreUpdateNotebookReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::updateNotebook( + const Notebook & notebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::updateNotebook: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " notebook = " << notebook); + + QByteArray params = NoteStoreUpdateNotebookPrepareParams( + ctx->authenticationToken(), + notebook); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreUpdateNotebookReadReply(reply); +} + +AsyncResult * NoteStore::updateNotebookAsync( + const Notebook & notebook, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::updateNotebookAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " notebook = " << notebook); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreUpdateNotebookPrepareParams( + ctx->authenticationToken(), + notebook); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreUpdateNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreExpungeNotebookPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreExpungeNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("expungeNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_expungeNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreExpungeNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("expungeNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("expungeNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreExpungeNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreExpungeNotebookReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::expungeNotebook( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::expungeNotebook: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreExpungeNotebookPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreExpungeNotebookReadReply(reply); +} + +AsyncResult * NoteStore::expungeNotebookAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::expungeNotebookAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreExpungeNotebookPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreExpungeNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreListTagsPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("note_store", "NoteStoreListTagsPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("listTags"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_listTags_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QList NoteStoreListTagsReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QList result = QList(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("listTags")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_LIST) { + resultIsSet = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (listTags.result)")); + } + for(qint32 i = 0; i < size; i++) { + Tag elem; + readTag(reader, elem); + v.append(elem); + } + reader.readListEnd(); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("listTags: missing result")); + } + + return result; +} + +QVariant NoteStoreListTagsReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreListTagsReadReply(reply)); +} + +} // namespace + +QList NoteStore::listTags( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::listTags: request id = " + << ctx->requestId()); + + QByteArray params = NoteStoreListTagsPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreListTagsReadReply(reply); +} + +AsyncResult * NoteStore::listTagsAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::listTagsAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreListTagsPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreListTagsReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreListTagsByNotebookPrepareParams( + QString authenticationToken, + Guid notebookGuid) +{ + QEC_DEBUG("note_store", "NoteStoreListTagsByNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("listTagsByNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_listTagsByNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("notebookGuid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(notebookGuid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QList NoteStoreListTagsByNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QList result = QList(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("listTagsByNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_LIST) { + resultIsSet = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (listTagsByNotebook.result)")); + } + for(qint32 i = 0; i < size; i++) { + Tag elem; + readTag(reader, elem); + v.append(elem); + } + reader.readListEnd(); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("listTagsByNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreListTagsByNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreListTagsByNotebookReadReply(reply)); +} + +} // namespace + +QList NoteStore::listTagsByNotebook( + Guid notebookGuid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::listTagsByNotebook: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " notebookGuid = " << notebookGuid); + + QByteArray params = NoteStoreListTagsByNotebookPrepareParams( + ctx->authenticationToken(), + notebookGuid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreListTagsByNotebookReadReply(reply); +} + +AsyncResult * NoteStore::listTagsByNotebookAsync( + Guid notebookGuid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::listTagsByNotebookAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " notebookGuid = " << notebookGuid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreListTagsByNotebookPrepareParams( + ctx->authenticationToken(), + notebookGuid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreListTagsByNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetTagPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreGetTagPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getTag"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getTag_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Tag NoteStoreGetTagReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Tag result = Tag(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getTag")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Tag v; + readTag(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getTag: missing result")); + } + + return result; +} + +QVariant NoteStoreGetTagReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetTagReadReply(reply)); +} + +} // namespace + +Tag NoteStore::getTag( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getTag: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreGetTagPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetTagReadReply(reply); +} + +AsyncResult * NoteStore::getTagAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getTagAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetTagPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetTagReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreCreateTagPrepareParams( + QString authenticationToken, + const Tag & tag) +{ + QEC_DEBUG("note_store", "NoteStoreCreateTagPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("createTag"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_createTag_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("tag"), + ThriftFieldType::T_STRUCT, + 2); + + writeTag(writer, tag); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Tag NoteStoreCreateTagReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Tag result = Tag(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("createTag")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Tag v; + readTag(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("createTag: missing result")); + } + + return result; +} + +QVariant NoteStoreCreateTagReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreCreateTagReadReply(reply)); +} + +} // namespace + +Tag NoteStore::createTag( + const Tag & tag, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::createTag: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " tag = " << tag); + + QByteArray params = NoteStoreCreateTagPrepareParams( + ctx->authenticationToken(), + tag); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreCreateTagReadReply(reply); +} + +AsyncResult * NoteStore::createTagAsync( + const Tag & tag, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::createTagAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " tag = " << tag); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreCreateTagPrepareParams( + ctx->authenticationToken(), + tag); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreCreateTagReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreUpdateTagPrepareParams( + QString authenticationToken, + const Tag & tag) +{ + QEC_DEBUG("note_store", "NoteStoreUpdateTagPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("updateTag"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_updateTag_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("tag"), + ThriftFieldType::T_STRUCT, + 2); + + writeTag(writer, tag); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreUpdateTagReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("updateTag")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("updateTag: missing result")); + } + + return result; +} + +QVariant NoteStoreUpdateTagReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreUpdateTagReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::updateTag( + const Tag & tag, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::updateTag: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " tag = " << tag); + + QByteArray params = NoteStoreUpdateTagPrepareParams( + ctx->authenticationToken(), + tag); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreUpdateTagReadReply(reply); +} + +AsyncResult * NoteStore::updateTagAsync( + const Tag & tag, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::updateTagAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " tag = " << tag); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreUpdateTagPrepareParams( + ctx->authenticationToken(), + tag); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreUpdateTagReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreUntagAllPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreUntagAllPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("untagAll"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_untagAll_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +void NoteStoreUntagAllReadReply(QByteArray reply) +{ + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("untagAll")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + +} + +QVariant NoteStoreUntagAllReadReplyAsync(QByteArray reply) +{ + NoteStoreUntagAllReadReply(reply); + return QVariant(); +} + +} // namespace + +void NoteStore::untagAll( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::untagAll: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreUntagAllPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + NoteStoreUntagAllReadReply(reply); +} + +AsyncResult * NoteStore::untagAllAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::untagAllAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreUntagAllPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreUntagAllReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreExpungeTagPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreExpungeTagPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("expungeTag"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_expungeTag_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreExpungeTagReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("expungeTag")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("expungeTag: missing result")); + } + + return result; +} + +QVariant NoteStoreExpungeTagReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreExpungeTagReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::expungeTag( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::expungeTag: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreExpungeTagPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreExpungeTagReadReply(reply); +} + +AsyncResult * NoteStore::expungeTagAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::expungeTagAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreExpungeTagPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreExpungeTagReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreListSearchesPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("note_store", "NoteStoreListSearchesPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("listSearches"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_listSearches_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QList NoteStoreListSearchesReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QList result = QList(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("listSearches")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_LIST) { + resultIsSet = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (listSearches.result)")); + } + for(qint32 i = 0; i < size; i++) { + SavedSearch elem; + readSavedSearch(reader, elem); + v.append(elem); + } + reader.readListEnd(); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("listSearches: missing result")); + } + + return result; +} + +QVariant NoteStoreListSearchesReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreListSearchesReadReply(reply)); +} + +} // namespace + +QList NoteStore::listSearches( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::listSearches: request id = " + << ctx->requestId()); + + QByteArray params = NoteStoreListSearchesPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreListSearchesReadReply(reply); +} + +AsyncResult * NoteStore::listSearchesAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::listSearchesAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreListSearchesPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreListSearchesReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetSearchPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreGetSearchPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getSearch"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getSearch_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +SavedSearch NoteStoreGetSearchReadReply(QByteArray reply) +{ + bool resultIsSet = false; + SavedSearch result = SavedSearch(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getSearch")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + SavedSearch v; + readSavedSearch(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getSearch: missing result")); + } + + return result; +} + +QVariant NoteStoreGetSearchReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetSearchReadReply(reply)); +} + +} // namespace + +SavedSearch NoteStore::getSearch( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getSearch: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreGetSearchPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetSearchReadReply(reply); +} + +AsyncResult * NoteStore::getSearchAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getSearchAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetSearchPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetSearchReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreCreateSearchPrepareParams( + QString authenticationToken, + const SavedSearch & search) +{ + QEC_DEBUG("note_store", "NoteStoreCreateSearchPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("createSearch"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_createSearch_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("search"), + ThriftFieldType::T_STRUCT, + 2); + + writeSavedSearch(writer, search); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +SavedSearch NoteStoreCreateSearchReadReply(QByteArray reply) +{ + bool resultIsSet = false; + SavedSearch result = SavedSearch(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("createSearch")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + SavedSearch v; + readSavedSearch(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("createSearch: missing result")); + } + + return result; +} + +QVariant NoteStoreCreateSearchReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreCreateSearchReadReply(reply)); +} + +} // namespace + +SavedSearch NoteStore::createSearch( + const SavedSearch & search, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::createSearch: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " search = " << search); + + QByteArray params = NoteStoreCreateSearchPrepareParams( + ctx->authenticationToken(), + search); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreCreateSearchReadReply(reply); +} + +AsyncResult * NoteStore::createSearchAsync( + const SavedSearch & search, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::createSearchAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " search = " << search); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreCreateSearchPrepareParams( + ctx->authenticationToken(), + search); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreCreateSearchReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreUpdateSearchPrepareParams( + QString authenticationToken, + const SavedSearch & search) +{ + QEC_DEBUG("note_store", "NoteStoreUpdateSearchPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("updateSearch"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_updateSearch_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("search"), + ThriftFieldType::T_STRUCT, + 2); + + writeSavedSearch(writer, search); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreUpdateSearchReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("updateSearch")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("updateSearch: missing result")); + } + + return result; +} + +QVariant NoteStoreUpdateSearchReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreUpdateSearchReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::updateSearch( + const SavedSearch & search, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::updateSearch: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " search = " << search); + + QByteArray params = NoteStoreUpdateSearchPrepareParams( + ctx->authenticationToken(), + search); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreUpdateSearchReadReply(reply); +} + +AsyncResult * NoteStore::updateSearchAsync( + const SavedSearch & search, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::updateSearchAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " search = " << search); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreUpdateSearchPrepareParams( + ctx->authenticationToken(), + search); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreUpdateSearchReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreExpungeSearchPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreExpungeSearchPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("expungeSearch"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_expungeSearch_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreExpungeSearchReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("expungeSearch")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("expungeSearch: missing result")); + } + + return result; +} + +QVariant NoteStoreExpungeSearchReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreExpungeSearchReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::expungeSearch( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::expungeSearch: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreExpungeSearchPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreExpungeSearchReadReply(reply); +} + +AsyncResult * NoteStore::expungeSearchAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::expungeSearchAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreExpungeSearchPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreExpungeSearchReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreFindNoteOffsetPrepareParams( + QString authenticationToken, + const NoteFilter & filter, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreFindNoteOffsetPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("findNoteOffset"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_findNoteOffset_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("filter"), + ThriftFieldType::T_STRUCT, + 2); + + writeNoteFilter(writer, filter); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreFindNoteOffsetReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("findNoteOffset")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("findNoteOffset: missing result")); + } + + return result; +} + +QVariant NoteStoreFindNoteOffsetReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreFindNoteOffsetReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::findNoteOffset( + const NoteFilter & filter, + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::findNoteOffset: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " filter = " << filter << "\n" + << " guid = " << guid); + + QByteArray params = NoteStoreFindNoteOffsetPrepareParams( + ctx->authenticationToken(), + filter, + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreFindNoteOffsetReadReply(reply); +} + +AsyncResult * NoteStore::findNoteOffsetAsync( + const NoteFilter & filter, + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::findNoteOffsetAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " filter = " << filter << "\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreFindNoteOffsetPrepareParams( + ctx->authenticationToken(), + filter, + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreFindNoteOffsetReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreFindNotesMetadataPrepareParams( + QString authenticationToken, + const NoteFilter & filter, + qint32 offset, + qint32 maxNotes, + const NotesMetadataResultSpec & resultSpec) +{ + QEC_DEBUG("note_store", "NoteStoreFindNotesMetadataPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("findNotesMetadata"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_findNotesMetadata_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("filter"), + ThriftFieldType::T_STRUCT, + 2); + + writeNoteFilter(writer, filter); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("offset"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(offset); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("maxNotes"), + ThriftFieldType::T_I32, + 4); + + writer.writeI32(maxNotes); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("resultSpec"), + ThriftFieldType::T_STRUCT, + 5); + + writeNotesMetadataResultSpec(writer, resultSpec); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +NotesMetadataList NoteStoreFindNotesMetadataReadReply(QByteArray reply) +{ + bool resultIsSet = false; + NotesMetadataList result = NotesMetadataList(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("findNotesMetadata")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + NotesMetadataList v; + readNotesMetadataList(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("findNotesMetadata: missing result")); + } + + return result; +} + +QVariant NoteStoreFindNotesMetadataReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreFindNotesMetadataReadReply(reply)); +} + +} // namespace + +NotesMetadataList NoteStore::findNotesMetadata( + const NoteFilter & filter, + qint32 offset, + qint32 maxNotes, + const NotesMetadataResultSpec & resultSpec, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::findNotesMetadata: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " filter = " << filter << "\n" + << " offset = " << offset << "\n" + << " maxNotes = " << maxNotes << "\n" + << " resultSpec = " << resultSpec); + + QByteArray params = NoteStoreFindNotesMetadataPrepareParams( + ctx->authenticationToken(), + filter, + offset, + maxNotes, + resultSpec); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreFindNotesMetadataReadReply(reply); +} + +AsyncResult * NoteStore::findNotesMetadataAsync( + const NoteFilter & filter, + qint32 offset, + qint32 maxNotes, + const NotesMetadataResultSpec & resultSpec, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::findNotesMetadataAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " filter = " << filter << "\n" + << " offset = " << offset << "\n" + << " maxNotes = " << maxNotes << "\n" + << " resultSpec = " << resultSpec); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreFindNotesMetadataPrepareParams( + ctx->authenticationToken(), + filter, + offset, + maxNotes, + resultSpec); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreFindNotesMetadataReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreFindNoteCountsPrepareParams( + QString authenticationToken, + const NoteFilter & filter, + bool withTrash) +{ + QEC_DEBUG("note_store", "NoteStoreFindNoteCountsPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("findNoteCounts"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_findNoteCounts_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("filter"), + ThriftFieldType::T_STRUCT, + 2); + + writeNoteFilter(writer, filter); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withTrash"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(withTrash); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +NoteCollectionCounts NoteStoreFindNoteCountsReadReply(QByteArray reply) +{ + bool resultIsSet = false; + NoteCollectionCounts result = NoteCollectionCounts(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("findNoteCounts")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + NoteCollectionCounts v; + readNoteCollectionCounts(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("findNoteCounts: missing result")); + } + + return result; +} + +QVariant NoteStoreFindNoteCountsReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreFindNoteCountsReadReply(reply)); +} + +} // namespace + +NoteCollectionCounts NoteStore::findNoteCounts( + const NoteFilter & filter, + bool withTrash, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::findNoteCounts: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " filter = " << filter << "\n" + << " withTrash = " << withTrash); + + QByteArray params = NoteStoreFindNoteCountsPrepareParams( + ctx->authenticationToken(), + filter, + withTrash); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreFindNoteCountsReadReply(reply); +} + +AsyncResult * NoteStore::findNoteCountsAsync( + const NoteFilter & filter, + bool withTrash, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::findNoteCountsAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " filter = " << filter << "\n" + << " withTrash = " << withTrash); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreFindNoteCountsPrepareParams( + ctx->authenticationToken(), + filter, + withTrash); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreFindNoteCountsReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetNoteWithResultSpecPrepareParams( + QString authenticationToken, + Guid guid, + const NoteResultSpec & resultSpec) +{ + QEC_DEBUG("note_store", "NoteStoreGetNoteWithResultSpecPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getNoteWithResultSpec"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getNoteWithResultSpec_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("resultSpec"), + ThriftFieldType::T_STRUCT, + 3); + + writeNoteResultSpec(writer, resultSpec); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Note NoteStoreGetNoteWithResultSpecReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Note result = Note(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getNoteWithResultSpec")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Note v; + readNote(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getNoteWithResultSpec: missing result")); + } + + return result; +} + +QVariant NoteStoreGetNoteWithResultSpecReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetNoteWithResultSpecReadReply(reply)); +} + +} // namespace + +Note NoteStore::getNoteWithResultSpec( + Guid guid, + const NoteResultSpec & resultSpec, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getNoteWithResultSpec: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " resultSpec = " << resultSpec); + + QByteArray params = NoteStoreGetNoteWithResultSpecPrepareParams( + ctx->authenticationToken(), + guid, + resultSpec); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetNoteWithResultSpecReadReply(reply); +} + +AsyncResult * NoteStore::getNoteWithResultSpecAsync( + Guid guid, + const NoteResultSpec & resultSpec, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getNoteWithResultSpecAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " resultSpec = " << resultSpec); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetNoteWithResultSpecPrepareParams( + ctx->authenticationToken(), + guid, + resultSpec); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetNoteWithResultSpecReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetNotePrepareParams( + QString authenticationToken, + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData) +{ + QEC_DEBUG("note_store", "NoteStoreGetNotePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getNote"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getNote_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withContent"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(withContent); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withResourcesData"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(withResourcesData); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withResourcesRecognition"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(withResourcesRecognition); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withResourcesAlternateData"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(withResourcesAlternateData); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Note NoteStoreGetNoteReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Note result = Note(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getNote")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Note v; + readNote(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getNote: missing result")); + } + + return result; +} + +QVariant NoteStoreGetNoteReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetNoteReadReply(reply)); +} + +} // namespace + +Note NoteStore::getNote( + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getNote: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " withContent = " << withContent << "\n" + << " withResourcesData = " << withResourcesData << "\n" + << " withResourcesRecognition = " << withResourcesRecognition << "\n" + << " withResourcesAlternateData = " << withResourcesAlternateData); + + QByteArray params = NoteStoreGetNotePrepareParams( + ctx->authenticationToken(), + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetNoteReadReply(reply); +} + +AsyncResult * NoteStore::getNoteAsync( + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getNoteAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " withContent = " << withContent << "\n" + << " withResourcesData = " << withResourcesData << "\n" + << " withResourcesRecognition = " << withResourcesRecognition << "\n" + << " withResourcesAlternateData = " << withResourcesAlternateData); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetNotePrepareParams( + ctx->authenticationToken(), + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetNoteReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetNoteApplicationDataPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreGetNoteApplicationDataPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getNoteApplicationData"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getNoteApplicationData_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +LazyMap NoteStoreGetNoteApplicationDataReadReply(QByteArray reply) +{ + bool resultIsSet = false; + LazyMap result = LazyMap(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getNoteApplicationData")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + LazyMap v; + readLazyMap(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getNoteApplicationData: missing result")); + } + + return result; +} + +QVariant NoteStoreGetNoteApplicationDataReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetNoteApplicationDataReadReply(reply)); +} + +} // namespace + +LazyMap NoteStore::getNoteApplicationData( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getNoteApplicationData: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreGetNoteApplicationDataPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetNoteApplicationDataReadReply(reply); +} + +AsyncResult * NoteStore::getNoteApplicationDataAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getNoteApplicationDataAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetNoteApplicationDataPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetNoteApplicationDataReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetNoteApplicationDataEntryPrepareParams( + QString authenticationToken, + Guid guid, + QString key) +{ + QEC_DEBUG("note_store", "NoteStoreGetNoteApplicationDataEntryPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getNoteApplicationDataEntry"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getNoteApplicationDataEntry_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("key"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(key); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QString NoteStoreGetNoteApplicationDataEntryReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QString result = QString(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getNoteApplicationDataEntry")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRING) { + resultIsSet = true; + QString v; + reader.readString(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getNoteApplicationDataEntry: missing result")); + } + + return result; +} + +QVariant NoteStoreGetNoteApplicationDataEntryReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetNoteApplicationDataEntryReadReply(reply)); +} + +} // namespace + +QString NoteStore::getNoteApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getNoteApplicationDataEntry: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " key = " << key); + + QByteArray params = NoteStoreGetNoteApplicationDataEntryPrepareParams( + ctx->authenticationToken(), + guid, + key); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetNoteApplicationDataEntryReadReply(reply); +} + +AsyncResult * NoteStore::getNoteApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getNoteApplicationDataEntryAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " key = " << key); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetNoteApplicationDataEntryPrepareParams( + ctx->authenticationToken(), + guid, + key); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetNoteApplicationDataEntryReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreSetNoteApplicationDataEntryPrepareParams( + QString authenticationToken, + Guid guid, + QString key, + QString value) +{ + QEC_DEBUG("note_store", "NoteStoreSetNoteApplicationDataEntryPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("setNoteApplicationDataEntry"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_setNoteApplicationDataEntry_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("key"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(key); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("value"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(value); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreSetNoteApplicationDataEntryReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("setNoteApplicationDataEntry")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("setNoteApplicationDataEntry: missing result")); + } + + return result; +} + +QVariant NoteStoreSetNoteApplicationDataEntryReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreSetNoteApplicationDataEntryReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::setNoteApplicationDataEntry( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::setNoteApplicationDataEntry: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " key = " << key << "\n" + << " value = " << value); + + QByteArray params = NoteStoreSetNoteApplicationDataEntryPrepareParams( + ctx->authenticationToken(), + guid, + key, + value); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreSetNoteApplicationDataEntryReadReply(reply); +} + +AsyncResult * NoteStore::setNoteApplicationDataEntryAsync( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::setNoteApplicationDataEntryAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " key = " << key << "\n" + << " value = " << value); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreSetNoteApplicationDataEntryPrepareParams( + ctx->authenticationToken(), + guid, + key, + value); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreSetNoteApplicationDataEntryReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreUnsetNoteApplicationDataEntryPrepareParams( + QString authenticationToken, + Guid guid, + QString key) +{ + QEC_DEBUG("note_store", "NoteStoreUnsetNoteApplicationDataEntryPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("unsetNoteApplicationDataEntry"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_unsetNoteApplicationDataEntry_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("key"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(key); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreUnsetNoteApplicationDataEntryReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("unsetNoteApplicationDataEntry")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("unsetNoteApplicationDataEntry: missing result")); + } + + return result; +} + +QVariant NoteStoreUnsetNoteApplicationDataEntryReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreUnsetNoteApplicationDataEntryReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::unsetNoteApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::unsetNoteApplicationDataEntry: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " key = " << key); + + QByteArray params = NoteStoreUnsetNoteApplicationDataEntryPrepareParams( + ctx->authenticationToken(), + guid, + key); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreUnsetNoteApplicationDataEntryReadReply(reply); +} + +AsyncResult * NoteStore::unsetNoteApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::unsetNoteApplicationDataEntryAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " key = " << key); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreUnsetNoteApplicationDataEntryPrepareParams( + ctx->authenticationToken(), + guid, + key); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreUnsetNoteApplicationDataEntryReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetNoteContentPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreGetNoteContentPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getNoteContent"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getNoteContent_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QString NoteStoreGetNoteContentReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QString result = QString(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getNoteContent")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRING) { + resultIsSet = true; + QString v; + reader.readString(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getNoteContent: missing result")); + } + + return result; +} + +QVariant NoteStoreGetNoteContentReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetNoteContentReadReply(reply)); +} + +} // namespace + +QString NoteStore::getNoteContent( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getNoteContent: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreGetNoteContentPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetNoteContentReadReply(reply); +} + +AsyncResult * NoteStore::getNoteContentAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getNoteContentAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetNoteContentPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetNoteContentReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetNoteSearchTextPrepareParams( + QString authenticationToken, + Guid guid, + bool noteOnly, + bool tokenizeForIndexing) +{ + QEC_DEBUG("note_store", "NoteStoreGetNoteSearchTextPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getNoteSearchText"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getNoteSearchText_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("noteOnly"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(noteOnly); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("tokenizeForIndexing"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(tokenizeForIndexing); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QString NoteStoreGetNoteSearchTextReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QString result = QString(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getNoteSearchText")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRING) { + resultIsSet = true; + QString v; + reader.readString(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getNoteSearchText: missing result")); + } + + return result; +} + +QVariant NoteStoreGetNoteSearchTextReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetNoteSearchTextReadReply(reply)); +} + +} // namespace + +QString NoteStore::getNoteSearchText( + Guid guid, + bool noteOnly, + bool tokenizeForIndexing, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getNoteSearchText: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " noteOnly = " << noteOnly << "\n" + << " tokenizeForIndexing = " << tokenizeForIndexing); + + QByteArray params = NoteStoreGetNoteSearchTextPrepareParams( + ctx->authenticationToken(), + guid, + noteOnly, + tokenizeForIndexing); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetNoteSearchTextReadReply(reply); +} + +AsyncResult * NoteStore::getNoteSearchTextAsync( + Guid guid, + bool noteOnly, + bool tokenizeForIndexing, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getNoteSearchTextAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " noteOnly = " << noteOnly << "\n" + << " tokenizeForIndexing = " << tokenizeForIndexing); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetNoteSearchTextPrepareParams( + ctx->authenticationToken(), + guid, + noteOnly, + tokenizeForIndexing); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetNoteSearchTextReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetResourceSearchTextPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreGetResourceSearchTextPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getResourceSearchText"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getResourceSearchText_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QString NoteStoreGetResourceSearchTextReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QString result = QString(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getResourceSearchText")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRING) { + resultIsSet = true; + QString v; + reader.readString(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getResourceSearchText: missing result")); + } + + return result; +} + +QVariant NoteStoreGetResourceSearchTextReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetResourceSearchTextReadReply(reply)); +} + +} // namespace + +QString NoteStore::getResourceSearchText( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getResourceSearchText: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreGetResourceSearchTextPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetResourceSearchTextReadReply(reply); +} + +AsyncResult * NoteStore::getResourceSearchTextAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getResourceSearchTextAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetResourceSearchTextPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetResourceSearchTextReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetNoteTagNamesPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreGetNoteTagNamesPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getNoteTagNames"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getNoteTagNames_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QStringList NoteStoreGetNoteTagNamesReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QStringList result = QStringList(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getNoteTagNames")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_LIST) { + resultIsSet = true; + QStringList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (getNoteTagNames.result)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getNoteTagNames: missing result")); + } + + return result; +} + +QVariant NoteStoreGetNoteTagNamesReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetNoteTagNamesReadReply(reply)); +} + +} // namespace + +QStringList NoteStore::getNoteTagNames( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getNoteTagNames: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreGetNoteTagNamesPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetNoteTagNamesReadReply(reply); +} + +AsyncResult * NoteStore::getNoteTagNamesAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getNoteTagNamesAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetNoteTagNamesPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetNoteTagNamesReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreCreateNotePrepareParams( + QString authenticationToken, + const Note & note) +{ + QEC_DEBUG("note_store", "NoteStoreCreateNotePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("createNote"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_createNote_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("note"), + ThriftFieldType::T_STRUCT, + 2); + + writeNote(writer, note); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Note NoteStoreCreateNoteReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Note result = Note(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("createNote")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Note v; + readNote(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("createNote: missing result")); + } + + return result; +} + +QVariant NoteStoreCreateNoteReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreCreateNoteReadReply(reply)); +} + +} // namespace + +Note NoteStore::createNote( + const Note & note, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::createNote: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " note = " << note); + + QByteArray params = NoteStoreCreateNotePrepareParams( + ctx->authenticationToken(), + note); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreCreateNoteReadReply(reply); +} + +AsyncResult * NoteStore::createNoteAsync( + const Note & note, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::createNoteAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " note = " << note); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreCreateNotePrepareParams( + ctx->authenticationToken(), + note); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreCreateNoteReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreUpdateNotePrepareParams( + QString authenticationToken, + const Note & note) +{ + QEC_DEBUG("note_store", "NoteStoreUpdateNotePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("updateNote"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_updateNote_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("note"), + ThriftFieldType::T_STRUCT, + 2); + + writeNote(writer, note); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Note NoteStoreUpdateNoteReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Note result = Note(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("updateNote")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Note v; + readNote(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("updateNote: missing result")); + } + + return result; +} + +QVariant NoteStoreUpdateNoteReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreUpdateNoteReadReply(reply)); +} + +} // namespace + +Note NoteStore::updateNote( + const Note & note, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::updateNote: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " note = " << note); + + QByteArray params = NoteStoreUpdateNotePrepareParams( + ctx->authenticationToken(), + note); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreUpdateNoteReadReply(reply); +} + +AsyncResult * NoteStore::updateNoteAsync( + const Note & note, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::updateNoteAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " note = " << note); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreUpdateNotePrepareParams( + ctx->authenticationToken(), + note); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreUpdateNoteReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreDeleteNotePrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreDeleteNotePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("deleteNote"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_deleteNote_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreDeleteNoteReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("deleteNote")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("deleteNote: missing result")); + } + + return result; +} + +QVariant NoteStoreDeleteNoteReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreDeleteNoteReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::deleteNote( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::deleteNote: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreDeleteNotePrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreDeleteNoteReadReply(reply); +} + +AsyncResult * NoteStore::deleteNoteAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::deleteNoteAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreDeleteNotePrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreDeleteNoteReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreExpungeNotePrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreExpungeNotePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("expungeNote"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_expungeNote_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreExpungeNoteReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("expungeNote")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("expungeNote: missing result")); + } + + return result; +} + +QVariant NoteStoreExpungeNoteReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreExpungeNoteReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::expungeNote( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::expungeNote: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreExpungeNotePrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreExpungeNoteReadReply(reply); +} + +AsyncResult * NoteStore::expungeNoteAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::expungeNoteAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreExpungeNotePrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreExpungeNoteReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreCopyNotePrepareParams( + QString authenticationToken, + Guid noteGuid, + Guid toNotebookGuid) +{ + QEC_DEBUG("note_store", "NoteStoreCopyNotePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("copyNote"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_copyNote_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("noteGuid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(noteGuid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("toNotebookGuid"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(toNotebookGuid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Note NoteStoreCopyNoteReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Note result = Note(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("copyNote")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Note v; + readNote(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("copyNote: missing result")); + } + + return result; +} + +QVariant NoteStoreCopyNoteReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreCopyNoteReadReply(reply)); +} + +} // namespace + +Note NoteStore::copyNote( + Guid noteGuid, + Guid toNotebookGuid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::copyNote: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " noteGuid = " << noteGuid << "\n" + << " toNotebookGuid = " << toNotebookGuid); + + QByteArray params = NoteStoreCopyNotePrepareParams( + ctx->authenticationToken(), + noteGuid, + toNotebookGuid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreCopyNoteReadReply(reply); +} + +AsyncResult * NoteStore::copyNoteAsync( + Guid noteGuid, + Guid toNotebookGuid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::copyNoteAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " noteGuid = " << noteGuid << "\n" + << " toNotebookGuid = " << toNotebookGuid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreCopyNotePrepareParams( + ctx->authenticationToken(), + noteGuid, + toNotebookGuid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreCopyNoteReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreListNoteVersionsPrepareParams( + QString authenticationToken, + Guid noteGuid) +{ + QEC_DEBUG("note_store", "NoteStoreListNoteVersionsPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("listNoteVersions"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_listNoteVersions_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("noteGuid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(noteGuid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QList NoteStoreListNoteVersionsReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QList result = QList(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("listNoteVersions")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_LIST) { + resultIsSet = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (listNoteVersions.result)")); + } + for(qint32 i = 0; i < size; i++) { + NoteVersionId elem; + readNoteVersionId(reader, elem); + v.append(elem); + } + reader.readListEnd(); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("listNoteVersions: missing result")); + } + + return result; +} + +QVariant NoteStoreListNoteVersionsReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreListNoteVersionsReadReply(reply)); +} + +} // namespace + +QList NoteStore::listNoteVersions( + Guid noteGuid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::listNoteVersions: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " noteGuid = " << noteGuid); + + QByteArray params = NoteStoreListNoteVersionsPrepareParams( + ctx->authenticationToken(), + noteGuid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreListNoteVersionsReadReply(reply); +} + +AsyncResult * NoteStore::listNoteVersionsAsync( + Guid noteGuid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::listNoteVersionsAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " noteGuid = " << noteGuid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreListNoteVersionsPrepareParams( + ctx->authenticationToken(), + noteGuid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreListNoteVersionsReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetNoteVersionPrepareParams( + QString authenticationToken, + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData) +{ + QEC_DEBUG("note_store", "NoteStoreGetNoteVersionPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getNoteVersion"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getNoteVersion_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("noteGuid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(noteGuid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("updateSequenceNum"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(updateSequenceNum); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withResourcesData"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(withResourcesData); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withResourcesRecognition"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(withResourcesRecognition); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withResourcesAlternateData"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(withResourcesAlternateData); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Note NoteStoreGetNoteVersionReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Note result = Note(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getNoteVersion")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Note v; + readNote(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getNoteVersion: missing result")); + } + + return result; +} + +QVariant NoteStoreGetNoteVersionReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetNoteVersionReadReply(reply)); +} + +} // namespace + +Note NoteStore::getNoteVersion( + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getNoteVersion: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " noteGuid = " << noteGuid << "\n" + << " updateSequenceNum = " << updateSequenceNum << "\n" + << " withResourcesData = " << withResourcesData << "\n" + << " withResourcesRecognition = " << withResourcesRecognition << "\n" + << " withResourcesAlternateData = " << withResourcesAlternateData); + + QByteArray params = NoteStoreGetNoteVersionPrepareParams( + ctx->authenticationToken(), + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetNoteVersionReadReply(reply); +} + +AsyncResult * NoteStore::getNoteVersionAsync( + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getNoteVersionAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " noteGuid = " << noteGuid << "\n" + << " updateSequenceNum = " << updateSequenceNum << "\n" + << " withResourcesData = " << withResourcesData << "\n" + << " withResourcesRecognition = " << withResourcesRecognition << "\n" + << " withResourcesAlternateData = " << withResourcesAlternateData); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetNoteVersionPrepareParams( + ctx->authenticationToken(), + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetNoteVersionReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetResourcePrepareParams( + QString authenticationToken, + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData) +{ + QEC_DEBUG("note_store", "NoteStoreGetResourcePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getResource"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getResource_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withData"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(withData); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withRecognition"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(withRecognition); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withAttributes"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(withAttributes); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withAlternateData"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(withAlternateData); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Resource NoteStoreGetResourceReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Resource result = Resource(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getResource")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Resource v; + readResource(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getResource: missing result")); + } + + return result; +} + +QVariant NoteStoreGetResourceReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetResourceReadReply(reply)); +} + +} // namespace + +Resource NoteStore::getResource( + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getResource: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " withData = " << withData << "\n" + << " withRecognition = " << withRecognition << "\n" + << " withAttributes = " << withAttributes << "\n" + << " withAlternateData = " << withAlternateData); + + QByteArray params = NoteStoreGetResourcePrepareParams( + ctx->authenticationToken(), + guid, + withData, + withRecognition, + withAttributes, + withAlternateData); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetResourceReadReply(reply); +} + +AsyncResult * NoteStore::getResourceAsync( + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getResourceAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " withData = " << withData << "\n" + << " withRecognition = " << withRecognition << "\n" + << " withAttributes = " << withAttributes << "\n" + << " withAlternateData = " << withAlternateData); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetResourcePrepareParams( + ctx->authenticationToken(), + guid, + withData, + withRecognition, + withAttributes, + withAlternateData); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetResourceReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetResourceApplicationDataPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreGetResourceApplicationDataPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getResourceApplicationData"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getResourceApplicationData_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +LazyMap NoteStoreGetResourceApplicationDataReadReply(QByteArray reply) +{ + bool resultIsSet = false; + LazyMap result = LazyMap(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getResourceApplicationData")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + LazyMap v; + readLazyMap(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getResourceApplicationData: missing result")); + } + + return result; +} + +QVariant NoteStoreGetResourceApplicationDataReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetResourceApplicationDataReadReply(reply)); +} + +} // namespace + +LazyMap NoteStore::getResourceApplicationData( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getResourceApplicationData: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreGetResourceApplicationDataPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetResourceApplicationDataReadReply(reply); +} + +AsyncResult * NoteStore::getResourceApplicationDataAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getResourceApplicationDataAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetResourceApplicationDataPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetResourceApplicationDataReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetResourceApplicationDataEntryPrepareParams( + QString authenticationToken, + Guid guid, + QString key) +{ + QEC_DEBUG("note_store", "NoteStoreGetResourceApplicationDataEntryPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getResourceApplicationDataEntry"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getResourceApplicationDataEntry_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("key"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(key); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QString NoteStoreGetResourceApplicationDataEntryReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QString result = QString(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getResourceApplicationDataEntry")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRING) { + resultIsSet = true; + QString v; + reader.readString(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getResourceApplicationDataEntry: missing result")); + } + + return result; +} + +QVariant NoteStoreGetResourceApplicationDataEntryReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetResourceApplicationDataEntryReadReply(reply)); +} + +} // namespace + +QString NoteStore::getResourceApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getResourceApplicationDataEntry: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " key = " << key); + + QByteArray params = NoteStoreGetResourceApplicationDataEntryPrepareParams( + ctx->authenticationToken(), + guid, + key); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetResourceApplicationDataEntryReadReply(reply); +} + +AsyncResult * NoteStore::getResourceApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getResourceApplicationDataEntryAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " key = " << key); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetResourceApplicationDataEntryPrepareParams( + ctx->authenticationToken(), + guid, + key); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetResourceApplicationDataEntryReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreSetResourceApplicationDataEntryPrepareParams( + QString authenticationToken, + Guid guid, + QString key, + QString value) +{ + QEC_DEBUG("note_store", "NoteStoreSetResourceApplicationDataEntryPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("setResourceApplicationDataEntry"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_setResourceApplicationDataEntry_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("key"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(key); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("value"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(value); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreSetResourceApplicationDataEntryReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("setResourceApplicationDataEntry")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("setResourceApplicationDataEntry: missing result")); + } + + return result; +} + +QVariant NoteStoreSetResourceApplicationDataEntryReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreSetResourceApplicationDataEntryReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::setResourceApplicationDataEntry( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::setResourceApplicationDataEntry: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " key = " << key << "\n" + << " value = " << value); + + QByteArray params = NoteStoreSetResourceApplicationDataEntryPrepareParams( + ctx->authenticationToken(), + guid, + key, + value); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreSetResourceApplicationDataEntryReadReply(reply); +} + +AsyncResult * NoteStore::setResourceApplicationDataEntryAsync( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::setResourceApplicationDataEntryAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " key = " << key << "\n" + << " value = " << value); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreSetResourceApplicationDataEntryPrepareParams( + ctx->authenticationToken(), + guid, + key, + value); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreSetResourceApplicationDataEntryReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreUnsetResourceApplicationDataEntryPrepareParams( + QString authenticationToken, + Guid guid, + QString key) +{ + QEC_DEBUG("note_store", "NoteStoreUnsetResourceApplicationDataEntryPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("unsetResourceApplicationDataEntry"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_unsetResourceApplicationDataEntry_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("key"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(key); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreUnsetResourceApplicationDataEntryReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("unsetResourceApplicationDataEntry")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("unsetResourceApplicationDataEntry: missing result")); + } + + return result; +} + +QVariant NoteStoreUnsetResourceApplicationDataEntryReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreUnsetResourceApplicationDataEntryReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::unsetResourceApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::unsetResourceApplicationDataEntry: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " key = " << key); + + QByteArray params = NoteStoreUnsetResourceApplicationDataEntryPrepareParams( + ctx->authenticationToken(), + guid, + key); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreUnsetResourceApplicationDataEntryReadReply(reply); +} + +AsyncResult * NoteStore::unsetResourceApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::unsetResourceApplicationDataEntryAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " key = " << key); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreUnsetResourceApplicationDataEntryPrepareParams( + ctx->authenticationToken(), + guid, + key); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreUnsetResourceApplicationDataEntryReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreUpdateResourcePrepareParams( + QString authenticationToken, + const Resource & resource) +{ + QEC_DEBUG("note_store", "NoteStoreUpdateResourcePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("updateResource"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_updateResource_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("resource"), + ThriftFieldType::T_STRUCT, + 2); + + writeResource(writer, resource); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreUpdateResourceReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("updateResource")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("updateResource: missing result")); + } + + return result; +} + +QVariant NoteStoreUpdateResourceReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreUpdateResourceReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::updateResource( + const Resource & resource, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::updateResource: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " resource = " << resource); + + QByteArray params = NoteStoreUpdateResourcePrepareParams( + ctx->authenticationToken(), + resource); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreUpdateResourceReadReply(reply); +} + +AsyncResult * NoteStore::updateResourceAsync( + const Resource & resource, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::updateResourceAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " resource = " << resource); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreUpdateResourcePrepareParams( + ctx->authenticationToken(), + resource); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreUpdateResourceReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetResourceDataPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreGetResourceDataPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getResourceData"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getResourceData_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QByteArray NoteStoreGetResourceDataReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QByteArray result = QByteArray(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getResourceData")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRING) { + resultIsSet = true; + QByteArray v; + reader.readBinary(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getResourceData: missing result")); + } + + return result; +} + +QVariant NoteStoreGetResourceDataReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetResourceDataReadReply(reply)); +} + +} // namespace + +QByteArray NoteStore::getResourceData( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getResourceData: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreGetResourceDataPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetResourceDataReadReply(reply); +} + +AsyncResult * NoteStore::getResourceDataAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getResourceDataAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetResourceDataPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetResourceDataReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetResourceByHashPrepareParams( + QString authenticationToken, + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData) +{ + QEC_DEBUG("note_store", "NoteStoreGetResourceByHashPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getResourceByHash"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getResourceByHash_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("noteGuid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(noteGuid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("contentHash"), + ThriftFieldType::T_STRING, + 3); + + writer.writeBinary(contentHash); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withData"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(withData); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withRecognition"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(withRecognition); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("withAlternateData"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(withAlternateData); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Resource NoteStoreGetResourceByHashReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Resource result = Resource(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getResourceByHash")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Resource v; + readResource(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getResourceByHash: missing result")); + } + + return result; +} + +QVariant NoteStoreGetResourceByHashReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetResourceByHashReadReply(reply)); +} + +} // namespace + +Resource NoteStore::getResourceByHash( + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getResourceByHash: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " noteGuid = " << noteGuid << "\n" + << " contentHash = " << contentHash << "\n" + << " withData = " << withData << "\n" + << " withRecognition = " << withRecognition << "\n" + << " withAlternateData = " << withAlternateData); + + QByteArray params = NoteStoreGetResourceByHashPrepareParams( + ctx->authenticationToken(), + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetResourceByHashReadReply(reply); +} + +AsyncResult * NoteStore::getResourceByHashAsync( + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getResourceByHashAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " noteGuid = " << noteGuid << "\n" + << " contentHash = " << contentHash << "\n" + << " withData = " << withData << "\n" + << " withRecognition = " << withRecognition << "\n" + << " withAlternateData = " << withAlternateData); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetResourceByHashPrepareParams( + ctx->authenticationToken(), + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetResourceByHashReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetResourceRecognitionPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreGetResourceRecognitionPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getResourceRecognition"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getResourceRecognition_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QByteArray NoteStoreGetResourceRecognitionReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QByteArray result = QByteArray(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getResourceRecognition")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRING) { + resultIsSet = true; + QByteArray v; + reader.readBinary(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getResourceRecognition: missing result")); + } + + return result; +} + +QVariant NoteStoreGetResourceRecognitionReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetResourceRecognitionReadReply(reply)); +} + +} // namespace + +QByteArray NoteStore::getResourceRecognition( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getResourceRecognition: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreGetResourceRecognitionPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetResourceRecognitionReadReply(reply); +} + +AsyncResult * NoteStore::getResourceRecognitionAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getResourceRecognitionAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetResourceRecognitionPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetResourceRecognitionReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetResourceAlternateDataPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreGetResourceAlternateDataPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getResourceAlternateData"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getResourceAlternateData_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QByteArray NoteStoreGetResourceAlternateDataReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QByteArray result = QByteArray(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getResourceAlternateData")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRING) { + resultIsSet = true; + QByteArray v; + reader.readBinary(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getResourceAlternateData: missing result")); + } + + return result; +} + +QVariant NoteStoreGetResourceAlternateDataReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetResourceAlternateDataReadReply(reply)); +} + +} // namespace + +QByteArray NoteStore::getResourceAlternateData( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getResourceAlternateData: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreGetResourceAlternateDataPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetResourceAlternateDataReadReply(reply); +} + +AsyncResult * NoteStore::getResourceAlternateDataAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getResourceAlternateDataAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetResourceAlternateDataPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetResourceAlternateDataReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetResourceAttributesPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreGetResourceAttributesPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getResourceAttributes"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getResourceAttributes_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +ResourceAttributes NoteStoreGetResourceAttributesReadReply(QByteArray reply) +{ + bool resultIsSet = false; + ResourceAttributes result = ResourceAttributes(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getResourceAttributes")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + ResourceAttributes v; + readResourceAttributes(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getResourceAttributes: missing result")); + } + + return result; +} + +QVariant NoteStoreGetResourceAttributesReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetResourceAttributesReadReply(reply)); +} + +} // namespace + +ResourceAttributes NoteStore::getResourceAttributes( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getResourceAttributes: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreGetResourceAttributesPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetResourceAttributesReadReply(reply); +} + +AsyncResult * NoteStore::getResourceAttributesAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getResourceAttributesAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetResourceAttributesPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetResourceAttributesReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetPublicNotebookPrepareParams( + UserID userId, + QString publicUri) +{ + QEC_DEBUG("note_store", "NoteStoreGetPublicNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getPublicNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getPublicNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("userId"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(userId); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("publicUri"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(publicUri); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Notebook NoteStoreGetPublicNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Notebook result = Notebook(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getPublicNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Notebook v; + readNotebook(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getPublicNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreGetPublicNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetPublicNotebookReadReply(reply)); +} + +} // namespace + +Notebook NoteStore::getPublicNotebook( + UserID userId, + QString publicUri, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getPublicNotebook: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " userId = " << userId << "\n" + << " publicUri = " << publicUri); + + QByteArray params = NoteStoreGetPublicNotebookPrepareParams( + userId, + publicUri); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetPublicNotebookReadReply(reply); +} + +AsyncResult * NoteStore::getPublicNotebookAsync( + UserID userId, + QString publicUri, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getPublicNotebookAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " userId = " << userId << "\n" + << " publicUri = " << publicUri); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetPublicNotebookPrepareParams( + userId, + publicUri); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetPublicNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreShareNotebookPrepareParams( + QString authenticationToken, + const SharedNotebook & sharedNotebook, + QString message) +{ + QEC_DEBUG("note_store", "NoteStoreShareNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("shareNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_shareNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("sharedNotebook"), + ThriftFieldType::T_STRUCT, + 2); + + writeSharedNotebook(writer, sharedNotebook); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("message"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(message); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +SharedNotebook NoteStoreShareNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + SharedNotebook result = SharedNotebook(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("shareNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + SharedNotebook v; + readSharedNotebook(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("shareNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreShareNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreShareNotebookReadReply(reply)); +} + +} // namespace + +SharedNotebook NoteStore::shareNotebook( + const SharedNotebook & sharedNotebook, + QString message, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::shareNotebook: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " sharedNotebook = " << sharedNotebook << "\n" + << " message = " << message); + + QByteArray params = NoteStoreShareNotebookPrepareParams( + ctx->authenticationToken(), + sharedNotebook, + message); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreShareNotebookReadReply(reply); +} + +AsyncResult * NoteStore::shareNotebookAsync( + const SharedNotebook & sharedNotebook, + QString message, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::shareNotebookAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " sharedNotebook = " << sharedNotebook << "\n" + << " message = " << message); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreShareNotebookPrepareParams( + ctx->authenticationToken(), + sharedNotebook, + message); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreShareNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreCreateOrUpdateNotebookSharesPrepareParams( + QString authenticationToken, + const NotebookShareTemplate & shareTemplate) +{ + QEC_DEBUG("note_store", "NoteStoreCreateOrUpdateNotebookSharesPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("createOrUpdateNotebookShares"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_createOrUpdateNotebookShares_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("shareTemplate"), + ThriftFieldType::T_STRUCT, + 2); + + writeNotebookShareTemplate(writer, shareTemplate); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +CreateOrUpdateNotebookSharesResult NoteStoreCreateOrUpdateNotebookSharesReadReply(QByteArray reply) +{ + bool resultIsSet = false; + CreateOrUpdateNotebookSharesResult result = CreateOrUpdateNotebookSharesResult(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("createOrUpdateNotebookShares")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + CreateOrUpdateNotebookSharesResult v; + readCreateOrUpdateNotebookSharesResult(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 4) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMInvalidContactsException e; + readEDAMInvalidContactsException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("createOrUpdateNotebookShares: missing result")); + } + + return result; +} + +QVariant NoteStoreCreateOrUpdateNotebookSharesReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreCreateOrUpdateNotebookSharesReadReply(reply)); +} + +} // namespace + +CreateOrUpdateNotebookSharesResult NoteStore::createOrUpdateNotebookShares( + const NotebookShareTemplate & shareTemplate, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::createOrUpdateNotebookShares: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " shareTemplate = " << shareTemplate); + + QByteArray params = NoteStoreCreateOrUpdateNotebookSharesPrepareParams( + ctx->authenticationToken(), + shareTemplate); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreCreateOrUpdateNotebookSharesReadReply(reply); +} + +AsyncResult * NoteStore::createOrUpdateNotebookSharesAsync( + const NotebookShareTemplate & shareTemplate, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::createOrUpdateNotebookSharesAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " shareTemplate = " << shareTemplate); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreCreateOrUpdateNotebookSharesPrepareParams( + ctx->authenticationToken(), + shareTemplate); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreCreateOrUpdateNotebookSharesReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreUpdateSharedNotebookPrepareParams( + QString authenticationToken, + const SharedNotebook & sharedNotebook) +{ + QEC_DEBUG("note_store", "NoteStoreUpdateSharedNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("updateSharedNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_updateSharedNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("sharedNotebook"), + ThriftFieldType::T_STRUCT, + 2); + + writeSharedNotebook(writer, sharedNotebook); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreUpdateSharedNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("updateSharedNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("updateSharedNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreUpdateSharedNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreUpdateSharedNotebookReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::updateSharedNotebook( + const SharedNotebook & sharedNotebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::updateSharedNotebook: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " sharedNotebook = " << sharedNotebook); + + QByteArray params = NoteStoreUpdateSharedNotebookPrepareParams( + ctx->authenticationToken(), + sharedNotebook); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreUpdateSharedNotebookReadReply(reply); +} + +AsyncResult * NoteStore::updateSharedNotebookAsync( + const SharedNotebook & sharedNotebook, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::updateSharedNotebookAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " sharedNotebook = " << sharedNotebook); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreUpdateSharedNotebookPrepareParams( + ctx->authenticationToken(), + sharedNotebook); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreUpdateSharedNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreSetNotebookRecipientSettingsPrepareParams( + QString authenticationToken, + QString notebookGuid, + const NotebookRecipientSettings & recipientSettings) +{ + QEC_DEBUG("note_store", "NoteStoreSetNotebookRecipientSettingsPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("setNotebookRecipientSettings"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_setNotebookRecipientSettings_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("notebookGuid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(notebookGuid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("recipientSettings"), + ThriftFieldType::T_STRUCT, + 3); + + writeNotebookRecipientSettings(writer, recipientSettings); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +Notebook NoteStoreSetNotebookRecipientSettingsReadReply(QByteArray reply) +{ + bool resultIsSet = false; + Notebook result = Notebook(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("setNotebookRecipientSettings")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + Notebook v; + readNotebook(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("setNotebookRecipientSettings: missing result")); + } + + return result; +} + +QVariant NoteStoreSetNotebookRecipientSettingsReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreSetNotebookRecipientSettingsReadReply(reply)); +} + +} // namespace + +Notebook NoteStore::setNotebookRecipientSettings( + QString notebookGuid, + const NotebookRecipientSettings & recipientSettings, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::setNotebookRecipientSettings: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " notebookGuid = " << notebookGuid << "\n" + << " recipientSettings = " << recipientSettings); + + QByteArray params = NoteStoreSetNotebookRecipientSettingsPrepareParams( + ctx->authenticationToken(), + notebookGuid, + recipientSettings); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreSetNotebookRecipientSettingsReadReply(reply); +} + +AsyncResult * NoteStore::setNotebookRecipientSettingsAsync( + QString notebookGuid, + const NotebookRecipientSettings & recipientSettings, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::setNotebookRecipientSettingsAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " notebookGuid = " << notebookGuid << "\n" + << " recipientSettings = " << recipientSettings); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreSetNotebookRecipientSettingsPrepareParams( + ctx->authenticationToken(), + notebookGuid, + recipientSettings); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreSetNotebookRecipientSettingsReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreListSharedNotebooksPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("note_store", "NoteStoreListSharedNotebooksPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("listSharedNotebooks"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_listSharedNotebooks_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QList NoteStoreListSharedNotebooksReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QList result = QList(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("listSharedNotebooks")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_LIST) { + resultIsSet = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (listSharedNotebooks.result)")); + } + for(qint32 i = 0; i < size; i++) { + SharedNotebook elem; + readSharedNotebook(reader, elem); + v.append(elem); + } + reader.readListEnd(); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("listSharedNotebooks: missing result")); + } + + return result; +} + +QVariant NoteStoreListSharedNotebooksReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreListSharedNotebooksReadReply(reply)); +} + +} // namespace + +QList NoteStore::listSharedNotebooks( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::listSharedNotebooks: request id = " + << ctx->requestId()); + + QByteArray params = NoteStoreListSharedNotebooksPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreListSharedNotebooksReadReply(reply); +} + +AsyncResult * NoteStore::listSharedNotebooksAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::listSharedNotebooksAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreListSharedNotebooksPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreListSharedNotebooksReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreCreateLinkedNotebookPrepareParams( + QString authenticationToken, + const LinkedNotebook & linkedNotebook) +{ + QEC_DEBUG("note_store", "NoteStoreCreateLinkedNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("createLinkedNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_createLinkedNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("linkedNotebook"), + ThriftFieldType::T_STRUCT, + 2); + + writeLinkedNotebook(writer, linkedNotebook); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +LinkedNotebook NoteStoreCreateLinkedNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + LinkedNotebook result = LinkedNotebook(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("createLinkedNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + LinkedNotebook v; + readLinkedNotebook(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("createLinkedNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreCreateLinkedNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreCreateLinkedNotebookReadReply(reply)); +} + +} // namespace + +LinkedNotebook NoteStore::createLinkedNotebook( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::createLinkedNotebook: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " linkedNotebook = " << linkedNotebook); + + QByteArray params = NoteStoreCreateLinkedNotebookPrepareParams( + ctx->authenticationToken(), + linkedNotebook); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreCreateLinkedNotebookReadReply(reply); +} + +AsyncResult * NoteStore::createLinkedNotebookAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::createLinkedNotebookAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " linkedNotebook = " << linkedNotebook); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreCreateLinkedNotebookPrepareParams( + ctx->authenticationToken(), + linkedNotebook); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreCreateLinkedNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreUpdateLinkedNotebookPrepareParams( + QString authenticationToken, + const LinkedNotebook & linkedNotebook) +{ + QEC_DEBUG("note_store", "NoteStoreUpdateLinkedNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("updateLinkedNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_updateLinkedNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("linkedNotebook"), + ThriftFieldType::T_STRUCT, + 2); + + writeLinkedNotebook(writer, linkedNotebook); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreUpdateLinkedNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("updateLinkedNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("updateLinkedNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreUpdateLinkedNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreUpdateLinkedNotebookReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::updateLinkedNotebook( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::updateLinkedNotebook: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " linkedNotebook = " << linkedNotebook); + + QByteArray params = NoteStoreUpdateLinkedNotebookPrepareParams( + ctx->authenticationToken(), + linkedNotebook); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreUpdateLinkedNotebookReadReply(reply); +} + +AsyncResult * NoteStore::updateLinkedNotebookAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::updateLinkedNotebookAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " linkedNotebook = " << linkedNotebook); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreUpdateLinkedNotebookPrepareParams( + ctx->authenticationToken(), + linkedNotebook); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreUpdateLinkedNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreListLinkedNotebooksPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("note_store", "NoteStoreListLinkedNotebooksPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("listLinkedNotebooks"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_listLinkedNotebooks_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QList NoteStoreListLinkedNotebooksReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QList result = QList(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("listLinkedNotebooks")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_LIST) { + resultIsSet = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (listLinkedNotebooks.result)")); + } + for(qint32 i = 0; i < size; i++) { + LinkedNotebook elem; + readLinkedNotebook(reader, elem); + v.append(elem); + } + reader.readListEnd(); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("listLinkedNotebooks: missing result")); + } + + return result; +} + +QVariant NoteStoreListLinkedNotebooksReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreListLinkedNotebooksReadReply(reply)); +} + +} // namespace + +QList NoteStore::listLinkedNotebooks( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::listLinkedNotebooks: request id = " + << ctx->requestId()); + + QByteArray params = NoteStoreListLinkedNotebooksPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreListLinkedNotebooksReadReply(reply); +} + +AsyncResult * NoteStore::listLinkedNotebooksAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::listLinkedNotebooksAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreListLinkedNotebooksPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreListLinkedNotebooksReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreExpungeLinkedNotebookPrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreExpungeLinkedNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("expungeLinkedNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_expungeLinkedNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +qint32 NoteStoreExpungeLinkedNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + qint32 result = qint32(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("expungeLinkedNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_I32) { + resultIsSet = true; + qint32 v; + reader.readI32(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("expungeLinkedNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreExpungeLinkedNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreExpungeLinkedNotebookReadReply(reply)); +} + +} // namespace + +qint32 NoteStore::expungeLinkedNotebook( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::expungeLinkedNotebook: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreExpungeLinkedNotebookPrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreExpungeLinkedNotebookReadReply(reply); +} + +AsyncResult * NoteStore::expungeLinkedNotebookAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::expungeLinkedNotebookAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreExpungeLinkedNotebookPrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreExpungeLinkedNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreAuthenticateToSharedNotebookPrepareParams( + QString shareKeyOrGlobalId, + QString authenticationToken) +{ + QEC_DEBUG("note_store", "NoteStoreAuthenticateToSharedNotebookPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("authenticateToSharedNotebook"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_authenticateToSharedNotebook_pargs")); + writer.writeFieldBegin( + QStringLiteral("shareKeyOrGlobalId"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(shareKeyOrGlobalId); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +AuthenticationResult NoteStoreAuthenticateToSharedNotebookReadReply(QByteArray reply) +{ + bool resultIsSet = false; + AuthenticationResult result = AuthenticationResult(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("authenticateToSharedNotebook")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + AuthenticationResult v; + readAuthenticationResult(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("authenticateToSharedNotebook: missing result")); + } + + return result; +} + +QVariant NoteStoreAuthenticateToSharedNotebookReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreAuthenticateToSharedNotebookReadReply(reply)); +} + +} // namespace + +AuthenticationResult NoteStore::authenticateToSharedNotebook( + QString shareKeyOrGlobalId, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::authenticateToSharedNotebook: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " shareKeyOrGlobalId = " << shareKeyOrGlobalId); + + QByteArray params = NoteStoreAuthenticateToSharedNotebookPrepareParams( + shareKeyOrGlobalId, + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreAuthenticateToSharedNotebookReadReply(reply); +} + +AsyncResult * NoteStore::authenticateToSharedNotebookAsync( + QString shareKeyOrGlobalId, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::authenticateToSharedNotebookAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " shareKeyOrGlobalId = " << shareKeyOrGlobalId); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreAuthenticateToSharedNotebookPrepareParams( + shareKeyOrGlobalId, + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreAuthenticateToSharedNotebookReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetSharedNotebookByAuthPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("note_store", "NoteStoreGetSharedNotebookByAuthPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getSharedNotebookByAuth"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getSharedNotebookByAuth_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +SharedNotebook NoteStoreGetSharedNotebookByAuthReadReply(QByteArray reply) +{ + bool resultIsSet = false; + SharedNotebook result = SharedNotebook(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getSharedNotebookByAuth")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + SharedNotebook v; + readSharedNotebook(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getSharedNotebookByAuth: missing result")); + } + + return result; +} + +QVariant NoteStoreGetSharedNotebookByAuthReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetSharedNotebookByAuthReadReply(reply)); +} + +} // namespace + +SharedNotebook NoteStore::getSharedNotebookByAuth( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getSharedNotebookByAuth: request id = " + << ctx->requestId()); + + QByteArray params = NoteStoreGetSharedNotebookByAuthPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetSharedNotebookByAuthReadReply(reply); +} + +AsyncResult * NoteStore::getSharedNotebookByAuthAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getSharedNotebookByAuthAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetSharedNotebookByAuthPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetSharedNotebookByAuthReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreEmailNotePrepareParams( + QString authenticationToken, + const NoteEmailParameters & parameters) +{ + QEC_DEBUG("note_store", "NoteStoreEmailNotePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("emailNote"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_emailNote_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("parameters"), + ThriftFieldType::T_STRUCT, + 2); + + writeNoteEmailParameters(writer, parameters); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +void NoteStoreEmailNoteReadReply(QByteArray reply) +{ + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("emailNote")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + +} + +QVariant NoteStoreEmailNoteReadReplyAsync(QByteArray reply) +{ + NoteStoreEmailNoteReadReply(reply); + return QVariant(); +} + +} // namespace + +void NoteStore::emailNote( + const NoteEmailParameters & parameters, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::emailNote: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " parameters = " << parameters); + + QByteArray params = NoteStoreEmailNotePrepareParams( + ctx->authenticationToken(), + parameters); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + NoteStoreEmailNoteReadReply(reply); +} + +AsyncResult * NoteStore::emailNoteAsync( + const NoteEmailParameters & parameters, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::emailNoteAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " parameters = " << parameters); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreEmailNotePrepareParams( + ctx->authenticationToken(), + parameters); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreEmailNoteReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreShareNotePrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreShareNotePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("shareNote"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_shareNote_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QString NoteStoreShareNoteReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QString result = QString(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("shareNote")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRING) { + resultIsSet = true; + QString v; + reader.readString(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("shareNote: missing result")); + } + + return result; +} + +QVariant NoteStoreShareNoteReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreShareNoteReadReply(reply)); +} + +} // namespace + +QString NoteStore::shareNote( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::shareNote: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreShareNotePrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreShareNoteReadReply(reply); +} + +AsyncResult * NoteStore::shareNoteAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::shareNoteAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreShareNotePrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreShareNoteReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreStopSharingNotePrepareParams( + QString authenticationToken, + Guid guid) +{ + QEC_DEBUG("note_store", "NoteStoreStopSharingNotePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("stopSharingNote"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_stopSharingNote_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +void NoteStoreStopSharingNoteReadReply(QByteArray reply) +{ + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("stopSharingNote")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + +} + +QVariant NoteStoreStopSharingNoteReadReplyAsync(QByteArray reply) +{ + NoteStoreStopSharingNoteReadReply(reply); + return QVariant(); +} + +} // namespace + +void NoteStore::stopSharingNote( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::stopSharingNote: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + QByteArray params = NoteStoreStopSharingNotePrepareParams( + ctx->authenticationToken(), + guid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + NoteStoreStopSharingNoteReadReply(reply); +} + +AsyncResult * NoteStore::stopSharingNoteAsync( + Guid guid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::stopSharingNoteAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreStopSharingNotePrepareParams( + ctx->authenticationToken(), + guid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreStopSharingNoteReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreAuthenticateToSharedNotePrepareParams( + QString guid, + QString noteKey, + QString authenticationToken) +{ + QEC_DEBUG("note_store", "NoteStoreAuthenticateToSharedNotePrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("authenticateToSharedNote"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_authenticateToSharedNote_pargs")); + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(guid); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("noteKey"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(noteKey); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +AuthenticationResult NoteStoreAuthenticateToSharedNoteReadReply(QByteArray reply) +{ + bool resultIsSet = false; + AuthenticationResult result = AuthenticationResult(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("authenticateToSharedNote")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + AuthenticationResult v; + readAuthenticationResult(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("authenticateToSharedNote: missing result")); + } + + return result; +} + +QVariant NoteStoreAuthenticateToSharedNoteReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreAuthenticateToSharedNoteReadReply(reply)); +} + +} // namespace + +AuthenticationResult NoteStore::authenticateToSharedNote( + QString guid, + QString noteKey, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::authenticateToSharedNote: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " noteKey = " << noteKey); + + QByteArray params = NoteStoreAuthenticateToSharedNotePrepareParams( + guid, + noteKey, + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreAuthenticateToSharedNoteReadReply(reply); +} + +AsyncResult * NoteStore::authenticateToSharedNoteAsync( + QString guid, + QString noteKey, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::authenticateToSharedNoteAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " guid = " << guid << "\n" + << " noteKey = " << noteKey); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreAuthenticateToSharedNotePrepareParams( + guid, + noteKey, + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreAuthenticateToSharedNoteReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreFindRelatedPrepareParams( + QString authenticationToken, + const RelatedQuery & query, + const RelatedResultSpec & resultSpec) +{ + QEC_DEBUG("note_store", "NoteStoreFindRelatedPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("findRelated"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_findRelated_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("query"), + ThriftFieldType::T_STRUCT, + 2); + + writeRelatedQuery(writer, query); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("resultSpec"), + ThriftFieldType::T_STRUCT, + 3); + + writeRelatedResultSpec(writer, resultSpec); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +RelatedResult NoteStoreFindRelatedReadReply(QByteArray reply) +{ + bool resultIsSet = false; + RelatedResult result = RelatedResult(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("findRelated")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + RelatedResult v; + readRelatedResult(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("findRelated: missing result")); + } + + return result; +} + +QVariant NoteStoreFindRelatedReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreFindRelatedReadReply(reply)); +} + +} // namespace + +RelatedResult NoteStore::findRelated( + const RelatedQuery & query, + const RelatedResultSpec & resultSpec, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::findRelated: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " query = " << query << "\n" + << " resultSpec = " << resultSpec); + + QByteArray params = NoteStoreFindRelatedPrepareParams( + ctx->authenticationToken(), + query, + resultSpec); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreFindRelatedReadReply(reply); +} + +AsyncResult * NoteStore::findRelatedAsync( + const RelatedQuery & query, + const RelatedResultSpec & resultSpec, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::findRelatedAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " query = " << query << "\n" + << " resultSpec = " << resultSpec); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreFindRelatedPrepareParams( + ctx->authenticationToken(), + query, + resultSpec); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreFindRelatedReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreUpdateNoteIfUsnMatchesPrepareParams( + QString authenticationToken, + const Note & note) +{ + QEC_DEBUG("note_store", "NoteStoreUpdateNoteIfUsnMatchesPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("updateNoteIfUsnMatches"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_updateNoteIfUsnMatches_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("note"), + ThriftFieldType::T_STRUCT, + 2); + + writeNote(writer, note); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +UpdateNoteIfUsnMatchesResult NoteStoreUpdateNoteIfUsnMatchesReadReply(QByteArray reply) +{ + bool resultIsSet = false; + UpdateNoteIfUsnMatchesResult result = UpdateNoteIfUsnMatchesResult(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("updateNoteIfUsnMatches")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + UpdateNoteIfUsnMatchesResult v; + readUpdateNoteIfUsnMatchesResult(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("updateNoteIfUsnMatches: missing result")); + } + + return result; +} + +QVariant NoteStoreUpdateNoteIfUsnMatchesReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreUpdateNoteIfUsnMatchesReadReply(reply)); +} + +} // namespace + +UpdateNoteIfUsnMatchesResult NoteStore::updateNoteIfUsnMatches( + const Note & note, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::updateNoteIfUsnMatches: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " note = " << note); + + QByteArray params = NoteStoreUpdateNoteIfUsnMatchesPrepareParams( + ctx->authenticationToken(), + note); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreUpdateNoteIfUsnMatchesReadReply(reply); +} + +AsyncResult * NoteStore::updateNoteIfUsnMatchesAsync( + const Note & note, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::updateNoteIfUsnMatchesAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " note = " << note); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreUpdateNoteIfUsnMatchesPrepareParams( + ctx->authenticationToken(), + note); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreUpdateNoteIfUsnMatchesReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreManageNotebookSharesPrepareParams( + QString authenticationToken, + const ManageNotebookSharesParameters & parameters) +{ + QEC_DEBUG("note_store", "NoteStoreManageNotebookSharesPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("manageNotebookShares"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_manageNotebookShares_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("parameters"), + ThriftFieldType::T_STRUCT, + 2); + + writeManageNotebookSharesParameters(writer, parameters); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +ManageNotebookSharesResult NoteStoreManageNotebookSharesReadReply(QByteArray reply) +{ + bool resultIsSet = false; + ManageNotebookSharesResult result = ManageNotebookSharesResult(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("manageNotebookShares")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + ManageNotebookSharesResult v; + readManageNotebookSharesResult(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("manageNotebookShares: missing result")); + } + + return result; +} + +QVariant NoteStoreManageNotebookSharesReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreManageNotebookSharesReadReply(reply)); +} + +} // namespace + +ManageNotebookSharesResult NoteStore::manageNotebookShares( + const ManageNotebookSharesParameters & parameters, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::manageNotebookShares: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " parameters = " << parameters); + + QByteArray params = NoteStoreManageNotebookSharesPrepareParams( + ctx->authenticationToken(), + parameters); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreManageNotebookSharesReadReply(reply); +} + +AsyncResult * NoteStore::manageNotebookSharesAsync( + const ManageNotebookSharesParameters & parameters, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::manageNotebookSharesAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " parameters = " << parameters); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreManageNotebookSharesPrepareParams( + ctx->authenticationToken(), + parameters); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreManageNotebookSharesReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray NoteStoreGetNotebookSharesPrepareParams( + QString authenticationToken, + QString notebookGuid) +{ + QEC_DEBUG("note_store", "NoteStoreGetNotebookSharesPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getNotebookShares"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("NoteStore_getNotebookShares_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("notebookGuid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(notebookGuid); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +ShareRelationships NoteStoreGetNotebookSharesReadReply(QByteArray reply) +{ + bool resultIsSet = false; + ShareRelationships result = ShareRelationships(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getNotebookShares")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + ShareRelationships v; + readShareRelationships(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getNotebookShares: missing result")); + } + + return result; +} + +QVariant NoteStoreGetNotebookSharesReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(NoteStoreGetNotebookSharesReadReply(reply)); +} + +} // namespace + +ShareRelationships NoteStore::getNotebookShares( + QString notebookGuid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("note_store", "NoteStore::getNotebookShares: request id = " + << ctx->requestId()); + QEC_TRACE("note_store", "Parameters:\n" + << " notebookGuid = " << notebookGuid); + + QByteArray params = NoteStoreGetNotebookSharesPrepareParams( + ctx->authenticationToken(), + notebookGuid); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("note_store", "received reply for request with id = " + << ctx->requestId()); + return NoteStoreGetNotebookSharesReadReply(reply); +} + +AsyncResult * NoteStore::getNotebookSharesAsync( + QString notebookGuid, + IRequestContextPtr ctx) +{ + QEC_DEBUG("note_store", "NoteStore::getNotebookSharesAsync"); + QEC_TRACE("note_store", "Parameters:\n" + << " notebookGuid = " << notebookGuid); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = NoteStoreGetNotebookSharesPrepareParams( + ctx->authenticationToken(), + notebookGuid); + + return new AsyncResult( + m_url, + params, + ctx, + NoteStoreGetNotebookSharesReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +class Q_DECL_HIDDEN UserStore: public IUserStore +{ + Q_OBJECT + Q_DISABLE_COPY(UserStore) +public: + explicit UserStore( + QString userStoreUrl = {}, + IRequestContextPtr ctx = {}, + QObject * parent = nullptr) : + IUserStore(parent), + m_url(std::move(userStoreUrl)), + m_ctx(std::move(ctx)) + { + if (!m_ctx) { + m_ctx = newRequestContext(); + } + } + + explicit UserStore(QObject * parent) : + IUserStore(parent) + { + m_ctx = newRequestContext(); + } + + virtual void setUserStoreUrl(QString userStoreUrl) override + { + m_url = std::move(userStoreUrl); + } + + virtual QString userStoreUrl() const override + { + return m_url; + } + + virtual bool checkVersion( + QString clientName, + qint16 edamVersionMajor = EDAM_VERSION_MAJOR, + qint16 edamVersionMinor = EDAM_VERSION_MINOR, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * checkVersionAsync( + QString clientName, + qint16 edamVersionMajor = EDAM_VERSION_MAJOR, + qint16 edamVersionMinor = EDAM_VERSION_MINOR, + IRequestContextPtr ctx = {}) override; + + virtual BootstrapInfo getBootstrapInfo( + QString locale, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getBootstrapInfoAsync( + QString locale, + IRequestContextPtr ctx = {}) override; + + virtual AuthenticationResult authenticateLongSession( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * authenticateLongSessionAsync( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor, + IRequestContextPtr ctx = {}) override; + + virtual AuthenticationResult completeTwoFactorAuthentication( + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * completeTwoFactorAuthenticationAsync( + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription, + IRequestContextPtr ctx = {}) override; + + virtual void revokeLongSession( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * revokeLongSessionAsync( + IRequestContextPtr ctx = {}) override; + + virtual AuthenticationResult authenticateToBusiness( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * authenticateToBusinessAsync( + IRequestContextPtr ctx = {}) override; + + virtual User getUser( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getUserAsync( + IRequestContextPtr ctx = {}) override; + + virtual PublicUserInfo getPublicUserInfo( + QString username, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getPublicUserInfoAsync( + QString username, + IRequestContextPtr ctx = {}) override; + + virtual UserUrls getUserUrls( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getUserUrlsAsync( + IRequestContextPtr ctx = {}) override; + + virtual void inviteToBusiness( + QString emailAddress, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * inviteToBusinessAsync( + QString emailAddress, + IRequestContextPtr ctx = {}) override; + + virtual void removeFromBusiness( + QString emailAddress, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * removeFromBusinessAsync( + QString emailAddress, + IRequestContextPtr ctx = {}) override; + + virtual void updateBusinessUserIdentifier( + QString oldEmailAddress, + QString newEmailAddress, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateBusinessUserIdentifierAsync( + QString oldEmailAddress, + QString newEmailAddress, + IRequestContextPtr ctx = {}) override; + + virtual QList listBusinessUsers( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listBusinessUsersAsync( + IRequestContextPtr ctx = {}) override; + + virtual QList listBusinessInvitations( + bool includeRequestedInvitations, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listBusinessInvitationsAsync( + bool includeRequestedInvitations, + IRequestContextPtr ctx = {}) override; + + virtual AccountLimits getAccountLimits( + ServiceLevel serviceLevel, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getAccountLimitsAsync( + ServiceLevel serviceLevel, + IRequestContextPtr ctx = {}) override; + +private: + QString m_url; + IRequestContextPtr m_ctx; +}; + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreCheckVersionPrepareParams( + QString clientName, + qint16 edamVersionMajor, + qint16 edamVersionMinor) +{ + QEC_DEBUG("user_store", "UserStoreCheckVersionPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("checkVersion"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_checkVersion_pargs")); + writer.writeFieldBegin( + QStringLiteral("clientName"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(clientName); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("edamVersionMajor"), + ThriftFieldType::T_I16, + 2); + + writer.writeI16(edamVersionMajor); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("edamVersionMinor"), + ThriftFieldType::T_I16, + 3); + + writer.writeI16(edamVersionMinor); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +bool UserStoreCheckVersionReadReply(QByteArray reply) +{ + bool resultIsSet = false; + bool result = bool(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("checkVersion")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_BOOL) { + resultIsSet = true; + bool v; + reader.readBool(v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("checkVersion: missing result")); + } + + return result; +} + +QVariant UserStoreCheckVersionReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(UserStoreCheckVersionReadReply(reply)); +} + +} // namespace + +bool UserStore::checkVersion( + QString clientName, + qint16 edamVersionMajor, + qint16 edamVersionMinor, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::checkVersion: request id = " + << ctx->requestId()); + QEC_TRACE("user_store", "Parameters:\n" + << " clientName = " << clientName << "\n" + << " edamVersionMajor = " << edamVersionMajor << "\n" + << " edamVersionMinor = " << edamVersionMinor); + + QByteArray params = UserStoreCheckVersionPrepareParams( + clientName, + edamVersionMajor, + edamVersionMinor); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + return UserStoreCheckVersionReadReply(reply); +} + +AsyncResult * UserStore::checkVersionAsync( + QString clientName, + qint16 edamVersionMajor, + qint16 edamVersionMinor, + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::checkVersionAsync"); + QEC_TRACE("user_store", "Parameters:\n" + << " clientName = " << clientName << "\n" + << " edamVersionMajor = " << edamVersionMajor << "\n" + << " edamVersionMinor = " << edamVersionMinor); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreCheckVersionPrepareParams( + clientName, + edamVersionMajor, + edamVersionMinor); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreCheckVersionReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreGetBootstrapInfoPrepareParams( + QString locale) +{ + QEC_DEBUG("user_store", "UserStoreGetBootstrapInfoPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getBootstrapInfo"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_getBootstrapInfo_pargs")); + writer.writeFieldBegin( + QStringLiteral("locale"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(locale); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +BootstrapInfo UserStoreGetBootstrapInfoReadReply(QByteArray reply) +{ + bool resultIsSet = false; + BootstrapInfo result = BootstrapInfo(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getBootstrapInfo")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + BootstrapInfo v; + readBootstrapInfo(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getBootstrapInfo: missing result")); + } + + return result; +} + +QVariant UserStoreGetBootstrapInfoReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(UserStoreGetBootstrapInfoReadReply(reply)); +} + +} // namespace + +BootstrapInfo UserStore::getBootstrapInfo( + QString locale, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::getBootstrapInfo: request id = " + << ctx->requestId()); + QEC_TRACE("user_store", "Parameters:\n" + << " locale = " << locale); + + QByteArray params = UserStoreGetBootstrapInfoPrepareParams( + locale); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + return UserStoreGetBootstrapInfoReadReply(reply); +} + +AsyncResult * UserStore::getBootstrapInfoAsync( + QString locale, + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::getBootstrapInfoAsync"); + QEC_TRACE("user_store", "Parameters:\n" + << " locale = " << locale); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreGetBootstrapInfoPrepareParams( + locale); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreGetBootstrapInfoReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreAuthenticateLongSessionPrepareParams( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor) +{ + QEC_DEBUG("user_store", "UserStoreAuthenticateLongSessionPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("authenticateLongSession"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_authenticateLongSession_pargs")); + writer.writeFieldBegin( + QStringLiteral("username"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(username); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("password"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(password); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("consumerKey"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(consumerKey); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("consumerSecret"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(consumerSecret); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("deviceIdentifier"), + ThriftFieldType::T_STRING, + 5); + + writer.writeString(deviceIdentifier); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("deviceDescription"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(deviceDescription); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("supportsTwoFactor"), + ThriftFieldType::T_BOOL, + 7); + + writer.writeBool(supportsTwoFactor); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +AuthenticationResult UserStoreAuthenticateLongSessionReadReply(QByteArray reply) +{ + bool resultIsSet = false; + AuthenticationResult result = AuthenticationResult(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("authenticateLongSession")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + AuthenticationResult v; + readAuthenticationResult(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("authenticateLongSession: missing result")); + } + + return result; +} + +QVariant UserStoreAuthenticateLongSessionReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(UserStoreAuthenticateLongSessionReadReply(reply)); +} + +} // namespace + +AuthenticationResult UserStore::authenticateLongSession( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::authenticateLongSession: request id = " + << ctx->requestId()); + QEC_TRACE("user_store", "Parameters:\n" + << " username = " << username << "\n" + << " deviceIdentifier = " << deviceIdentifier << "\n" + << " deviceDescription = " << deviceDescription << "\n" + << " supportsTwoFactor = " << supportsTwoFactor); + + QByteArray params = UserStoreAuthenticateLongSessionPrepareParams( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + return UserStoreAuthenticateLongSessionReadReply(reply); +} + +AsyncResult * UserStore::authenticateLongSessionAsync( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor, + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::authenticateLongSessionAsync"); + QEC_TRACE("user_store", "Parameters:\n" + << " username = " << username << "\n" + << " deviceIdentifier = " << deviceIdentifier << "\n" + << " deviceDescription = " << deviceDescription << "\n" + << " supportsTwoFactor = " << supportsTwoFactor); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreAuthenticateLongSessionPrepareParams( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreAuthenticateLongSessionReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreCompleteTwoFactorAuthenticationPrepareParams( + QString authenticationToken, + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription) +{ + QEC_DEBUG("user_store", "UserStoreCompleteTwoFactorAuthenticationPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("completeTwoFactorAuthentication"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_completeTwoFactorAuthentication_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("oneTimeCode"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(oneTimeCode); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("deviceIdentifier"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(deviceIdentifier); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("deviceDescription"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(deviceDescription); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +AuthenticationResult UserStoreCompleteTwoFactorAuthenticationReadReply(QByteArray reply) +{ + bool resultIsSet = false; + AuthenticationResult result = AuthenticationResult(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("completeTwoFactorAuthentication")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + AuthenticationResult v; + readAuthenticationResult(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("completeTwoFactorAuthentication: missing result")); + } + + return result; +} + +QVariant UserStoreCompleteTwoFactorAuthenticationReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(UserStoreCompleteTwoFactorAuthenticationReadReply(reply)); +} + +} // namespace + +AuthenticationResult UserStore::completeTwoFactorAuthentication( + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::completeTwoFactorAuthentication: request id = " + << ctx->requestId()); + QEC_TRACE("user_store", "Parameters:\n" + << " deviceIdentifier = " << deviceIdentifier << "\n" + << " deviceDescription = " << deviceDescription); + + QByteArray params = UserStoreCompleteTwoFactorAuthenticationPrepareParams( + ctx->authenticationToken(), + oneTimeCode, + deviceIdentifier, + deviceDescription); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + return UserStoreCompleteTwoFactorAuthenticationReadReply(reply); +} + +AsyncResult * UserStore::completeTwoFactorAuthenticationAsync( + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription, + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::completeTwoFactorAuthenticationAsync"); + QEC_TRACE("user_store", "Parameters:\n" + << " deviceIdentifier = " << deviceIdentifier << "\n" + << " deviceDescription = " << deviceDescription); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreCompleteTwoFactorAuthenticationPrepareParams( + ctx->authenticationToken(), + oneTimeCode, + deviceIdentifier, + deviceDescription); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreCompleteTwoFactorAuthenticationReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreRevokeLongSessionPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("user_store", "UserStoreRevokeLongSessionPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("revokeLongSession"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_revokeLongSession_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +void UserStoreRevokeLongSessionReadReply(QByteArray reply) +{ + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("revokeLongSession")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + +} + +QVariant UserStoreRevokeLongSessionReadReplyAsync(QByteArray reply) +{ + UserStoreRevokeLongSessionReadReply(reply); + return QVariant(); +} + +} // namespace + +void UserStore::revokeLongSession( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::revokeLongSession: request id = " + << ctx->requestId()); + + QByteArray params = UserStoreRevokeLongSessionPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + UserStoreRevokeLongSessionReadReply(reply); +} + +AsyncResult * UserStore::revokeLongSessionAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::revokeLongSessionAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreRevokeLongSessionPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreRevokeLongSessionReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreAuthenticateToBusinessPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("user_store", "UserStoreAuthenticateToBusinessPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("authenticateToBusiness"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_authenticateToBusiness_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +AuthenticationResult UserStoreAuthenticateToBusinessReadReply(QByteArray reply) +{ + bool resultIsSet = false; + AuthenticationResult result = AuthenticationResult(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("authenticateToBusiness")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + AuthenticationResult v; + readAuthenticationResult(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("authenticateToBusiness: missing result")); + } + + return result; +} + +QVariant UserStoreAuthenticateToBusinessReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(UserStoreAuthenticateToBusinessReadReply(reply)); +} + +} // namespace + +AuthenticationResult UserStore::authenticateToBusiness( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::authenticateToBusiness: request id = " + << ctx->requestId()); + + QByteArray params = UserStoreAuthenticateToBusinessPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + return UserStoreAuthenticateToBusinessReadReply(reply); +} + +AsyncResult * UserStore::authenticateToBusinessAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::authenticateToBusinessAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreAuthenticateToBusinessPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreAuthenticateToBusinessReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreGetUserPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("user_store", "UserStoreGetUserPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getUser"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_getUser_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +User UserStoreGetUserReadReply(QByteArray reply) +{ + bool resultIsSet = false; + User result = User(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getUser")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + User v; + readUser(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getUser: missing result")); + } + + return result; +} + +QVariant UserStoreGetUserReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(UserStoreGetUserReadReply(reply)); +} + +} // namespace + +User UserStore::getUser( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::getUser: request id = " + << ctx->requestId()); + + QByteArray params = UserStoreGetUserPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + return UserStoreGetUserReadReply(reply); +} + +AsyncResult * UserStore::getUserAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::getUserAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreGetUserPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreGetUserReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreGetPublicUserInfoPrepareParams( + QString username) +{ + QEC_DEBUG("user_store", "UserStoreGetPublicUserInfoPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getPublicUserInfo"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_getPublicUserInfo_pargs")); + writer.writeFieldBegin( + QStringLiteral("username"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(username); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +PublicUserInfo UserStoreGetPublicUserInfoReadReply(QByteArray reply) +{ + bool resultIsSet = false; + PublicUserInfo result = PublicUserInfo(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getPublicUserInfo")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + PublicUserInfo v; + readPublicUserInfo(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getPublicUserInfo: missing result")); + } + + return result; +} + +QVariant UserStoreGetPublicUserInfoReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(UserStoreGetPublicUserInfoReadReply(reply)); +} + +} // namespace + +PublicUserInfo UserStore::getPublicUserInfo( + QString username, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::getPublicUserInfo: request id = " + << ctx->requestId()); + QEC_TRACE("user_store", "Parameters:\n" + << " username = " << username); + + QByteArray params = UserStoreGetPublicUserInfoPrepareParams( + username); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + return UserStoreGetPublicUserInfoReadReply(reply); +} + +AsyncResult * UserStore::getPublicUserInfoAsync( + QString username, + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::getPublicUserInfoAsync"); + QEC_TRACE("user_store", "Parameters:\n" + << " username = " << username); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreGetPublicUserInfoPrepareParams( + username); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreGetPublicUserInfoReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreGetUserUrlsPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("user_store", "UserStoreGetUserUrlsPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getUserUrls"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_getUserUrls_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +UserUrls UserStoreGetUserUrlsReadReply(QByteArray reply) +{ + bool resultIsSet = false; + UserUrls result = UserUrls(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getUserUrls")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + UserUrls v; + readUserUrls(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getUserUrls: missing result")); + } + + return result; +} + +QVariant UserStoreGetUserUrlsReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(UserStoreGetUserUrlsReadReply(reply)); +} + +} // namespace + +UserUrls UserStore::getUserUrls( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::getUserUrls: request id = " + << ctx->requestId()); + + QByteArray params = UserStoreGetUserUrlsPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + return UserStoreGetUserUrlsReadReply(reply); +} + +AsyncResult * UserStore::getUserUrlsAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::getUserUrlsAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreGetUserUrlsPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreGetUserUrlsReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreInviteToBusinessPrepareParams( + QString authenticationToken, + QString emailAddress) +{ + QEC_DEBUG("user_store", "UserStoreInviteToBusinessPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("inviteToBusiness"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_inviteToBusiness_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("emailAddress"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(emailAddress); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +void UserStoreInviteToBusinessReadReply(QByteArray reply) +{ + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("inviteToBusiness")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + +} + +QVariant UserStoreInviteToBusinessReadReplyAsync(QByteArray reply) +{ + UserStoreInviteToBusinessReadReply(reply); + return QVariant(); +} + +} // namespace + +void UserStore::inviteToBusiness( + QString emailAddress, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::inviteToBusiness: request id = " + << ctx->requestId()); + QEC_TRACE("user_store", "Parameters:\n" + << " emailAddress = " << emailAddress); + + QByteArray params = UserStoreInviteToBusinessPrepareParams( + ctx->authenticationToken(), + emailAddress); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + UserStoreInviteToBusinessReadReply(reply); +} + +AsyncResult * UserStore::inviteToBusinessAsync( + QString emailAddress, + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::inviteToBusinessAsync"); + QEC_TRACE("user_store", "Parameters:\n" + << " emailAddress = " << emailAddress); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreInviteToBusinessPrepareParams( + ctx->authenticationToken(), + emailAddress); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreInviteToBusinessReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreRemoveFromBusinessPrepareParams( + QString authenticationToken, + QString emailAddress) +{ + QEC_DEBUG("user_store", "UserStoreRemoveFromBusinessPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("removeFromBusiness"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_removeFromBusiness_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("emailAddress"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(emailAddress); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +void UserStoreRemoveFromBusinessReadReply(QByteArray reply) +{ + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("removeFromBusiness")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + +} + +QVariant UserStoreRemoveFromBusinessReadReplyAsync(QByteArray reply) +{ + UserStoreRemoveFromBusinessReadReply(reply); + return QVariant(); +} + +} // namespace + +void UserStore::removeFromBusiness( + QString emailAddress, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::removeFromBusiness: request id = " + << ctx->requestId()); + QEC_TRACE("user_store", "Parameters:\n" + << " emailAddress = " << emailAddress); + + QByteArray params = UserStoreRemoveFromBusinessPrepareParams( + ctx->authenticationToken(), + emailAddress); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + UserStoreRemoveFromBusinessReadReply(reply); +} + +AsyncResult * UserStore::removeFromBusinessAsync( + QString emailAddress, + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::removeFromBusinessAsync"); + QEC_TRACE("user_store", "Parameters:\n" + << " emailAddress = " << emailAddress); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreRemoveFromBusinessPrepareParams( + ctx->authenticationToken(), + emailAddress); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreRemoveFromBusinessReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreUpdateBusinessUserIdentifierPrepareParams( + QString authenticationToken, + QString oldEmailAddress, + QString newEmailAddress) +{ + QEC_DEBUG("user_store", "UserStoreUpdateBusinessUserIdentifierPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("updateBusinessUserIdentifier"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_updateBusinessUserIdentifier_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("oldEmailAddress"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(oldEmailAddress); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("newEmailAddress"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(newEmailAddress); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +void UserStoreUpdateBusinessUserIdentifierReadReply(QByteArray reply) +{ + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("updateBusinessUserIdentifier")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 3) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException e; + readEDAMNotFoundException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + +} + +QVariant UserStoreUpdateBusinessUserIdentifierReadReplyAsync(QByteArray reply) +{ + UserStoreUpdateBusinessUserIdentifierReadReply(reply); + return QVariant(); +} + +} // namespace + +void UserStore::updateBusinessUserIdentifier( + QString oldEmailAddress, + QString newEmailAddress, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::updateBusinessUserIdentifier: request id = " + << ctx->requestId()); + QEC_TRACE("user_store", "Parameters:\n" + << " oldEmailAddress = " << oldEmailAddress << "\n" + << " newEmailAddress = " << newEmailAddress); + + QByteArray params = UserStoreUpdateBusinessUserIdentifierPrepareParams( + ctx->authenticationToken(), + oldEmailAddress, + newEmailAddress); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + UserStoreUpdateBusinessUserIdentifierReadReply(reply); +} + +AsyncResult * UserStore::updateBusinessUserIdentifierAsync( + QString oldEmailAddress, + QString newEmailAddress, + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::updateBusinessUserIdentifierAsync"); + QEC_TRACE("user_store", "Parameters:\n" + << " oldEmailAddress = " << oldEmailAddress << "\n" + << " newEmailAddress = " << newEmailAddress); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreUpdateBusinessUserIdentifierPrepareParams( + ctx->authenticationToken(), + oldEmailAddress, + newEmailAddress); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreUpdateBusinessUserIdentifierReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreListBusinessUsersPrepareParams( + QString authenticationToken) +{ + QEC_DEBUG("user_store", "UserStoreListBusinessUsersPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("listBusinessUsers"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_listBusinessUsers_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QList UserStoreListBusinessUsersReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QList result = QList(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("listBusinessUsers")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_LIST) { + resultIsSet = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (listBusinessUsers.result)")); + } + for(qint32 i = 0; i < size; i++) { + UserProfile elem; + readUserProfile(reader, elem); + v.append(elem); + } + reader.readListEnd(); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("listBusinessUsers: missing result")); + } + + return result; +} + +QVariant UserStoreListBusinessUsersReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(UserStoreListBusinessUsersReadReply(reply)); +} + +} // namespace + +QList UserStore::listBusinessUsers( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::listBusinessUsers: request id = " + << ctx->requestId()); + + QByteArray params = UserStoreListBusinessUsersPrepareParams( + ctx->authenticationToken()); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + return UserStoreListBusinessUsersReadReply(reply); +} + +AsyncResult * UserStore::listBusinessUsersAsync( + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::listBusinessUsersAsync"); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreListBusinessUsersPrepareParams( + ctx->authenticationToken()); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreListBusinessUsersReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreListBusinessInvitationsPrepareParams( + QString authenticationToken, + bool includeRequestedInvitations) +{ + QEC_DEBUG("user_store", "UserStoreListBusinessInvitationsPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("listBusinessInvitations"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_listBusinessInvitations_pargs")); + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("includeRequestedInvitations"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(includeRequestedInvitations); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +QList UserStoreListBusinessInvitationsReadReply(QByteArray reply) +{ + bool resultIsSet = false; + QList result = QList(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("listBusinessInvitations")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_LIST) { + resultIsSet = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (listBusinessInvitations.result)")); + } + for(qint32 i = 0; i < size; i++) { + BusinessInvitation elem; + readBusinessInvitation(reader, elem); + v.append(elem); + } + reader.readListEnd(); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 2) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMSystemException e; + readEDAMSystemException(reader, e); + throwEDAMSystemException(e); + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("listBusinessInvitations: missing result")); + } + + return result; +} + +QVariant UserStoreListBusinessInvitationsReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(UserStoreListBusinessInvitationsReadReply(reply)); +} + +} // namespace + +QList UserStore::listBusinessInvitations( + bool includeRequestedInvitations, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::listBusinessInvitations: request id = " + << ctx->requestId()); + QEC_TRACE("user_store", "Parameters:\n" + << " includeRequestedInvitations = " << includeRequestedInvitations); + + QByteArray params = UserStoreListBusinessInvitationsPrepareParams( + ctx->authenticationToken(), + includeRequestedInvitations); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + return UserStoreListBusinessInvitationsReadReply(reply); +} + +AsyncResult * UserStore::listBusinessInvitationsAsync( + bool includeRequestedInvitations, + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::listBusinessInvitationsAsync"); + QEC_TRACE("user_store", "Parameters:\n" + << " includeRequestedInvitations = " << includeRequestedInvitations); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreListBusinessInvitationsPrepareParams( + ctx->authenticationToken(), + includeRequestedInvitations); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreListBusinessInvitationsReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +namespace { + +QByteArray UserStoreGetAccountLimitsPrepareParams( + ServiceLevel serviceLevel) +{ + QEC_DEBUG("user_store", "UserStoreGetAccountLimitsPrepareParams"); + + ThriftBinaryBufferWriter writer; + qint32 cseqid = 0; + + writer.writeMessageBegin( + QStringLiteral("getAccountLimits"), + ThriftMessageType::T_CALL, + cseqid); + + writer.writeStructBegin( + QStringLiteral("UserStore_getAccountLimits_pargs")); + writer.writeFieldBegin( + QStringLiteral("serviceLevel"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(static_cast(serviceLevel)); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); + writer.writeMessageEnd(); + return writer.buffer(); +} + +AccountLimits UserStoreGetAccountLimitsReadReply(QByteArray reply) +{ + bool resultIsSet = false; + AccountLimits result = AccountLimits(); + ThriftBinaryBufferReader reader(reply); + qint32 rseqid = 0; + QString fname; + ThriftMessageType mtype; + reader.readMessageBegin(fname, mtype, rseqid); + if (mtype == ThriftMessageType::T_EXCEPTION) { + ThriftException e = readThriftException(reader); + reader.readMessageEnd(); + throw e; + } + if (mtype != ThriftMessageType::T_REPLY) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); + } + if (fname.compare(QStringLiteral("getAccountLimits")) != 0) { + reader.skip(ThriftFieldType::T_STRUCT); + reader.readMessageEnd(); + throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); + } + + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) { + break; + } + + if (fieldId == 0) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + resultIsSet = true; + AccountLimits v; + readAccountLimits(reader, v); + result = v; + } + else { + reader.skip(fieldType); + } + } + else if (fieldId == 1) + { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException e; + readEDAMUserException(reader, e); + throw e; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + + reader.readFieldEnd(); + } + + reader.readStructEnd(); + reader.readMessageEnd(); + + if (!resultIsSet) { + throw ThriftException( + ThriftException::Type::MISSING_RESULT, + QStringLiteral("getAccountLimits: missing result")); + } + + return result; +} + +QVariant UserStoreGetAccountLimitsReadReplyAsync(QByteArray reply) +{ + return QVariant::fromValue(UserStoreGetAccountLimitsReadReply(reply)); +} + +} // namespace + +AccountLimits UserStore::getAccountLimits( + ServiceLevel serviceLevel, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QEC_DEBUG("user_store", "UserStore::getAccountLimits: request id = " + << ctx->requestId()); + QEC_TRACE("user_store", "Parameters:\n" + << " serviceLevel = " << serviceLevel); + + QByteArray params = UserStoreGetAccountLimitsPrepareParams( + serviceLevel); + + QByteArray reply = askEvernote( + m_url, + params, + ctx->requestTimeout(), + ctx->cookies()); + + QEC_DEBUG("user_store", "received reply for request with id = " + << ctx->requestId()); + return UserStoreGetAccountLimitsReadReply(reply); +} + +AsyncResult * UserStore::getAccountLimitsAsync( + ServiceLevel serviceLevel, + IRequestContextPtr ctx) +{ + QEC_DEBUG("user_store", "UserStore::getAccountLimitsAsync"); + QEC_TRACE("user_store", "Parameters:\n" + << " serviceLevel = " << serviceLevel); + + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + QByteArray params = UserStoreGetAccountLimitsPrepareParams( + serviceLevel); + + return new AsyncResult( + m_url, + params, + ctx, + UserStoreGetAccountLimitsReadReplyAsync); +} + +//////////////////////////////////////////////////////////////////////////////// + +class Q_DECL_HIDDEN DurableNoteStore: public INoteStore +{ + Q_OBJECT + Q_DISABLE_COPY(DurableNoteStore) +public: + explicit DurableNoteStore( + INoteStorePtr service, + IRequestContextPtr ctx = {}, + IRetryPolicyPtr retryPolicy = newRetryPolicy(), + QObject * parent = nullptr) : + INoteStore(parent), + m_service(std::move(service)), + m_durableService(newDurableService(retryPolicy, ctx)), + m_ctx(std::move(ctx)) + { + if (!m_ctx) { + m_ctx = newRequestContext(); + } + + m_service->setParent(this); + } + + ~DurableNoteStore() + { + // Don't interfere with std::shared_ptr's lifetime tracking + m_service->setParent(nullptr); + } + + virtual void setNoteStoreUrl(QString noteStoreUrl) override + { + m_service->setNoteStoreUrl(noteStoreUrl); + } + + virtual QString noteStoreUrl() const override + { + return m_service->noteStoreUrl(); + } + + virtual SyncState getSyncState( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getSyncStateAsync( + IRequestContextPtr ctx = {}) override; + + virtual SyncChunk getFilteredSyncChunk( + qint32 afterUSN, + qint32 maxEntries, + const SyncChunkFilter & filter, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getFilteredSyncChunkAsync( + qint32 afterUSN, + qint32 maxEntries, + const SyncChunkFilter & filter, + IRequestContextPtr ctx = {}) override; + + virtual SyncState getLinkedNotebookSyncState( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getLinkedNotebookSyncStateAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual SyncChunk getLinkedNotebookSyncChunk( + const LinkedNotebook & linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getLinkedNotebookSyncChunkAsync( + const LinkedNotebook & linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly, + IRequestContextPtr ctx = {}) override; + + virtual QList listNotebooks( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listNotebooksAsync( + IRequestContextPtr ctx = {}) override; + + virtual QList listAccessibleBusinessNotebooks( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listAccessibleBusinessNotebooksAsync( + IRequestContextPtr ctx = {}) override; + + virtual Notebook getNotebook( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNotebookAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual Notebook getDefaultNotebook( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getDefaultNotebookAsync( + IRequestContextPtr ctx = {}) override; + + virtual Notebook createNotebook( + const Notebook & notebook, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * createNotebookAsync( + const Notebook & notebook, + IRequestContextPtr ctx = {}) override; + + virtual qint32 updateNotebook( + const Notebook & notebook, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateNotebookAsync( + const Notebook & notebook, + IRequestContextPtr ctx = {}) override; + + virtual qint32 expungeNotebook( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * expungeNotebookAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QList listTags( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listTagsAsync( + IRequestContextPtr ctx = {}) override; + + virtual QList listTagsByNotebook( + Guid notebookGuid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listTagsByNotebookAsync( + Guid notebookGuid, + IRequestContextPtr ctx = {}) override; + + virtual Tag getTag( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getTagAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual Tag createTag( + const Tag & tag, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * createTagAsync( + const Tag & tag, + IRequestContextPtr ctx = {}) override; + + virtual qint32 updateTag( + const Tag & tag, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateTagAsync( + const Tag & tag, + IRequestContextPtr ctx = {}) override; + + virtual void untagAll( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * untagAllAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual qint32 expungeTag( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * expungeTagAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QList listSearches( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listSearchesAsync( + IRequestContextPtr ctx = {}) override; + + virtual SavedSearch getSearch( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getSearchAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual SavedSearch createSearch( + const SavedSearch & search, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * createSearchAsync( + const SavedSearch & search, + IRequestContextPtr ctx = {}) override; + + virtual qint32 updateSearch( + const SavedSearch & search, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateSearchAsync( + const SavedSearch & search, + IRequestContextPtr ctx = {}) override; + + virtual qint32 expungeSearch( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * expungeSearchAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual qint32 findNoteOffset( + const NoteFilter & filter, + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * findNoteOffsetAsync( + const NoteFilter & filter, + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual NotesMetadataList findNotesMetadata( + const NoteFilter & filter, + qint32 offset, + qint32 maxNotes, + const NotesMetadataResultSpec & resultSpec, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * findNotesMetadataAsync( + const NoteFilter & filter, + qint32 offset, + qint32 maxNotes, + const NotesMetadataResultSpec & resultSpec, + IRequestContextPtr ctx = {}) override; + + virtual NoteCollectionCounts findNoteCounts( + const NoteFilter & filter, + bool withTrash, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * findNoteCountsAsync( + const NoteFilter & filter, + bool withTrash, + IRequestContextPtr ctx = {}) override; + + virtual Note getNoteWithResultSpec( + Guid guid, + const NoteResultSpec & resultSpec, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteWithResultSpecAsync( + Guid guid, + const NoteResultSpec & resultSpec, + IRequestContextPtr ctx = {}) override; + + virtual Note getNote( + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteAsync( + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual LazyMap getNoteApplicationData( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteApplicationDataAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QString getNoteApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual qint32 setNoteApplicationDataEntry( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * setNoteApplicationDataEntryAsync( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx = {}) override; + + virtual qint32 unsetNoteApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * unsetNoteApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual QString getNoteContent( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteContentAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QString getNoteSearchText( + Guid guid, + bool noteOnly, + bool tokenizeForIndexing, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteSearchTextAsync( + Guid guid, + bool noteOnly, + bool tokenizeForIndexing, + IRequestContextPtr ctx = {}) override; + + virtual QString getResourceSearchText( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceSearchTextAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QStringList getNoteTagNames( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteTagNamesAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual Note createNote( + const Note & note, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * createNoteAsync( + const Note & note, + IRequestContextPtr ctx = {}) override; + + virtual Note updateNote( + const Note & note, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateNoteAsync( + const Note & note, + IRequestContextPtr ctx = {}) override; + + virtual qint32 deleteNote( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * deleteNoteAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual qint32 expungeNote( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * expungeNoteAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual Note copyNote( + Guid noteGuid, + Guid toNotebookGuid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * copyNoteAsync( + Guid noteGuid, + Guid toNotebookGuid, + IRequestContextPtr ctx = {}) override; + + virtual QList listNoteVersions( + Guid noteGuid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listNoteVersionsAsync( + Guid noteGuid, + IRequestContextPtr ctx = {}) override; + + virtual Note getNoteVersion( + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNoteVersionAsync( + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual Resource getResource( + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceAsync( + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual LazyMap getResourceApplicationData( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceApplicationDataAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QString getResourceApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual qint32 setResourceApplicationDataEntry( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * setResourceApplicationDataEntryAsync( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx = {}) override; + + virtual qint32 unsetResourceApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * unsetResourceApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx = {}) override; + + virtual qint32 updateResource( + const Resource & resource, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateResourceAsync( + const Resource & resource, + IRequestContextPtr ctx = {}) override; + + virtual QByteArray getResourceData( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceDataAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual Resource getResourceByHash( + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceByHashAsync( + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData, + IRequestContextPtr ctx = {}) override; + + virtual QByteArray getResourceRecognition( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceRecognitionAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual QByteArray getResourceAlternateData( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceAlternateDataAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual ResourceAttributes getResourceAttributes( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getResourceAttributesAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual Notebook getPublicNotebook( + UserID userId, + QString publicUri, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getPublicNotebookAsync( + UserID userId, + QString publicUri, + IRequestContextPtr ctx = {}) override; + + virtual SharedNotebook shareNotebook( + const SharedNotebook & sharedNotebook, + QString message, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * shareNotebookAsync( + const SharedNotebook & sharedNotebook, + QString message, + IRequestContextPtr ctx = {}) override; + + virtual CreateOrUpdateNotebookSharesResult createOrUpdateNotebookShares( + const NotebookShareTemplate & shareTemplate, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * createOrUpdateNotebookSharesAsync( + const NotebookShareTemplate & shareTemplate, + IRequestContextPtr ctx = {}) override; + + virtual qint32 updateSharedNotebook( + const SharedNotebook & sharedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateSharedNotebookAsync( + const SharedNotebook & sharedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual Notebook setNotebookRecipientSettings( + QString notebookGuid, + const NotebookRecipientSettings & recipientSettings, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * setNotebookRecipientSettingsAsync( + QString notebookGuid, + const NotebookRecipientSettings & recipientSettings, + IRequestContextPtr ctx = {}) override; + + virtual QList listSharedNotebooks( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listSharedNotebooksAsync( + IRequestContextPtr ctx = {}) override; + + virtual LinkedNotebook createLinkedNotebook( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * createLinkedNotebookAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual qint32 updateLinkedNotebook( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateLinkedNotebookAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx = {}) override; + + virtual QList listLinkedNotebooks( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listLinkedNotebooksAsync( + IRequestContextPtr ctx = {}) override; + + virtual qint32 expungeLinkedNotebook( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * expungeLinkedNotebookAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AuthenticationResult authenticateToSharedNotebook( + QString shareKeyOrGlobalId, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * authenticateToSharedNotebookAsync( + QString shareKeyOrGlobalId, + IRequestContextPtr ctx = {}) override; + + virtual SharedNotebook getSharedNotebookByAuth( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getSharedNotebookByAuthAsync( + IRequestContextPtr ctx = {}) override; + + virtual void emailNote( + const NoteEmailParameters & parameters, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * emailNoteAsync( + const NoteEmailParameters & parameters, + IRequestContextPtr ctx = {}) override; + + virtual QString shareNote( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * shareNoteAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual void stopSharingNote( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * stopSharingNoteAsync( + Guid guid, + IRequestContextPtr ctx = {}) override; + + virtual AuthenticationResult authenticateToSharedNote( + QString guid, + QString noteKey, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * authenticateToSharedNoteAsync( + QString guid, + QString noteKey, + IRequestContextPtr ctx = {}) override; + + virtual RelatedResult findRelated( + const RelatedQuery & query, + const RelatedResultSpec & resultSpec, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * findRelatedAsync( + const RelatedQuery & query, + const RelatedResultSpec & resultSpec, + IRequestContextPtr ctx = {}) override; + + virtual UpdateNoteIfUsnMatchesResult updateNoteIfUsnMatches( + const Note & note, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateNoteIfUsnMatchesAsync( + const Note & note, + IRequestContextPtr ctx = {}) override; + + virtual ManageNotebookSharesResult manageNotebookShares( + const ManageNotebookSharesParameters & parameters, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * manageNotebookSharesAsync( + const ManageNotebookSharesParameters & parameters, + IRequestContextPtr ctx = {}) override; + + virtual ShareRelationships getNotebookShares( + QString notebookGuid, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getNotebookSharesAsync( + QString notebookGuid, + IRequestContextPtr ctx = {}) override; + +private: + INoteStorePtr m_service; + IDurableServicePtr m_durableService; + IRequestContextPtr m_ctx; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class Q_DECL_HIDDEN DurableUserStore: public IUserStore +{ + Q_OBJECT + Q_DISABLE_COPY(DurableUserStore) +public: + explicit DurableUserStore( + IUserStorePtr service, + IRequestContextPtr ctx = {}, + IRetryPolicyPtr retryPolicy = newRetryPolicy(), + QObject * parent = nullptr) : + IUserStore(parent), + m_service(std::move(service)), + m_durableService(newDurableService(retryPolicy, ctx)), + m_ctx(std::move(ctx)) + { + if (!m_ctx) { + m_ctx = newRequestContext(); + } + + m_service->setParent(this); + } + + ~DurableUserStore() + { + // Don't interfere with std::shared_ptr's lifetime tracking + m_service->setParent(nullptr); + } + + virtual void setUserStoreUrl(QString userStoreUrl) override + { + m_service->setUserStoreUrl(userStoreUrl); + } + + virtual QString userStoreUrl() const override + { + return m_service->userStoreUrl(); + } + + virtual bool checkVersion( + QString clientName, + qint16 edamVersionMajor = EDAM_VERSION_MAJOR, + qint16 edamVersionMinor = EDAM_VERSION_MINOR, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * checkVersionAsync( + QString clientName, + qint16 edamVersionMajor = EDAM_VERSION_MAJOR, + qint16 edamVersionMinor = EDAM_VERSION_MINOR, + IRequestContextPtr ctx = {}) override; + + virtual BootstrapInfo getBootstrapInfo( + QString locale, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getBootstrapInfoAsync( + QString locale, + IRequestContextPtr ctx = {}) override; + + virtual AuthenticationResult authenticateLongSession( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * authenticateLongSessionAsync( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor, + IRequestContextPtr ctx = {}) override; + + virtual AuthenticationResult completeTwoFactorAuthentication( + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * completeTwoFactorAuthenticationAsync( + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription, + IRequestContextPtr ctx = {}) override; + + virtual void revokeLongSession( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * revokeLongSessionAsync( + IRequestContextPtr ctx = {}) override; + + virtual AuthenticationResult authenticateToBusiness( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * authenticateToBusinessAsync( + IRequestContextPtr ctx = {}) override; + + virtual User getUser( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getUserAsync( + IRequestContextPtr ctx = {}) override; + + virtual PublicUserInfo getPublicUserInfo( + QString username, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getPublicUserInfoAsync( + QString username, + IRequestContextPtr ctx = {}) override; + + virtual UserUrls getUserUrls( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getUserUrlsAsync( + IRequestContextPtr ctx = {}) override; + + virtual void inviteToBusiness( + QString emailAddress, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * inviteToBusinessAsync( + QString emailAddress, + IRequestContextPtr ctx = {}) override; + + virtual void removeFromBusiness( + QString emailAddress, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * removeFromBusinessAsync( + QString emailAddress, + IRequestContextPtr ctx = {}) override; + + virtual void updateBusinessUserIdentifier( + QString oldEmailAddress, + QString newEmailAddress, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * updateBusinessUserIdentifierAsync( + QString oldEmailAddress, + QString newEmailAddress, + IRequestContextPtr ctx = {}) override; + + virtual QList listBusinessUsers( + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listBusinessUsersAsync( + IRequestContextPtr ctx = {}) override; + + virtual QList listBusinessInvitations( + bool includeRequestedInvitations, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * listBusinessInvitationsAsync( + bool includeRequestedInvitations, + IRequestContextPtr ctx = {}) override; + + virtual AccountLimits getAccountLimits( + ServiceLevel serviceLevel, + IRequestContextPtr ctx = {}) override; + + virtual AsyncResult * getAccountLimitsAsync( + ServiceLevel serviceLevel, + IRequestContextPtr ctx = {}) override; + +private: + IUserStorePtr m_service; + IDurableServicePtr m_durableService; + IRequestContextPtr m_ctx; +}; + +//////////////////////////////////////////////////////////////////////////////// + +SyncState DurableNoteStore::getSyncState( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getSyncState( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "getSyncState", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getSyncStateAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getSyncStateAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "getSyncState", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +SyncChunk DurableNoteStore::getFilteredSyncChunk( + qint32 afterUSN, + qint32 maxEntries, + const SyncChunkFilter & filter, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getFilteredSyncChunk( + afterUSN, + maxEntries, + filter, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "afterUSN = " << afterUSN << "\n"; + strm << "maxEntries = " << maxEntries << "\n"; + strm << "filter = " << filter << "\n"; + } + + IDurableService::SyncRequest request( + "getFilteredSyncChunk", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getFilteredSyncChunkAsync( + qint32 afterUSN, + qint32 maxEntries, + const SyncChunkFilter & filter, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getFilteredSyncChunkAsync( + afterUSN, + maxEntries, + filter, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "afterUSN = " << afterUSN << "\n"; + strm << "maxEntries = " << maxEntries << "\n"; + strm << "filter = " << filter << "\n"; + } + + IDurableService::AsyncRequest request( + "getFilteredSyncChunk", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +SyncState DurableNoteStore::getLinkedNotebookSyncState( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getLinkedNotebookSyncState( + linkedNotebook, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "linkedNotebook = " << linkedNotebook << "\n"; + } + + IDurableService::SyncRequest request( + "getLinkedNotebookSyncState", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getLinkedNotebookSyncStateAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getLinkedNotebookSyncStateAsync( + linkedNotebook, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "linkedNotebook = " << linkedNotebook << "\n"; + } + + IDurableService::AsyncRequest request( + "getLinkedNotebookSyncState", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +SyncChunk DurableNoteStore::getLinkedNotebookSyncChunk( + const LinkedNotebook & linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getLinkedNotebookSyncChunk( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "linkedNotebook = " << linkedNotebook << "\n"; + strm << "afterUSN = " << afterUSN << "\n"; + strm << "maxEntries = " << maxEntries << "\n"; + strm << "fullSyncOnly = " << fullSyncOnly << "\n"; + } + + IDurableService::SyncRequest request( + "getLinkedNotebookSyncChunk", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getLinkedNotebookSyncChunkAsync( + const LinkedNotebook & linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getLinkedNotebookSyncChunkAsync( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "linkedNotebook = " << linkedNotebook << "\n"; + strm << "afterUSN = " << afterUSN << "\n"; + strm << "maxEntries = " << maxEntries << "\n"; + strm << "fullSyncOnly = " << fullSyncOnly << "\n"; + } + + IDurableService::AsyncRequest request( + "getLinkedNotebookSyncChunk", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QList DurableNoteStore::listNotebooks( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->listNotebooks( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "listNotebooks", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value>(); +} + +AsyncResult * DurableNoteStore::listNotebooksAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->listNotebooksAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "listNotebooks", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QList DurableNoteStore::listAccessibleBusinessNotebooks( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->listAccessibleBusinessNotebooks( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "listAccessibleBusinessNotebooks", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value>(); +} + +AsyncResult * DurableNoteStore::listAccessibleBusinessNotebooksAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->listAccessibleBusinessNotebooksAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "listAccessibleBusinessNotebooks", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Notebook DurableNoteStore::getNotebook( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getNotebook( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "getNotebook", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getNotebookAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getNotebookAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "getNotebook", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Notebook DurableNoteStore::getDefaultNotebook( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getDefaultNotebook( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "getDefaultNotebook", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getDefaultNotebookAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getDefaultNotebookAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "getDefaultNotebook", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Notebook DurableNoteStore::createNotebook( + const Notebook & notebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->createNotebook( + notebook, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "notebook = " << notebook << "\n"; + } + + IDurableService::SyncRequest request( + "createNotebook", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::createNotebookAsync( + const Notebook & notebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->createNotebookAsync( + notebook, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "notebook = " << notebook << "\n"; + } + + IDurableService::AsyncRequest request( + "createNotebook", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::updateNotebook( + const Notebook & notebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->updateNotebook( + notebook, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "notebook = " << notebook << "\n"; + } + + IDurableService::SyncRequest request( + "updateNotebook", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::updateNotebookAsync( + const Notebook & notebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->updateNotebookAsync( + notebook, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "notebook = " << notebook << "\n"; + } + + IDurableService::AsyncRequest request( + "updateNotebook", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::expungeNotebook( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->expungeNotebook( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "expungeNotebook", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::expungeNotebookAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->expungeNotebookAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "expungeNotebook", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QList DurableNoteStore::listTags( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->listTags( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "listTags", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value>(); +} + +AsyncResult * DurableNoteStore::listTagsAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->listTagsAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "listTags", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QList DurableNoteStore::listTagsByNotebook( + Guid notebookGuid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->listTagsByNotebook( + notebookGuid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "notebookGuid = " << notebookGuid << "\n"; + } + + IDurableService::SyncRequest request( + "listTagsByNotebook", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value>(); +} + +AsyncResult * DurableNoteStore::listTagsByNotebookAsync( + Guid notebookGuid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->listTagsByNotebookAsync( + notebookGuid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "notebookGuid = " << notebookGuid << "\n"; + } + + IDurableService::AsyncRequest request( + "listTagsByNotebook", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Tag DurableNoteStore::getTag( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getTag( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "getTag", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getTagAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getTagAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "getTag", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Tag DurableNoteStore::createTag( + const Tag & tag, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->createTag( + tag, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "tag = " << tag << "\n"; + } + + IDurableService::SyncRequest request( + "createTag", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::createTagAsync( + const Tag & tag, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->createTagAsync( + tag, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "tag = " << tag << "\n"; + } + + IDurableService::AsyncRequest request( + "createTag", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::updateTag( + const Tag & tag, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->updateTag( + tag, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "tag = " << tag << "\n"; + } + + IDurableService::SyncRequest request( + "updateTag", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::updateTagAsync( + const Tag & tag, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->updateTagAsync( + tag, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "tag = " << tag << "\n"; + } + + IDurableService::AsyncRequest request( + "updateTag", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +void DurableNoteStore::untagAll( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + m_service->untagAll( + guid, + ctx); + return IDurableService::SyncResult(QVariant(), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "untagAll", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return; +} + +AsyncResult * DurableNoteStore::untagAllAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->untagAllAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "untagAll", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::expungeTag( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->expungeTag( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "expungeTag", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::expungeTagAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->expungeTagAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "expungeTag", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QList DurableNoteStore::listSearches( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->listSearches( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "listSearches", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value>(); +} + +AsyncResult * DurableNoteStore::listSearchesAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->listSearchesAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "listSearches", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +SavedSearch DurableNoteStore::getSearch( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getSearch( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "getSearch", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getSearchAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getSearchAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "getSearch", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +SavedSearch DurableNoteStore::createSearch( + const SavedSearch & search, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->createSearch( + search, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "search = " << search << "\n"; + } + + IDurableService::SyncRequest request( + "createSearch", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::createSearchAsync( + const SavedSearch & search, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->createSearchAsync( + search, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "search = " << search << "\n"; + } + + IDurableService::AsyncRequest request( + "createSearch", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::updateSearch( + const SavedSearch & search, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->updateSearch( + search, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "search = " << search << "\n"; + } + + IDurableService::SyncRequest request( + "updateSearch", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::updateSearchAsync( + const SavedSearch & search, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->updateSearchAsync( + search, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "search = " << search << "\n"; + } + + IDurableService::AsyncRequest request( + "updateSearch", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::expungeSearch( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->expungeSearch( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "expungeSearch", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::expungeSearchAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->expungeSearchAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "expungeSearch", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::findNoteOffset( + const NoteFilter & filter, + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->findNoteOffset( + filter, + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "filter = " << filter << "\n"; + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "findNoteOffset", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::findNoteOffsetAsync( + const NoteFilter & filter, + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->findNoteOffsetAsync( + filter, + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "filter = " << filter << "\n"; + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "findNoteOffset", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +NotesMetadataList DurableNoteStore::findNotesMetadata( + const NoteFilter & filter, + qint32 offset, + qint32 maxNotes, + const NotesMetadataResultSpec & resultSpec, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->findNotesMetadata( + filter, + offset, + maxNotes, + resultSpec, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "filter = " << filter << "\n"; + strm << "offset = " << offset << "\n"; + strm << "maxNotes = " << maxNotes << "\n"; + strm << "resultSpec = " << resultSpec << "\n"; + } + + IDurableService::SyncRequest request( + "findNotesMetadata", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::findNotesMetadataAsync( + const NoteFilter & filter, + qint32 offset, + qint32 maxNotes, + const NotesMetadataResultSpec & resultSpec, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->findNotesMetadataAsync( + filter, + offset, + maxNotes, + resultSpec, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "filter = " << filter << "\n"; + strm << "offset = " << offset << "\n"; + strm << "maxNotes = " << maxNotes << "\n"; + strm << "resultSpec = " << resultSpec << "\n"; + } + + IDurableService::AsyncRequest request( + "findNotesMetadata", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +NoteCollectionCounts DurableNoteStore::findNoteCounts( + const NoteFilter & filter, + bool withTrash, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->findNoteCounts( + filter, + withTrash, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "filter = " << filter << "\n"; + strm << "withTrash = " << withTrash << "\n"; + } + + IDurableService::SyncRequest request( + "findNoteCounts", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::findNoteCountsAsync( + const NoteFilter & filter, + bool withTrash, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->findNoteCountsAsync( + filter, + withTrash, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "filter = " << filter << "\n"; + strm << "withTrash = " << withTrash << "\n"; + } + + IDurableService::AsyncRequest request( + "findNoteCounts", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Note DurableNoteStore::getNoteWithResultSpec( + Guid guid, + const NoteResultSpec & resultSpec, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getNoteWithResultSpec( + guid, + resultSpec, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "resultSpec = " << resultSpec << "\n"; + } + + IDurableService::SyncRequest request( + "getNoteWithResultSpec", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getNoteWithResultSpecAsync( + Guid guid, + const NoteResultSpec & resultSpec, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getNoteWithResultSpecAsync( + guid, + resultSpec, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "resultSpec = " << resultSpec << "\n"; + } + + IDurableService::AsyncRequest request( + "getNoteWithResultSpec", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Note DurableNoteStore::getNote( + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getNote( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "withContent = " << withContent << "\n"; + strm << "withResourcesData = " << withResourcesData << "\n"; + strm << "withResourcesRecognition = " << withResourcesRecognition << "\n"; + strm << "withResourcesAlternateData = " << withResourcesAlternateData << "\n"; + } + + IDurableService::SyncRequest request( + "getNote", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getNoteAsync( + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getNoteAsync( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "withContent = " << withContent << "\n"; + strm << "withResourcesData = " << withResourcesData << "\n"; + strm << "withResourcesRecognition = " << withResourcesRecognition << "\n"; + strm << "withResourcesAlternateData = " << withResourcesAlternateData << "\n"; + } + + IDurableService::AsyncRequest request( + "getNote", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +LazyMap DurableNoteStore::getNoteApplicationData( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getNoteApplicationData( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "getNoteApplicationData", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getNoteApplicationDataAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getNoteApplicationDataAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "getNoteApplicationData", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QString DurableNoteStore::getNoteApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getNoteApplicationDataEntry( + guid, + key, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "key = " << key << "\n"; + } + + IDurableService::SyncRequest request( + "getNoteApplicationDataEntry", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.toString(); +} + +AsyncResult * DurableNoteStore::getNoteApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getNoteApplicationDataEntryAsync( + guid, + key, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "key = " << key << "\n"; + } + + IDurableService::AsyncRequest request( + "getNoteApplicationDataEntry", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::setNoteApplicationDataEntry( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->setNoteApplicationDataEntry( + guid, + key, + value, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "key = " << key << "\n"; + strm << "value = " << value << "\n"; + } + + IDurableService::SyncRequest request( + "setNoteApplicationDataEntry", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::setNoteApplicationDataEntryAsync( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->setNoteApplicationDataEntryAsync( + guid, + key, + value, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "key = " << key << "\n"; + strm << "value = " << value << "\n"; + } + + IDurableService::AsyncRequest request( + "setNoteApplicationDataEntry", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::unsetNoteApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->unsetNoteApplicationDataEntry( + guid, + key, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "key = " << key << "\n"; + } + + IDurableService::SyncRequest request( + "unsetNoteApplicationDataEntry", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::unsetNoteApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->unsetNoteApplicationDataEntryAsync( + guid, + key, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "key = " << key << "\n"; + } + + IDurableService::AsyncRequest request( + "unsetNoteApplicationDataEntry", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QString DurableNoteStore::getNoteContent( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getNoteContent( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "getNoteContent", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.toString(); +} + +AsyncResult * DurableNoteStore::getNoteContentAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getNoteContentAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "getNoteContent", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QString DurableNoteStore::getNoteSearchText( + Guid guid, + bool noteOnly, + bool tokenizeForIndexing, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getNoteSearchText( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "noteOnly = " << noteOnly << "\n"; + strm << "tokenizeForIndexing = " << tokenizeForIndexing << "\n"; + } + + IDurableService::SyncRequest request( + "getNoteSearchText", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.toString(); +} + +AsyncResult * DurableNoteStore::getNoteSearchTextAsync( + Guid guid, + bool noteOnly, + bool tokenizeForIndexing, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getNoteSearchTextAsync( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "noteOnly = " << noteOnly << "\n"; + strm << "tokenizeForIndexing = " << tokenizeForIndexing << "\n"; + } + + IDurableService::AsyncRequest request( + "getNoteSearchText", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QString DurableNoteStore::getResourceSearchText( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getResourceSearchText( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "getResourceSearchText", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.toString(); +} + +AsyncResult * DurableNoteStore::getResourceSearchTextAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getResourceSearchTextAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "getResourceSearchText", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QStringList DurableNoteStore::getNoteTagNames( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getNoteTagNames( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "getNoteTagNames", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.toStringList(); +} + +AsyncResult * DurableNoteStore::getNoteTagNamesAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getNoteTagNamesAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "getNoteTagNames", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Note DurableNoteStore::createNote( + const Note & note, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->createNote( + note, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "note = " << note << "\n"; + } + + IDurableService::SyncRequest request( + "createNote", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::createNoteAsync( + const Note & note, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->createNoteAsync( + note, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "note = " << note << "\n"; + } + + IDurableService::AsyncRequest request( + "createNote", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Note DurableNoteStore::updateNote( + const Note & note, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->updateNote( + note, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "note = " << note << "\n"; + } + + IDurableService::SyncRequest request( + "updateNote", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::updateNoteAsync( + const Note & note, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->updateNoteAsync( + note, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "note = " << note << "\n"; + } + + IDurableService::AsyncRequest request( + "updateNote", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::deleteNote( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->deleteNote( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "deleteNote", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::deleteNoteAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->deleteNoteAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "deleteNote", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::expungeNote( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->expungeNote( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "expungeNote", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::expungeNoteAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->expungeNoteAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "expungeNote", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Note DurableNoteStore::copyNote( + Guid noteGuid, + Guid toNotebookGuid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->copyNote( + noteGuid, + toNotebookGuid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "noteGuid = " << noteGuid << "\n"; + strm << "toNotebookGuid = " << toNotebookGuid << "\n"; + } + + IDurableService::SyncRequest request( + "copyNote", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::copyNoteAsync( + Guid noteGuid, + Guid toNotebookGuid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->copyNoteAsync( + noteGuid, + toNotebookGuid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "noteGuid = " << noteGuid << "\n"; + strm << "toNotebookGuid = " << toNotebookGuid << "\n"; + } + + IDurableService::AsyncRequest request( + "copyNote", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QList DurableNoteStore::listNoteVersions( + Guid noteGuid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->listNoteVersions( + noteGuid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "noteGuid = " << noteGuid << "\n"; + } + + IDurableService::SyncRequest request( + "listNoteVersions", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value>(); +} + +AsyncResult * DurableNoteStore::listNoteVersionsAsync( + Guid noteGuid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->listNoteVersionsAsync( + noteGuid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "noteGuid = " << noteGuid << "\n"; + } + + IDurableService::AsyncRequest request( + "listNoteVersions", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Note DurableNoteStore::getNoteVersion( + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getNoteVersion( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "noteGuid = " << noteGuid << "\n"; + strm << "updateSequenceNum = " << updateSequenceNum << "\n"; + strm << "withResourcesData = " << withResourcesData << "\n"; + strm << "withResourcesRecognition = " << withResourcesRecognition << "\n"; + strm << "withResourcesAlternateData = " << withResourcesAlternateData << "\n"; + } + + IDurableService::SyncRequest request( + "getNoteVersion", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getNoteVersionAsync( + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getNoteVersionAsync( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "noteGuid = " << noteGuid << "\n"; + strm << "updateSequenceNum = " << updateSequenceNum << "\n"; + strm << "withResourcesData = " << withResourcesData << "\n"; + strm << "withResourcesRecognition = " << withResourcesRecognition << "\n"; + strm << "withResourcesAlternateData = " << withResourcesAlternateData << "\n"; + } + + IDurableService::AsyncRequest request( + "getNoteVersion", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Resource DurableNoteStore::getResource( + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getResource( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "withData = " << withData << "\n"; + strm << "withRecognition = " << withRecognition << "\n"; + strm << "withAttributes = " << withAttributes << "\n"; + strm << "withAlternateData = " << withAlternateData << "\n"; + } + + IDurableService::SyncRequest request( + "getResource", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getResourceAsync( + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getResourceAsync( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "withData = " << withData << "\n"; + strm << "withRecognition = " << withRecognition << "\n"; + strm << "withAttributes = " << withAttributes << "\n"; + strm << "withAlternateData = " << withAlternateData << "\n"; + } + + IDurableService::AsyncRequest request( + "getResource", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +LazyMap DurableNoteStore::getResourceApplicationData( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getResourceApplicationData( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "getResourceApplicationData", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getResourceApplicationDataAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getResourceApplicationDataAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "getResourceApplicationData", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QString DurableNoteStore::getResourceApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getResourceApplicationDataEntry( + guid, + key, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "key = " << key << "\n"; + } + + IDurableService::SyncRequest request( + "getResourceApplicationDataEntry", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.toString(); +} + +AsyncResult * DurableNoteStore::getResourceApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getResourceApplicationDataEntryAsync( + guid, + key, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "key = " << key << "\n"; + } + + IDurableService::AsyncRequest request( + "getResourceApplicationDataEntry", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::setResourceApplicationDataEntry( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->setResourceApplicationDataEntry( + guid, + key, + value, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "key = " << key << "\n"; + strm << "value = " << value << "\n"; + } + + IDurableService::SyncRequest request( + "setResourceApplicationDataEntry", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::setResourceApplicationDataEntryAsync( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->setResourceApplicationDataEntryAsync( + guid, + key, + value, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "key = " << key << "\n"; + strm << "value = " << value << "\n"; + } + + IDurableService::AsyncRequest request( + "setResourceApplicationDataEntry", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::unsetResourceApplicationDataEntry( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->unsetResourceApplicationDataEntry( + guid, + key, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "key = " << key << "\n"; + } + + IDurableService::SyncRequest request( + "unsetResourceApplicationDataEntry", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::unsetResourceApplicationDataEntryAsync( + Guid guid, + QString key, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->unsetResourceApplicationDataEntryAsync( + guid, + key, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "key = " << key << "\n"; + } + + IDurableService::AsyncRequest request( + "unsetResourceApplicationDataEntry", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::updateResource( + const Resource & resource, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->updateResource( + resource, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "resource = " << resource << "\n"; + } + + IDurableService::SyncRequest request( + "updateResource", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::updateResourceAsync( + const Resource & resource, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->updateResourceAsync( + resource, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "resource = " << resource << "\n"; + } + + IDurableService::AsyncRequest request( + "updateResource", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QByteArray DurableNoteStore::getResourceData( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getResourceData( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "getResourceData", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.toByteArray(); +} + +AsyncResult * DurableNoteStore::getResourceDataAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getResourceDataAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "getResourceData", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Resource DurableNoteStore::getResourceByHash( + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getResourceByHash( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "noteGuid = " << noteGuid << "\n"; + strm << "contentHash = " << contentHash << "\n"; + strm << "withData = " << withData << "\n"; + strm << "withRecognition = " << withRecognition << "\n"; + strm << "withAlternateData = " << withAlternateData << "\n"; + } + + IDurableService::SyncRequest request( + "getResourceByHash", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getResourceByHashAsync( + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getResourceByHashAsync( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "noteGuid = " << noteGuid << "\n"; + strm << "contentHash = " << contentHash << "\n"; + strm << "withData = " << withData << "\n"; + strm << "withRecognition = " << withRecognition << "\n"; + strm << "withAlternateData = " << withAlternateData << "\n"; + } + + IDurableService::AsyncRequest request( + "getResourceByHash", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QByteArray DurableNoteStore::getResourceRecognition( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getResourceRecognition( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "getResourceRecognition", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.toByteArray(); +} + +AsyncResult * DurableNoteStore::getResourceRecognitionAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getResourceRecognitionAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "getResourceRecognition", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QByteArray DurableNoteStore::getResourceAlternateData( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getResourceAlternateData( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "getResourceAlternateData", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.toByteArray(); +} + +AsyncResult * DurableNoteStore::getResourceAlternateDataAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getResourceAlternateDataAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "getResourceAlternateData", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +ResourceAttributes DurableNoteStore::getResourceAttributes( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getResourceAttributes( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "getResourceAttributes", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getResourceAttributesAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getResourceAttributesAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "getResourceAttributes", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Notebook DurableNoteStore::getPublicNotebook( + UserID userId, + QString publicUri, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getPublicNotebook( + userId, + publicUri, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "userId = " << userId << "\n"; + strm << "publicUri = " << publicUri << "\n"; + } + + IDurableService::SyncRequest request( + "getPublicNotebook", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getPublicNotebookAsync( + UserID userId, + QString publicUri, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getPublicNotebookAsync( + userId, + publicUri, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "userId = " << userId << "\n"; + strm << "publicUri = " << publicUri << "\n"; + } + + IDurableService::AsyncRequest request( + "getPublicNotebook", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +SharedNotebook DurableNoteStore::shareNotebook( + const SharedNotebook & sharedNotebook, + QString message, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->shareNotebook( + sharedNotebook, + message, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "sharedNotebook = " << sharedNotebook << "\n"; + strm << "message = " << message << "\n"; + } + + IDurableService::SyncRequest request( + "shareNotebook", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::shareNotebookAsync( + const SharedNotebook & sharedNotebook, + QString message, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->shareNotebookAsync( + sharedNotebook, + message, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "sharedNotebook = " << sharedNotebook << "\n"; + strm << "message = " << message << "\n"; + } + + IDurableService::AsyncRequest request( + "shareNotebook", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +CreateOrUpdateNotebookSharesResult DurableNoteStore::createOrUpdateNotebookShares( + const NotebookShareTemplate & shareTemplate, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->createOrUpdateNotebookShares( + shareTemplate, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "shareTemplate = " << shareTemplate << "\n"; + } + + IDurableService::SyncRequest request( + "createOrUpdateNotebookShares", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::createOrUpdateNotebookSharesAsync( + const NotebookShareTemplate & shareTemplate, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->createOrUpdateNotebookSharesAsync( + shareTemplate, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "shareTemplate = " << shareTemplate << "\n"; + } + + IDurableService::AsyncRequest request( + "createOrUpdateNotebookShares", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::updateSharedNotebook( + const SharedNotebook & sharedNotebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->updateSharedNotebook( + sharedNotebook, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "sharedNotebook = " << sharedNotebook << "\n"; + } + + IDurableService::SyncRequest request( + "updateSharedNotebook", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::updateSharedNotebookAsync( + const SharedNotebook & sharedNotebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->updateSharedNotebookAsync( + sharedNotebook, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "sharedNotebook = " << sharedNotebook << "\n"; + } + + IDurableService::AsyncRequest request( + "updateSharedNotebook", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +Notebook DurableNoteStore::setNotebookRecipientSettings( + QString notebookGuid, + const NotebookRecipientSettings & recipientSettings, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->setNotebookRecipientSettings( + notebookGuid, + recipientSettings, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "notebookGuid = " << notebookGuid << "\n"; + strm << "recipientSettings = " << recipientSettings << "\n"; + } + + IDurableService::SyncRequest request( + "setNotebookRecipientSettings", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::setNotebookRecipientSettingsAsync( + QString notebookGuid, + const NotebookRecipientSettings & recipientSettings, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->setNotebookRecipientSettingsAsync( + notebookGuid, + recipientSettings, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "notebookGuid = " << notebookGuid << "\n"; + strm << "recipientSettings = " << recipientSettings << "\n"; + } + + IDurableService::AsyncRequest request( + "setNotebookRecipientSettings", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QList DurableNoteStore::listSharedNotebooks( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->listSharedNotebooks( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "listSharedNotebooks", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value>(); +} + +AsyncResult * DurableNoteStore::listSharedNotebooksAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->listSharedNotebooksAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "listSharedNotebooks", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +LinkedNotebook DurableNoteStore::createLinkedNotebook( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->createLinkedNotebook( + linkedNotebook, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "linkedNotebook = " << linkedNotebook << "\n"; + } + + IDurableService::SyncRequest request( + "createLinkedNotebook", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::createLinkedNotebookAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->createLinkedNotebookAsync( + linkedNotebook, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "linkedNotebook = " << linkedNotebook << "\n"; + } + + IDurableService::AsyncRequest request( + "createLinkedNotebook", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::updateLinkedNotebook( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->updateLinkedNotebook( + linkedNotebook, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "linkedNotebook = " << linkedNotebook << "\n"; + } + + IDurableService::SyncRequest request( + "updateLinkedNotebook", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::updateLinkedNotebookAsync( + const LinkedNotebook & linkedNotebook, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->updateLinkedNotebookAsync( + linkedNotebook, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "linkedNotebook = " << linkedNotebook << "\n"; + } + + IDurableService::AsyncRequest request( + "updateLinkedNotebook", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QList DurableNoteStore::listLinkedNotebooks( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->listLinkedNotebooks( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "listLinkedNotebooks", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value>(); +} + +AsyncResult * DurableNoteStore::listLinkedNotebooksAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->listLinkedNotebooksAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "listLinkedNotebooks", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +qint32 DurableNoteStore::expungeLinkedNotebook( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->expungeLinkedNotebook( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "expungeLinkedNotebook", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::expungeLinkedNotebookAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->expungeLinkedNotebookAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "expungeLinkedNotebook", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +AuthenticationResult DurableNoteStore::authenticateToSharedNotebook( + QString shareKeyOrGlobalId, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->authenticateToSharedNotebook( + shareKeyOrGlobalId, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "shareKeyOrGlobalId = " << shareKeyOrGlobalId << "\n"; + } + + IDurableService::SyncRequest request( + "authenticateToSharedNotebook", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::authenticateToSharedNotebookAsync( + QString shareKeyOrGlobalId, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->authenticateToSharedNotebookAsync( + shareKeyOrGlobalId, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "shareKeyOrGlobalId = " << shareKeyOrGlobalId << "\n"; + } + + IDurableService::AsyncRequest request( + "authenticateToSharedNotebook", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +SharedNotebook DurableNoteStore::getSharedNotebookByAuth( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getSharedNotebookByAuth( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "getSharedNotebookByAuth", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getSharedNotebookByAuthAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getSharedNotebookByAuthAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "getSharedNotebookByAuth", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +void DurableNoteStore::emailNote( + const NoteEmailParameters & parameters, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + m_service->emailNote( + parameters, + ctx); + return IDurableService::SyncResult(QVariant(), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "parameters = " << parameters << "\n"; + } + + IDurableService::SyncRequest request( + "emailNote", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return; +} + +AsyncResult * DurableNoteStore::emailNoteAsync( + const NoteEmailParameters & parameters, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->emailNoteAsync( + parameters, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "parameters = " << parameters << "\n"; + } + + IDurableService::AsyncRequest request( + "emailNote", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QString DurableNoteStore::shareNote( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->shareNote( + guid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "shareNote", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.toString(); +} + +AsyncResult * DurableNoteStore::shareNoteAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->shareNoteAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "shareNote", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +void DurableNoteStore::stopSharingNote( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + m_service->stopSharingNote( + guid, + ctx); + return IDurableService::SyncResult(QVariant(), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::SyncRequest request( + "stopSharingNote", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return; +} + +AsyncResult * DurableNoteStore::stopSharingNoteAsync( + Guid guid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->stopSharingNoteAsync( + guid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + } + + IDurableService::AsyncRequest request( + "stopSharingNote", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +AuthenticationResult DurableNoteStore::authenticateToSharedNote( + QString guid, + QString noteKey, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->authenticateToSharedNote( + guid, + noteKey, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "noteKey = " << noteKey << "\n"; + } + + IDurableService::SyncRequest request( + "authenticateToSharedNote", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::authenticateToSharedNoteAsync( + QString guid, + QString noteKey, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->authenticateToSharedNoteAsync( + guid, + noteKey, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "guid = " << guid << "\n"; + strm << "noteKey = " << noteKey << "\n"; + } + + IDurableService::AsyncRequest request( + "authenticateToSharedNote", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +RelatedResult DurableNoteStore::findRelated( + const RelatedQuery & query, + const RelatedResultSpec & resultSpec, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->findRelated( + query, + resultSpec, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "query = " << query << "\n"; + strm << "resultSpec = " << resultSpec << "\n"; + } + + IDurableService::SyncRequest request( + "findRelated", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::findRelatedAsync( + const RelatedQuery & query, + const RelatedResultSpec & resultSpec, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->findRelatedAsync( + query, + resultSpec, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "query = " << query << "\n"; + strm << "resultSpec = " << resultSpec << "\n"; + } + + IDurableService::AsyncRequest request( + "findRelated", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +UpdateNoteIfUsnMatchesResult DurableNoteStore::updateNoteIfUsnMatches( + const Note & note, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->updateNoteIfUsnMatches( + note, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "note = " << note << "\n"; + } + + IDurableService::SyncRequest request( + "updateNoteIfUsnMatches", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::updateNoteIfUsnMatchesAsync( + const Note & note, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->updateNoteIfUsnMatchesAsync( + note, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "note = " << note << "\n"; + } + + IDurableService::AsyncRequest request( + "updateNoteIfUsnMatches", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +ManageNotebookSharesResult DurableNoteStore::manageNotebookShares( + const ManageNotebookSharesParameters & parameters, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->manageNotebookShares( + parameters, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "parameters = " << parameters << "\n"; + } + + IDurableService::SyncRequest request( + "manageNotebookShares", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::manageNotebookSharesAsync( + const ManageNotebookSharesParameters & parameters, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->manageNotebookSharesAsync( + parameters, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "parameters = " << parameters << "\n"; + } + + IDurableService::AsyncRequest request( + "manageNotebookShares", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +ShareRelationships DurableNoteStore::getNotebookShares( + QString notebookGuid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getNotebookShares( + notebookGuid, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "notebookGuid = " << notebookGuid << "\n"; + } + + IDurableService::SyncRequest request( + "getNotebookShares", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableNoteStore::getNotebookSharesAsync( + QString notebookGuid, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getNotebookSharesAsync( + notebookGuid, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "notebookGuid = " << notebookGuid << "\n"; + } + + IDurableService::AsyncRequest request( + "getNotebookShares", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +//////////////////////////////////////////////////////////////////////////////// + +bool DurableUserStore::checkVersion( + QString clientName, + qint16 edamVersionMajor, + qint16 edamVersionMinor, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->checkVersion( + clientName, + edamVersionMajor, + edamVersionMinor, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "clientName = " << clientName << "\n"; + strm << "edamVersionMajor = " << edamVersionMajor << "\n"; + strm << "edamVersionMinor = " << edamVersionMinor << "\n"; + } + + IDurableService::SyncRequest request( + "checkVersion", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.toBool(); +} + +AsyncResult * DurableUserStore::checkVersionAsync( + QString clientName, + qint16 edamVersionMajor, + qint16 edamVersionMinor, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->checkVersionAsync( + clientName, + edamVersionMajor, + edamVersionMinor, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "clientName = " << clientName << "\n"; + strm << "edamVersionMajor = " << edamVersionMajor << "\n"; + strm << "edamVersionMinor = " << edamVersionMinor << "\n"; + } + + IDurableService::AsyncRequest request( + "checkVersion", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +BootstrapInfo DurableUserStore::getBootstrapInfo( + QString locale, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getBootstrapInfo( + locale, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "locale = " << locale << "\n"; + } + + IDurableService::SyncRequest request( + "getBootstrapInfo", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableUserStore::getBootstrapInfoAsync( + QString locale, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getBootstrapInfoAsync( + locale, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "locale = " << locale << "\n"; + } + + IDurableService::AsyncRequest request( + "getBootstrapInfo", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +AuthenticationResult DurableUserStore::authenticateLongSession( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->authenticateLongSession( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "username = " << username << "\n"; + strm << "deviceIdentifier = " << deviceIdentifier << "\n"; + strm << "deviceDescription = " << deviceDescription << "\n"; + strm << "supportsTwoFactor = " << supportsTwoFactor << "\n"; + } + + IDurableService::SyncRequest request( + "authenticateLongSession", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableUserStore::authenticateLongSessionAsync( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->authenticateLongSessionAsync( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "username = " << username << "\n"; + strm << "deviceIdentifier = " << deviceIdentifier << "\n"; + strm << "deviceDescription = " << deviceDescription << "\n"; + strm << "supportsTwoFactor = " << supportsTwoFactor << "\n"; + } + + IDurableService::AsyncRequest request( + "authenticateLongSession", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +AuthenticationResult DurableUserStore::completeTwoFactorAuthentication( + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->completeTwoFactorAuthentication( + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "deviceIdentifier = " << deviceIdentifier << "\n"; + strm << "deviceDescription = " << deviceDescription << "\n"; + } + + IDurableService::SyncRequest request( + "completeTwoFactorAuthentication", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableUserStore::completeTwoFactorAuthenticationAsync( + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->completeTwoFactorAuthenticationAsync( + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "deviceIdentifier = " << deviceIdentifier << "\n"; + strm << "deviceDescription = " << deviceDescription << "\n"; + } + + IDurableService::AsyncRequest request( + "completeTwoFactorAuthentication", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +void DurableUserStore::revokeLongSession( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + m_service->revokeLongSession( + ctx); + return IDurableService::SyncResult(QVariant(), {}); + }); + + IDurableService::SyncRequest request( + "revokeLongSession", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return; +} + +AsyncResult * DurableUserStore::revokeLongSessionAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->revokeLongSessionAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "revokeLongSession", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +AuthenticationResult DurableUserStore::authenticateToBusiness( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->authenticateToBusiness( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "authenticateToBusiness", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableUserStore::authenticateToBusinessAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->authenticateToBusinessAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "authenticateToBusiness", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +User DurableUserStore::getUser( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getUser( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "getUser", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableUserStore::getUserAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getUserAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "getUser", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +PublicUserInfo DurableUserStore::getPublicUserInfo( + QString username, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getPublicUserInfo( + username, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "username = " << username << "\n"; + } + + IDurableService::SyncRequest request( + "getPublicUserInfo", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableUserStore::getPublicUserInfoAsync( + QString username, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getPublicUserInfoAsync( + username, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "username = " << username << "\n"; + } + + IDurableService::AsyncRequest request( + "getPublicUserInfo", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +UserUrls DurableUserStore::getUserUrls( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getUserUrls( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "getUserUrls", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableUserStore::getUserUrlsAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getUserUrlsAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "getUserUrls", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +void DurableUserStore::inviteToBusiness( + QString emailAddress, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + m_service->inviteToBusiness( + emailAddress, + ctx); + return IDurableService::SyncResult(QVariant(), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "emailAddress = " << emailAddress << "\n"; + } + + IDurableService::SyncRequest request( + "inviteToBusiness", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return; +} + +AsyncResult * DurableUserStore::inviteToBusinessAsync( + QString emailAddress, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->inviteToBusinessAsync( + emailAddress, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "emailAddress = " << emailAddress << "\n"; + } + + IDurableService::AsyncRequest request( + "inviteToBusiness", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +void DurableUserStore::removeFromBusiness( + QString emailAddress, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + m_service->removeFromBusiness( + emailAddress, + ctx); + return IDurableService::SyncResult(QVariant(), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "emailAddress = " << emailAddress << "\n"; + } + + IDurableService::SyncRequest request( + "removeFromBusiness", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return; +} + +AsyncResult * DurableUserStore::removeFromBusinessAsync( + QString emailAddress, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->removeFromBusinessAsync( + emailAddress, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "emailAddress = " << emailAddress << "\n"; + } + + IDurableService::AsyncRequest request( + "removeFromBusiness", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +void DurableUserStore::updateBusinessUserIdentifier( + QString oldEmailAddress, + QString newEmailAddress, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + m_service->updateBusinessUserIdentifier( + oldEmailAddress, + newEmailAddress, + ctx); + return IDurableService::SyncResult(QVariant(), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "oldEmailAddress = " << oldEmailAddress << "\n"; + strm << "newEmailAddress = " << newEmailAddress << "\n"; + } + + IDurableService::SyncRequest request( + "updateBusinessUserIdentifier", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return; +} + +AsyncResult * DurableUserStore::updateBusinessUserIdentifierAsync( + QString oldEmailAddress, + QString newEmailAddress, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->updateBusinessUserIdentifierAsync( + oldEmailAddress, + newEmailAddress, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "oldEmailAddress = " << oldEmailAddress << "\n"; + strm << "newEmailAddress = " << newEmailAddress << "\n"; + } + + IDurableService::AsyncRequest request( + "updateBusinessUserIdentifier", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QList DurableUserStore::listBusinessUsers( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->listBusinessUsers( + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + IDurableService::SyncRequest request( + "listBusinessUsers", + {}, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value>(); +} + +AsyncResult * DurableUserStore::listBusinessUsersAsync( + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->listBusinessUsersAsync( + ctx); + }); + + IDurableService::AsyncRequest request( + "listBusinessUsers", + {}, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +QList DurableUserStore::listBusinessInvitations( + bool includeRequestedInvitations, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->listBusinessInvitations( + includeRequestedInvitations, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "includeRequestedInvitations = " << includeRequestedInvitations << "\n"; + } + + IDurableService::SyncRequest request( + "listBusinessInvitations", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value>(); +} + +AsyncResult * DurableUserStore::listBusinessInvitationsAsync( + bool includeRequestedInvitations, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->listBusinessInvitationsAsync( + includeRequestedInvitations, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "includeRequestedInvitations = " << includeRequestedInvitations << "\n"; + } + + IDurableService::AsyncRequest request( + "listBusinessInvitations", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +AccountLimits DurableUserStore::getAccountLimits( + ServiceLevel serviceLevel, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::SyncServiceCall( + [&] (IRequestContextPtr ctx) + { + auto res = m_service->getAccountLimits( + serviceLevel, + ctx); + return IDurableService::SyncResult(QVariant::fromValue(res), {}); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "serviceLevel = " << serviceLevel << "\n"; + } + + IDurableService::SyncRequest request( + "getAccountLimits", + requestDescription, + std::move(call)); + + auto result = m_durableService->executeSyncRequest( + std::move(request), ctx); + + if (result.second) { + result.second->throwException(); + } + + return result.first.value(); +} + +AsyncResult * DurableUserStore::getAccountLimitsAsync( + ServiceLevel serviceLevel, + IRequestContextPtr ctx) +{ + if (!ctx) { + ctx.reset(m_ctx->clone()); + } + + auto call = IDurableService::AsyncServiceCall( + [=, service=m_service] (IRequestContextPtr ctx) + { + return service->getAccountLimitsAsync( + serviceLevel, + ctx); + }); + + QString requestDescription; + QTextStream strm(&requestDescription); + if (logger()->shouldLog(LogLevel::Trace, "durable_service")) { + strm << "serviceLevel = " << serviceLevel << "\n"; + } + + IDurableService::AsyncRequest request( + "getAccountLimits", + requestDescription, + std::move(call)); + + return m_durableService->executeAsyncRequest( + std::move(request), ctx); + +} + +//////////////////////////////////////////////////////////////////////////////// + +INoteStore * newNoteStore( + QString noteStoreUrl, + IRequestContextPtr ctx, + QObject * parent, + IRetryPolicyPtr retryPolicy) +{ + if (ctx && ctx->maxRequestRetryCount() == 0) + { + return new NoteStore(noteStoreUrl, ctx); + } + else + { + if (!retryPolicy) { + retryPolicy = newRetryPolicy(); + } + + return new DurableNoteStore( + std::make_shared(noteStoreUrl, ctx), + ctx, + retryPolicy, + parent); + } +} + +IUserStore * newUserStore( + QString userStoreUrl, + IRequestContextPtr ctx, + QObject * parent, + IRetryPolicyPtr retryPolicy) +{ + if (ctx && ctx->maxRequestRetryCount() == 0) + { + return new UserStore(userStoreUrl, ctx); + } + else + { + if (!retryPolicy) { + retryPolicy = newRetryPolicy(); + } + + return new DurableUserStore( + std::make_shared(userStoreUrl, ctx), + ctx, + retryPolicy, + parent); + } +} + +} // namespace qevercloud + +#include diff --git a/src/qevercloud/QEverCloud/src/generated/Types.cpp b/src/qevercloud/QEverCloud/src/generated/Types.cpp new file mode 100644 index 00000000..7e4e0485 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/generated/Types.cpp @@ -0,0 +1,21907 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + * + * This file was generated from Evernote Thrift API + */ + +#include +#include "../Impl.h" +#include "../Impl.h" +#include "Types_io.h" +#include +#include +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +/** @cond HIDDEN_SYMBOLS */ + +void readEnumEDAMErrorCode( + ThriftBinaryBufferReader & reader, + EDAMErrorCode & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(EDAMErrorCode::UNKNOWN): e = EDAMErrorCode::UNKNOWN; break; + case static_cast(EDAMErrorCode::BAD_DATA_FORMAT): e = EDAMErrorCode::BAD_DATA_FORMAT; break; + case static_cast(EDAMErrorCode::PERMISSION_DENIED): e = EDAMErrorCode::PERMISSION_DENIED; break; + case static_cast(EDAMErrorCode::INTERNAL_ERROR): e = EDAMErrorCode::INTERNAL_ERROR; break; + case static_cast(EDAMErrorCode::DATA_REQUIRED): e = EDAMErrorCode::DATA_REQUIRED; break; + case static_cast(EDAMErrorCode::LIMIT_REACHED): e = EDAMErrorCode::LIMIT_REACHED; break; + case static_cast(EDAMErrorCode::QUOTA_REACHED): e = EDAMErrorCode::QUOTA_REACHED; break; + case static_cast(EDAMErrorCode::INVALID_AUTH): e = EDAMErrorCode::INVALID_AUTH; break; + case static_cast(EDAMErrorCode::AUTH_EXPIRED): e = EDAMErrorCode::AUTH_EXPIRED; break; + case static_cast(EDAMErrorCode::DATA_CONFLICT): e = EDAMErrorCode::DATA_CONFLICT; break; + case static_cast(EDAMErrorCode::ENML_VALIDATION): e = EDAMErrorCode::ENML_VALIDATION; break; + case static_cast(EDAMErrorCode::SHARD_UNAVAILABLE): e = EDAMErrorCode::SHARD_UNAVAILABLE; break; + case static_cast(EDAMErrorCode::LEN_TOO_SHORT): e = EDAMErrorCode::LEN_TOO_SHORT; break; + case static_cast(EDAMErrorCode::LEN_TOO_LONG): e = EDAMErrorCode::LEN_TOO_LONG; break; + case static_cast(EDAMErrorCode::TOO_FEW): e = EDAMErrorCode::TOO_FEW; break; + case static_cast(EDAMErrorCode::TOO_MANY): e = EDAMErrorCode::TOO_MANY; break; + case static_cast(EDAMErrorCode::UNSUPPORTED_OPERATION): e = EDAMErrorCode::UNSUPPORTED_OPERATION; break; + case static_cast(EDAMErrorCode::TAKEN_DOWN): e = EDAMErrorCode::TAKEN_DOWN; break; + case static_cast(EDAMErrorCode::RATE_LIMIT_REACHED): e = EDAMErrorCode::RATE_LIMIT_REACHED; break; + case static_cast(EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED): e = EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED; break; + case static_cast(EDAMErrorCode::DEVICE_LIMIT_REACHED): e = EDAMErrorCode::DEVICE_LIMIT_REACHED; break; + case static_cast(EDAMErrorCode::OPENID_ALREADY_TAKEN): e = EDAMErrorCode::OPENID_ALREADY_TAKEN; break; + case static_cast(EDAMErrorCode::INVALID_OPENID_TOKEN): e = EDAMErrorCode::INVALID_OPENID_TOKEN; break; + case static_cast(EDAMErrorCode::USER_NOT_ASSOCIATED): e = EDAMErrorCode::USER_NOT_ASSOCIATED; break; + case static_cast(EDAMErrorCode::USER_NOT_REGISTERED): e = EDAMErrorCode::USER_NOT_REGISTERED; break; + case static_cast(EDAMErrorCode::USER_ALREADY_ASSOCIATED): e = EDAMErrorCode::USER_ALREADY_ASSOCIATED; break; + case static_cast(EDAMErrorCode::ACCOUNT_CLEAR): e = EDAMErrorCode::ACCOUNT_CLEAR; break; + case static_cast(EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED): e = EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum EDAMErrorCode")); + } +} + +void readEnumEDAMInvalidContactReason( + ThriftBinaryBufferReader & reader, + EDAMInvalidContactReason & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(EDAMInvalidContactReason::BAD_ADDRESS): e = EDAMInvalidContactReason::BAD_ADDRESS; break; + case static_cast(EDAMInvalidContactReason::DUPLICATE_CONTACT): e = EDAMInvalidContactReason::DUPLICATE_CONTACT; break; + case static_cast(EDAMInvalidContactReason::NO_CONNECTION): e = EDAMInvalidContactReason::NO_CONNECTION; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum EDAMInvalidContactReason")); + } +} + +void readEnumShareRelationshipPrivilegeLevel( + ThriftBinaryBufferReader & reader, + ShareRelationshipPrivilegeLevel & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(ShareRelationshipPrivilegeLevel::READ_NOTEBOOK): e = ShareRelationshipPrivilegeLevel::READ_NOTEBOOK; break; + case static_cast(ShareRelationshipPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY): e = ShareRelationshipPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY; break; + case static_cast(ShareRelationshipPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY): e = ShareRelationshipPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY; break; + case static_cast(ShareRelationshipPrivilegeLevel::FULL_ACCESS): e = ShareRelationshipPrivilegeLevel::FULL_ACCESS; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum ShareRelationshipPrivilegeLevel")); + } +} + +void readEnumPrivilegeLevel( + ThriftBinaryBufferReader & reader, + PrivilegeLevel & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(PrivilegeLevel::NORMAL): e = PrivilegeLevel::NORMAL; break; + case static_cast(PrivilegeLevel::PREMIUM): e = PrivilegeLevel::PREMIUM; break; + case static_cast(PrivilegeLevel::VIP): e = PrivilegeLevel::VIP; break; + case static_cast(PrivilegeLevel::MANAGER): e = PrivilegeLevel::MANAGER; break; + case static_cast(PrivilegeLevel::SUPPORT): e = PrivilegeLevel::SUPPORT; break; + case static_cast(PrivilegeLevel::ADMIN): e = PrivilegeLevel::ADMIN; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum PrivilegeLevel")); + } +} + +void readEnumServiceLevel( + ThriftBinaryBufferReader & reader, + ServiceLevel & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(ServiceLevel::BASIC): e = ServiceLevel::BASIC; break; + case static_cast(ServiceLevel::PLUS): e = ServiceLevel::PLUS; break; + case static_cast(ServiceLevel::PREMIUM): e = ServiceLevel::PREMIUM; break; + case static_cast(ServiceLevel::BUSINESS): e = ServiceLevel::BUSINESS; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum ServiceLevel")); + } +} + +void readEnumQueryFormat( + ThriftBinaryBufferReader & reader, + QueryFormat & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(QueryFormat::USER): e = QueryFormat::USER; break; + case static_cast(QueryFormat::SEXP): e = QueryFormat::SEXP; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum QueryFormat")); + } +} + +void readEnumNoteSortOrder( + ThriftBinaryBufferReader & reader, + NoteSortOrder & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(NoteSortOrder::CREATED): e = NoteSortOrder::CREATED; break; + case static_cast(NoteSortOrder::UPDATED): e = NoteSortOrder::UPDATED; break; + case static_cast(NoteSortOrder::RELEVANCE): e = NoteSortOrder::RELEVANCE; break; + case static_cast(NoteSortOrder::UPDATE_SEQUENCE_NUMBER): e = NoteSortOrder::UPDATE_SEQUENCE_NUMBER; break; + case static_cast(NoteSortOrder::TITLE): e = NoteSortOrder::TITLE; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum NoteSortOrder")); + } +} + +void readEnumPremiumOrderStatus( + ThriftBinaryBufferReader & reader, + PremiumOrderStatus & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(PremiumOrderStatus::NONE): e = PremiumOrderStatus::NONE; break; + case static_cast(PremiumOrderStatus::PENDING): e = PremiumOrderStatus::PENDING; break; + case static_cast(PremiumOrderStatus::ACTIVE): e = PremiumOrderStatus::ACTIVE; break; + case static_cast(PremiumOrderStatus::FAILED): e = PremiumOrderStatus::FAILED; break; + case static_cast(PremiumOrderStatus::CANCELLATION_PENDING): e = PremiumOrderStatus::CANCELLATION_PENDING; break; + case static_cast(PremiumOrderStatus::CANCELED): e = PremiumOrderStatus::CANCELED; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum PremiumOrderStatus")); + } +} + +void readEnumSharedNotebookPrivilegeLevel( + ThriftBinaryBufferReader & reader, + SharedNotebookPrivilegeLevel & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(SharedNotebookPrivilegeLevel::READ_NOTEBOOK): e = SharedNotebookPrivilegeLevel::READ_NOTEBOOK; break; + case static_cast(SharedNotebookPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY): e = SharedNotebookPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY; break; + case static_cast(SharedNotebookPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY): e = SharedNotebookPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY; break; + case static_cast(SharedNotebookPrivilegeLevel::GROUP): e = SharedNotebookPrivilegeLevel::GROUP; break; + case static_cast(SharedNotebookPrivilegeLevel::FULL_ACCESS): e = SharedNotebookPrivilegeLevel::FULL_ACCESS; break; + case static_cast(SharedNotebookPrivilegeLevel::BUSINESS_FULL_ACCESS): e = SharedNotebookPrivilegeLevel::BUSINESS_FULL_ACCESS; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum SharedNotebookPrivilegeLevel")); + } +} + +void readEnumSharedNotePrivilegeLevel( + ThriftBinaryBufferReader & reader, + SharedNotePrivilegeLevel & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(SharedNotePrivilegeLevel::READ_NOTE): e = SharedNotePrivilegeLevel::READ_NOTE; break; + case static_cast(SharedNotePrivilegeLevel::MODIFY_NOTE): e = SharedNotePrivilegeLevel::MODIFY_NOTE; break; + case static_cast(SharedNotePrivilegeLevel::FULL_ACCESS): e = SharedNotePrivilegeLevel::FULL_ACCESS; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum SharedNotePrivilegeLevel")); + } +} + +void readEnumSponsoredGroupRole( + ThriftBinaryBufferReader & reader, + SponsoredGroupRole & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(SponsoredGroupRole::GROUP_MEMBER): e = SponsoredGroupRole::GROUP_MEMBER; break; + case static_cast(SponsoredGroupRole::GROUP_ADMIN): e = SponsoredGroupRole::GROUP_ADMIN; break; + case static_cast(SponsoredGroupRole::GROUP_OWNER): e = SponsoredGroupRole::GROUP_OWNER; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum SponsoredGroupRole")); + } +} + +void readEnumBusinessUserRole( + ThriftBinaryBufferReader & reader, + BusinessUserRole & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(BusinessUserRole::ADMIN): e = BusinessUserRole::ADMIN; break; + case static_cast(BusinessUserRole::NORMAL): e = BusinessUserRole::NORMAL; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum BusinessUserRole")); + } +} + +void readEnumBusinessUserStatus( + ThriftBinaryBufferReader & reader, + BusinessUserStatus & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(BusinessUserStatus::ACTIVE): e = BusinessUserStatus::ACTIVE; break; + case static_cast(BusinessUserStatus::DEACTIVATED): e = BusinessUserStatus::DEACTIVATED; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum BusinessUserStatus")); + } +} + +void readEnumSharedNotebookInstanceRestrictions( + ThriftBinaryBufferReader & reader, + SharedNotebookInstanceRestrictions & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(SharedNotebookInstanceRestrictions::ASSIGNED): e = SharedNotebookInstanceRestrictions::ASSIGNED; break; + case static_cast(SharedNotebookInstanceRestrictions::NO_SHARED_NOTEBOOKS): e = SharedNotebookInstanceRestrictions::NO_SHARED_NOTEBOOKS; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum SharedNotebookInstanceRestrictions")); + } +} + +void readEnumReminderEmailConfig( + ThriftBinaryBufferReader & reader, + ReminderEmailConfig & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(ReminderEmailConfig::DO_NOT_SEND): e = ReminderEmailConfig::DO_NOT_SEND; break; + case static_cast(ReminderEmailConfig::SEND_DAILY_EMAIL): e = ReminderEmailConfig::SEND_DAILY_EMAIL; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum ReminderEmailConfig")); + } +} + +void readEnumBusinessInvitationStatus( + ThriftBinaryBufferReader & reader, + BusinessInvitationStatus & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(BusinessInvitationStatus::APPROVED): e = BusinessInvitationStatus::APPROVED; break; + case static_cast(BusinessInvitationStatus::REQUESTED): e = BusinessInvitationStatus::REQUESTED; break; + case static_cast(BusinessInvitationStatus::REDEEMED): e = BusinessInvitationStatus::REDEEMED; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum BusinessInvitationStatus")); + } +} + +void readEnumContactType( + ThriftBinaryBufferReader & reader, + ContactType & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(ContactType::EVERNOTE): e = ContactType::EVERNOTE; break; + case static_cast(ContactType::SMS): e = ContactType::SMS; break; + case static_cast(ContactType::FACEBOOK): e = ContactType::FACEBOOK; break; + case static_cast(ContactType::EMAIL): e = ContactType::EMAIL; break; + case static_cast(ContactType::TWITTER): e = ContactType::TWITTER; break; + case static_cast(ContactType::LINKEDIN): e = ContactType::LINKEDIN; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum ContactType")); + } +} + +void readEnumEntityType( + ThriftBinaryBufferReader & reader, + EntityType & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(EntityType::NOTE): e = EntityType::NOTE; break; + case static_cast(EntityType::NOTEBOOK): e = EntityType::NOTEBOOK; break; + case static_cast(EntityType::WORKSPACE): e = EntityType::WORKSPACE; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum EntityType")); + } +} + +void readEnumRecipientStatus( + ThriftBinaryBufferReader & reader, + RecipientStatus & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(RecipientStatus::NOT_IN_MY_LIST): e = RecipientStatus::NOT_IN_MY_LIST; break; + case static_cast(RecipientStatus::IN_MY_LIST): e = RecipientStatus::IN_MY_LIST; break; + case static_cast(RecipientStatus::IN_MY_LIST_AND_DEFAULT_NOTEBOOK): e = RecipientStatus::IN_MY_LIST_AND_DEFAULT_NOTEBOOK; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum RecipientStatus")); + } +} + +void readEnumCanMoveToContainerStatus( + ThriftBinaryBufferReader & reader, + CanMoveToContainerStatus & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(CanMoveToContainerStatus::CAN_BE_MOVED): e = CanMoveToContainerStatus::CAN_BE_MOVED; break; + case static_cast(CanMoveToContainerStatus::INSUFFICIENT_ENTITY_PRIVILEGE): e = CanMoveToContainerStatus::INSUFFICIENT_ENTITY_PRIVILEGE; break; + case static_cast(CanMoveToContainerStatus::INSUFFICIENT_CONTAINER_PRIVILEGE): e = CanMoveToContainerStatus::INSUFFICIENT_CONTAINER_PRIVILEGE; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum CanMoveToContainerStatus")); + } +} + +void readEnumRelatedContentType( + ThriftBinaryBufferReader & reader, + RelatedContentType & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(RelatedContentType::NEWS_ARTICLE): e = RelatedContentType::NEWS_ARTICLE; break; + case static_cast(RelatedContentType::PROFILE_PERSON): e = RelatedContentType::PROFILE_PERSON; break; + case static_cast(RelatedContentType::PROFILE_ORGANIZATION): e = RelatedContentType::PROFILE_ORGANIZATION; break; + case static_cast(RelatedContentType::REFERENCE_MATERIAL): e = RelatedContentType::REFERENCE_MATERIAL; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum RelatedContentType")); + } +} + +void readEnumRelatedContentAccess( + ThriftBinaryBufferReader & reader, + RelatedContentAccess & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(RelatedContentAccess::NOT_ACCESSIBLE): e = RelatedContentAccess::NOT_ACCESSIBLE; break; + case static_cast(RelatedContentAccess::DIRECT_LINK_ACCESS_OK): e = RelatedContentAccess::DIRECT_LINK_ACCESS_OK; break; + case static_cast(RelatedContentAccess::DIRECT_LINK_LOGIN_REQUIRED): e = RelatedContentAccess::DIRECT_LINK_LOGIN_REQUIRED; break; + case static_cast(RelatedContentAccess::DIRECT_LINK_EMBEDDED_VIEW): e = RelatedContentAccess::DIRECT_LINK_EMBEDDED_VIEW; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum RelatedContentAccess")); + } +} + +void readEnumUserIdentityType( + ThriftBinaryBufferReader & reader, + UserIdentityType & e) +{ + qint32 i; + reader.readI32(i); + switch(i) { + case static_cast(UserIdentityType::EVERNOTE_USERID): e = UserIdentityType::EVERNOTE_USERID; break; + case static_cast(UserIdentityType::EMAIL): e = UserIdentityType::EMAIL; break; + case static_cast(UserIdentityType::IDENTITYID): e = UserIdentityType::IDENTITYID; break; + default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum UserIdentityType")); + } +} + +EverCloudLocalData::EverCloudLocalData() +{ + id = QUuid::createUuid().toString(); + // Remove curvy braces + id.remove(id.size() - 1, 1); + id.remove(0, 1); +} + +EverCloudLocalData::~EverCloudLocalData() noexcept +{} + +void EverCloudLocalData::print(QTextStream & strm) const +{ + strm << " localData.id = " << id << "\n" + << " localData.dirty = " << (dirty ? "true" : "false") << "\n" + << " localData.local = " << (local ? "true" : "false") << "\n" + << " localData.favorited = " << (favorited ? "true" : "false") << "\n"; + + if (!dict.isEmpty()) + { + strm << " localData.dict:" << "\n"; + QString valueStr; + for(const auto & it: toRange(dict)) { + strm << " [" << it.key() << "] = "; + valueStr.resize(0); + QDebug dbg(&valueStr); + dbg.noquote(); + dbg.nospace(); + dbg << it.value(); + strm << valueStr << "\n"; + } + } +} + +bool EverCloudLocalData::operator==( + const EverCloudLocalData & other) const +{ + return id == other.id && dirty == other.dirty && + local == other.local && favorited == other.favorited && + dict == other.dict; +} + +bool EverCloudLocalData::operator!=( + const EverCloudLocalData & other) const +{ + return !operator==(other); +} + +void writeSyncState( + ThriftBinaryBufferWriter & writer, + const SyncState & s) +{ + writer.writeStructBegin(QStringLiteral("SyncState")); + writer.writeFieldBegin( + QStringLiteral("currentTime"), + ThriftFieldType::T_I64, + 1); + + writer.writeI64(s.currentTime); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("fullSyncBefore"), + ThriftFieldType::T_I64, + 2); + + writer.writeI64(s.fullSyncBefore); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("updateCount"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(s.updateCount); + writer.writeFieldEnd(); + + if (s.uploaded.isSet()) { + writer.writeFieldBegin( + QStringLiteral("uploaded"), + ThriftFieldType::T_I64, + 4); + + writer.writeI64(s.uploaded.ref()); + writer.writeFieldEnd(); + } + + if (s.userLastUpdated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userLastUpdated"), + ThriftFieldType::T_I64, + 5); + + writer.writeI64(s.userLastUpdated.ref()); + writer.writeFieldEnd(); + } + + if (s.userMaxMessageEventId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userMaxMessageEventId"), + ThriftFieldType::T_I64, + 6); + + writer.writeI64(s.userMaxMessageEventId.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readSyncState( + ThriftBinaryBufferReader & reader, + SyncState & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool currentTime_isset = false; + bool fullSyncBefore_isset = false; + bool updateCount_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I64) { + currentTime_isset = true; + qint64 v; + reader.readI64(v); + s.currentTime = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I64) { + fullSyncBefore_isset = true; + qint64 v; + reader.readI64(v); + s.fullSyncBefore = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + updateCount_isset = true; + qint32 v; + reader.readI32(v); + s.updateCount = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.uploaded = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.userLastUpdated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_I64) { + MessageEventID v; + reader.readI64(v); + s.userMaxMessageEventId = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!currentTime_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("SyncState.currentTime has no value")); + if (!fullSyncBefore_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("SyncState.fullSyncBefore has no value")); + if (!updateCount_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("SyncState.updateCount has no value")); +} + +void SyncState::print(QTextStream & strm) const +{ + strm << "SyncState: {\n"; + localData.print(strm); + strm << " currentTime = " + << currentTime << "\n"; + strm << " fullSyncBefore = " + << fullSyncBefore << "\n"; + strm << " updateCount = " + << updateCount << "\n"; + + if (uploaded.isSet()) { + strm << " uploaded = " + << uploaded.ref() << "\n"; + } + else { + strm << " uploaded is not set\n"; + } + + if (userLastUpdated.isSet()) { + strm << " userLastUpdated = " + << userLastUpdated.ref() << "\n"; + } + else { + strm << " userLastUpdated is not set\n"; + } + + if (userMaxMessageEventId.isSet()) { + strm << " userMaxMessageEventId = " + << userMaxMessageEventId.ref() << "\n"; + } + else { + strm << " userMaxMessageEventId is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeSyncChunk( + ThriftBinaryBufferWriter & writer, + const SyncChunk & s) +{ + writer.writeStructBegin(QStringLiteral("SyncChunk")); + writer.writeFieldBegin( + QStringLiteral("currentTime"), + ThriftFieldType::T_I64, + 1); + + writer.writeI64(s.currentTime); + writer.writeFieldEnd(); + + if (s.chunkHighUSN.isSet()) { + writer.writeFieldBegin( + QStringLiteral("chunkHighUSN"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(s.chunkHighUSN.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldBegin( + QStringLiteral("updateCount"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(s.updateCount); + writer.writeFieldEnd(); + + if (s.notes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notes"), + ThriftFieldType::T_LIST, + 4); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.notes.ref().length()); + for(const auto & value: qAsConst(s.notes.ref())) { + writeNote(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.notebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebooks"), + ThriftFieldType::T_LIST, + 5); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.notebooks.ref().length()); + for(const auto & value: qAsConst(s.notebooks.ref())) { + writeNotebook(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.tags.isSet()) { + writer.writeFieldBegin( + QStringLiteral("tags"), + ThriftFieldType::T_LIST, + 6); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.tags.ref().length()); + for(const auto & value: qAsConst(s.tags.ref())) { + writeTag(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.searches.isSet()) { + writer.writeFieldBegin( + QStringLiteral("searches"), + ThriftFieldType::T_LIST, + 7); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.searches.ref().length()); + for(const auto & value: qAsConst(s.searches.ref())) { + writeSavedSearch(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.resources.isSet()) { + writer.writeFieldBegin( + QStringLiteral("resources"), + ThriftFieldType::T_LIST, + 8); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.resources.ref().length()); + for(const auto & value: qAsConst(s.resources.ref())) { + writeResource(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.expungedNotes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("expungedNotes"), + ThriftFieldType::T_LIST, + 9); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.expungedNotes.ref().length()); + for(const auto & value: qAsConst(s.expungedNotes.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.expungedNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("expungedNotebooks"), + ThriftFieldType::T_LIST, + 10); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.expungedNotebooks.ref().length()); + for(const auto & value: qAsConst(s.expungedNotebooks.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.expungedTags.isSet()) { + writer.writeFieldBegin( + QStringLiteral("expungedTags"), + ThriftFieldType::T_LIST, + 11); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.expungedTags.ref().length()); + for(const auto & value: qAsConst(s.expungedTags.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.expungedSearches.isSet()) { + writer.writeFieldBegin( + QStringLiteral("expungedSearches"), + ThriftFieldType::T_LIST, + 12); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.expungedSearches.ref().length()); + for(const auto & value: qAsConst(s.expungedSearches.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.linkedNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("linkedNotebooks"), + ThriftFieldType::T_LIST, + 13); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.linkedNotebooks.ref().length()); + for(const auto & value: qAsConst(s.linkedNotebooks.ref())) { + writeLinkedNotebook(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.expungedLinkedNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("expungedLinkedNotebooks"), + ThriftFieldType::T_LIST, + 14); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.expungedLinkedNotebooks.ref().length()); + for(const auto & value: qAsConst(s.expungedLinkedNotebooks.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readSyncChunk( + ThriftBinaryBufferReader & reader, + SyncChunk & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool currentTime_isset = false; + bool updateCount_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I64) { + currentTime_isset = true; + qint64 v; + reader.readI64(v); + s.currentTime = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.chunkHighUSN = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + updateCount_isset = true; + qint32 v; + reader.readI32(v); + s.updateCount = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (SyncChunk.notes)")); + } + for(qint32 i = 0; i < size; i++) { + Note elem; + readNote(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.notes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (SyncChunk.notebooks)")); + } + for(qint32 i = 0; i < size; i++) { + Notebook elem; + readNotebook(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.notebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (SyncChunk.tags)")); + } + for(qint32 i = 0; i < size; i++) { + Tag elem; + readTag(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.tags = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (SyncChunk.searches)")); + } + for(qint32 i = 0; i < size; i++) { + SavedSearch elem; + readSavedSearch(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.searches = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (SyncChunk.resources)")); + } + for(qint32 i = 0; i < size; i++) { + Resource elem; + readResource(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.resources = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (SyncChunk.expungedNotes)")); + } + for(qint32 i = 0; i < size; i++) { + Guid elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.expungedNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (SyncChunk.expungedNotebooks)")); + } + for(qint32 i = 0; i < size; i++) { + Guid elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.expungedNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (SyncChunk.expungedTags)")); + } + for(qint32 i = 0; i < size; i++) { + Guid elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.expungedTags = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (SyncChunk.expungedSearches)")); + } + for(qint32 i = 0; i < size; i++) { + Guid elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.expungedSearches = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (SyncChunk.linkedNotebooks)")); + } + for(qint32 i = 0; i < size; i++) { + LinkedNotebook elem; + readLinkedNotebook(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.linkedNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 14) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (SyncChunk.expungedLinkedNotebooks)")); + } + for(qint32 i = 0; i < size; i++) { + Guid elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.expungedLinkedNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!currentTime_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("SyncChunk.currentTime has no value")); + if (!updateCount_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("SyncChunk.updateCount has no value")); +} + +void SyncChunk::print(QTextStream & strm) const +{ + strm << "SyncChunk: {\n"; + localData.print(strm); + strm << " currentTime = " + << currentTime << "\n"; + + if (chunkHighUSN.isSet()) { + strm << " chunkHighUSN = " + << chunkHighUSN.ref() << "\n"; + } + else { + strm << " chunkHighUSN is not set\n"; + } + + strm << " updateCount = " + << updateCount << "\n"; + + if (notes.isSet()) { + strm << " notes = " + << "QList {"; + for(const auto & v: notes.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " notes is not set\n"; + } + + if (notebooks.isSet()) { + strm << " notebooks = " + << "QList {"; + for(const auto & v: notebooks.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " notebooks is not set\n"; + } + + if (tags.isSet()) { + strm << " tags = " + << "QList {"; + for(const auto & v: tags.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " tags is not set\n"; + } + + if (searches.isSet()) { + strm << " searches = " + << "QList {"; + for(const auto & v: searches.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " searches is not set\n"; + } + + if (resources.isSet()) { + strm << " resources = " + << "QList {"; + for(const auto & v: resources.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " resources is not set\n"; + } + + if (expungedNotes.isSet()) { + strm << " expungedNotes = " + << "QList {"; + for(const auto & v: expungedNotes.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " expungedNotes is not set\n"; + } + + if (expungedNotebooks.isSet()) { + strm << " expungedNotebooks = " + << "QList {"; + for(const auto & v: expungedNotebooks.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " expungedNotebooks is not set\n"; + } + + if (expungedTags.isSet()) { + strm << " expungedTags = " + << "QList {"; + for(const auto & v: expungedTags.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " expungedTags is not set\n"; + } + + if (expungedSearches.isSet()) { + strm << " expungedSearches = " + << "QList {"; + for(const auto & v: expungedSearches.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " expungedSearches is not set\n"; + } + + if (linkedNotebooks.isSet()) { + strm << " linkedNotebooks = " + << "QList {"; + for(const auto & v: linkedNotebooks.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " linkedNotebooks is not set\n"; + } + + if (expungedLinkedNotebooks.isSet()) { + strm << " expungedLinkedNotebooks = " + << "QList {"; + for(const auto & v: expungedLinkedNotebooks.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " expungedLinkedNotebooks is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeSyncChunkFilter( + ThriftBinaryBufferWriter & writer, + const SyncChunkFilter & s) +{ + writer.writeStructBegin(QStringLiteral("SyncChunkFilter")); + if (s.includeNotes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeNotes"), + ThriftFieldType::T_BOOL, + 1); + + writer.writeBool(s.includeNotes.ref()); + writer.writeFieldEnd(); + } + + if (s.includeNoteResources.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeNoteResources"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(s.includeNoteResources.ref()); + writer.writeFieldEnd(); + } + + if (s.includeNoteAttributes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeNoteAttributes"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(s.includeNoteAttributes.ref()); + writer.writeFieldEnd(); + } + + if (s.includeNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeNotebooks"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(s.includeNotebooks.ref()); + writer.writeFieldEnd(); + } + + if (s.includeTags.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeTags"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(s.includeTags.ref()); + writer.writeFieldEnd(); + } + + if (s.includeSearches.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeSearches"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(s.includeSearches.ref()); + writer.writeFieldEnd(); + } + + if (s.includeResources.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeResources"), + ThriftFieldType::T_BOOL, + 7); + + writer.writeBool(s.includeResources.ref()); + writer.writeFieldEnd(); + } + + if (s.includeLinkedNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeLinkedNotebooks"), + ThriftFieldType::T_BOOL, + 8); + + writer.writeBool(s.includeLinkedNotebooks.ref()); + writer.writeFieldEnd(); + } + + if (s.includeExpunged.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeExpunged"), + ThriftFieldType::T_BOOL, + 9); + + writer.writeBool(s.includeExpunged.ref()); + writer.writeFieldEnd(); + } + + if (s.includeNoteApplicationDataFullMap.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeNoteApplicationDataFullMap"), + ThriftFieldType::T_BOOL, + 10); + + writer.writeBool(s.includeNoteApplicationDataFullMap.ref()); + writer.writeFieldEnd(); + } + + if (s.includeResourceApplicationDataFullMap.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeResourceApplicationDataFullMap"), + ThriftFieldType::T_BOOL, + 12); + + writer.writeBool(s.includeResourceApplicationDataFullMap.ref()); + writer.writeFieldEnd(); + } + + if (s.includeNoteResourceApplicationDataFullMap.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeNoteResourceApplicationDataFullMap"), + ThriftFieldType::T_BOOL, + 13); + + writer.writeBool(s.includeNoteResourceApplicationDataFullMap.ref()); + writer.writeFieldEnd(); + } + + if (s.includeSharedNotes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeSharedNotes"), + ThriftFieldType::T_BOOL, + 17); + + writer.writeBool(s.includeSharedNotes.ref()); + writer.writeFieldEnd(); + } + + if (s.omitSharedNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("omitSharedNotebooks"), + ThriftFieldType::T_BOOL, + 16); + + writer.writeBool(s.omitSharedNotebooks.ref()); + writer.writeFieldEnd(); + } + + if (s.requireNoteContentClass.isSet()) { + writer.writeFieldBegin( + QStringLiteral("requireNoteContentClass"), + ThriftFieldType::T_STRING, + 11); + + writer.writeString(s.requireNoteContentClass.ref()); + writer.writeFieldEnd(); + } + + if (s.notebookGuids.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebookGuids"), + ThriftFieldType::T_SET, + 15); + + writer.writeSetBegin(ThriftFieldType::T_STRING, s.notebookGuids.ref().count()); + for(const auto & value: qAsConst(s.notebookGuids.ref())) { + writer.writeString(value); + } + writer.writeSetEnd(); + + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readSyncChunkFilter( + ThriftBinaryBufferReader & reader, + SyncChunkFilter & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeNoteResources = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeNoteAttributes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeTags = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeSearches = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeResources = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeLinkedNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeExpunged = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeNoteApplicationDataFullMap = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeResourceApplicationDataFullMap = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeNoteResourceApplicationDataFullMap = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 17) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeSharedNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 16) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.omitSharedNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.requireNoteContentClass = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 15) { + if (fieldType == ThriftFieldType::T_SET) { + QSet v; + qint32 size; + ThriftFieldType elemType; + reader.readSetBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect set type (SyncChunkFilter.notebookGuids)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.insert(elem); + } + reader.readSetEnd(); + s.notebookGuids = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void SyncChunkFilter::print(QTextStream & strm) const +{ + strm << "SyncChunkFilter: {\n"; + localData.print(strm); + + if (includeNotes.isSet()) { + strm << " includeNotes = " + << includeNotes.ref() << "\n"; + } + else { + strm << " includeNotes is not set\n"; + } + + if (includeNoteResources.isSet()) { + strm << " includeNoteResources = " + << includeNoteResources.ref() << "\n"; + } + else { + strm << " includeNoteResources is not set\n"; + } + + if (includeNoteAttributes.isSet()) { + strm << " includeNoteAttributes = " + << includeNoteAttributes.ref() << "\n"; + } + else { + strm << " includeNoteAttributes is not set\n"; + } + + if (includeNotebooks.isSet()) { + strm << " includeNotebooks = " + << includeNotebooks.ref() << "\n"; + } + else { + strm << " includeNotebooks is not set\n"; + } + + if (includeTags.isSet()) { + strm << " includeTags = " + << includeTags.ref() << "\n"; + } + else { + strm << " includeTags is not set\n"; + } + + if (includeSearches.isSet()) { + strm << " includeSearches = " + << includeSearches.ref() << "\n"; + } + else { + strm << " includeSearches is not set\n"; + } + + if (includeResources.isSet()) { + strm << " includeResources = " + << includeResources.ref() << "\n"; + } + else { + strm << " includeResources is not set\n"; + } + + if (includeLinkedNotebooks.isSet()) { + strm << " includeLinkedNotebooks = " + << includeLinkedNotebooks.ref() << "\n"; + } + else { + strm << " includeLinkedNotebooks is not set\n"; + } + + if (includeExpunged.isSet()) { + strm << " includeExpunged = " + << includeExpunged.ref() << "\n"; + } + else { + strm << " includeExpunged is not set\n"; + } + + if (includeNoteApplicationDataFullMap.isSet()) { + strm << " includeNoteApplicationDataFullMap = " + << includeNoteApplicationDataFullMap.ref() << "\n"; + } + else { + strm << " includeNoteApplicationDataFullMap is not set\n"; + } + + if (includeResourceApplicationDataFullMap.isSet()) { + strm << " includeResourceApplicationDataFullMap = " + << includeResourceApplicationDataFullMap.ref() << "\n"; + } + else { + strm << " includeResourceApplicationDataFullMap is not set\n"; + } + + if (includeNoteResourceApplicationDataFullMap.isSet()) { + strm << " includeNoteResourceApplicationDataFullMap = " + << includeNoteResourceApplicationDataFullMap.ref() << "\n"; + } + else { + strm << " includeNoteResourceApplicationDataFullMap is not set\n"; + } + + if (includeSharedNotes.isSet()) { + strm << " includeSharedNotes = " + << includeSharedNotes.ref() << "\n"; + } + else { + strm << " includeSharedNotes is not set\n"; + } + + if (omitSharedNotebooks.isSet()) { + strm << " omitSharedNotebooks = " + << omitSharedNotebooks.ref() << "\n"; + } + else { + strm << " omitSharedNotebooks is not set\n"; + } + + if (requireNoteContentClass.isSet()) { + strm << " requireNoteContentClass = " + << requireNoteContentClass.ref() << "\n"; + } + else { + strm << " requireNoteContentClass is not set\n"; + } + + if (notebookGuids.isSet()) { + strm << " notebookGuids = " + << "QSet {"; + for(const auto & v: notebookGuids.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " notebookGuids is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteFilter( + ThriftBinaryBufferWriter & writer, + const NoteFilter & s) +{ + writer.writeStructBegin(QStringLiteral("NoteFilter")); + if (s.order.isSet()) { + writer.writeFieldBegin( + QStringLiteral("order"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.order.ref()); + writer.writeFieldEnd(); + } + + if (s.ascending.isSet()) { + writer.writeFieldBegin( + QStringLiteral("ascending"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(s.ascending.ref()); + writer.writeFieldEnd(); + } + + if (s.words.isSet()) { + writer.writeFieldBegin( + QStringLiteral("words"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.words.ref()); + writer.writeFieldEnd(); + } + + if (s.notebookGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebookGuid"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.notebookGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.tagGuids.isSet()) { + writer.writeFieldBegin( + QStringLiteral("tagGuids"), + ThriftFieldType::T_LIST, + 5); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.tagGuids.ref().length()); + for(const auto & value: qAsConst(s.tagGuids.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.timeZone.isSet()) { + writer.writeFieldBegin( + QStringLiteral("timeZone"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.timeZone.ref()); + writer.writeFieldEnd(); + } + + if (s.inactive.isSet()) { + writer.writeFieldBegin( + QStringLiteral("inactive"), + ThriftFieldType::T_BOOL, + 7); + + writer.writeBool(s.inactive.ref()); + writer.writeFieldEnd(); + } + + if (s.emphasized.isSet()) { + writer.writeFieldBegin( + QStringLiteral("emphasized"), + ThriftFieldType::T_STRING, + 8); + + writer.writeString(s.emphasized.ref()); + writer.writeFieldEnd(); + } + + if (s.includeAllReadableNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeAllReadableNotebooks"), + ThriftFieldType::T_BOOL, + 9); + + writer.writeBool(s.includeAllReadableNotebooks.ref()); + writer.writeFieldEnd(); + } + + if (s.includeAllReadableWorkspaces.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeAllReadableWorkspaces"), + ThriftFieldType::T_BOOL, + 15); + + writer.writeBool(s.includeAllReadableWorkspaces.ref()); + writer.writeFieldEnd(); + } + + if (s.context.isSet()) { + writer.writeFieldBegin( + QStringLiteral("context"), + ThriftFieldType::T_STRING, + 10); + + writer.writeString(s.context.ref()); + writer.writeFieldEnd(); + } + + if (s.rawWords.isSet()) { + writer.writeFieldBegin( + QStringLiteral("rawWords"), + ThriftFieldType::T_STRING, + 11); + + writer.writeString(s.rawWords.ref()); + writer.writeFieldEnd(); + } + + if (s.searchContextBytes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("searchContextBytes"), + ThriftFieldType::T_STRING, + 12); + + writer.writeBinary(s.searchContextBytes.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteFilter( + ThriftBinaryBufferReader & reader, + NoteFilter & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.order = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.ascending = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.words = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.notebookGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NoteFilter.tagGuids)")); + } + for(qint32 i = 0; i < size; i++) { + Guid elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.tagGuids = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.timeZone = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.inactive = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.emphasized = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeAllReadableNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 15) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeAllReadableWorkspaces = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.context = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.rawWords = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_STRING) { + QByteArray v; + reader.readBinary(v); + s.searchContextBytes = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NoteFilter::print(QTextStream & strm) const +{ + strm << "NoteFilter: {\n"; + localData.print(strm); + + if (order.isSet()) { + strm << " order = " + << order.ref() << "\n"; + } + else { + strm << " order is not set\n"; + } + + if (ascending.isSet()) { + strm << " ascending = " + << ascending.ref() << "\n"; + } + else { + strm << " ascending is not set\n"; + } + + if (words.isSet()) { + strm << " words = " + << words.ref() << "\n"; + } + else { + strm << " words is not set\n"; + } + + if (notebookGuid.isSet()) { + strm << " notebookGuid = " + << notebookGuid.ref() << "\n"; + } + else { + strm << " notebookGuid is not set\n"; + } + + if (tagGuids.isSet()) { + strm << " tagGuids = " + << "QList {"; + for(const auto & v: tagGuids.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " tagGuids is not set\n"; + } + + if (timeZone.isSet()) { + strm << " timeZone = " + << timeZone.ref() << "\n"; + } + else { + strm << " timeZone is not set\n"; + } + + if (inactive.isSet()) { + strm << " inactive = " + << inactive.ref() << "\n"; + } + else { + strm << " inactive is not set\n"; + } + + if (emphasized.isSet()) { + strm << " emphasized = " + << emphasized.ref() << "\n"; + } + else { + strm << " emphasized is not set\n"; + } + + if (includeAllReadableNotebooks.isSet()) { + strm << " includeAllReadableNotebooks = " + << includeAllReadableNotebooks.ref() << "\n"; + } + else { + strm << " includeAllReadableNotebooks is not set\n"; + } + + if (includeAllReadableWorkspaces.isSet()) { + strm << " includeAllReadableWorkspaces = " + << includeAllReadableWorkspaces.ref() << "\n"; + } + else { + strm << " includeAllReadableWorkspaces is not set\n"; + } + + if (context.isSet()) { + strm << " context = " + << context.ref() << "\n"; + } + else { + strm << " context is not set\n"; + } + + if (rawWords.isSet()) { + strm << " rawWords = " + << rawWords.ref() << "\n"; + } + else { + strm << " rawWords is not set\n"; + } + + if (searchContextBytes.isSet()) { + strm << " searchContextBytes = " + << searchContextBytes.ref() << "\n"; + } + else { + strm << " searchContextBytes is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteList( + ThriftBinaryBufferWriter & writer, + const NoteList & s) +{ + writer.writeStructBegin(QStringLiteral("NoteList")); + writer.writeFieldBegin( + QStringLiteral("startIndex"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.startIndex); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("totalNotes"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(s.totalNotes); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("notes"), + ThriftFieldType::T_LIST, + 3); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.notes.length()); + for(const auto & value: qAsConst(s.notes)) { + writeNote(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + + if (s.stoppedWords.isSet()) { + writer.writeFieldBegin( + QStringLiteral("stoppedWords"), + ThriftFieldType::T_LIST, + 4); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.stoppedWords.ref().length()); + for(const auto & value: qAsConst(s.stoppedWords.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.searchedWords.isSet()) { + writer.writeFieldBegin( + QStringLiteral("searchedWords"), + ThriftFieldType::T_LIST, + 5); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.searchedWords.ref().length()); + for(const auto & value: qAsConst(s.searchedWords.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.updateCount.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updateCount"), + ThriftFieldType::T_I32, + 6); + + writer.writeI32(s.updateCount.ref()); + writer.writeFieldEnd(); + } + + if (s.searchContextBytes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("searchContextBytes"), + ThriftFieldType::T_STRING, + 7); + + writer.writeBinary(s.searchContextBytes.ref()); + writer.writeFieldEnd(); + } + + if (s.debugInfo.isSet()) { + writer.writeFieldBegin( + QStringLiteral("debugInfo"), + ThriftFieldType::T_STRING, + 8); + + writer.writeString(s.debugInfo.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteList( + ThriftBinaryBufferReader & reader, + NoteList & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool startIndex_isset = false; + bool totalNotes_isset = false; + bool notes_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + startIndex_isset = true; + qint32 v; + reader.readI32(v); + s.startIndex = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I32) { + totalNotes_isset = true; + qint32 v; + reader.readI32(v); + s.totalNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_LIST) { + notes_isset = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NoteList.notes)")); + } + for(qint32 i = 0; i < size; i++) { + Note elem; + readNote(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.notes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_LIST) { + QStringList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NoteList.stoppedWords)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.stoppedWords = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_LIST) { + QStringList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NoteList.searchedWords)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.searchedWords = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.updateCount = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_STRING) { + QByteArray v; + reader.readBinary(v); + s.searchContextBytes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.debugInfo = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!startIndex_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteList.startIndex has no value")); + if (!totalNotes_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteList.totalNotes has no value")); + if (!notes_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteList.notes has no value")); +} + +void NoteList::print(QTextStream & strm) const +{ + strm << "NoteList: {\n"; + localData.print(strm); + strm << " startIndex = " + << startIndex << "\n"; + strm << " totalNotes = " + << totalNotes << "\n"; + strm << " notes = " + << "QList {"; + for(const auto & v: notes) { + strm << " " << v << "\n"; + } + strm << "}\n"; + + if (stoppedWords.isSet()) { + strm << " stoppedWords = " + << "QList {"; + for(const auto & v: stoppedWords.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " stoppedWords is not set\n"; + } + + if (searchedWords.isSet()) { + strm << " searchedWords = " + << "QList {"; + for(const auto & v: searchedWords.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " searchedWords is not set\n"; + } + + if (updateCount.isSet()) { + strm << " updateCount = " + << updateCount.ref() << "\n"; + } + else { + strm << " updateCount is not set\n"; + } + + if (searchContextBytes.isSet()) { + strm << " searchContextBytes = " + << searchContextBytes.ref() << "\n"; + } + else { + strm << " searchContextBytes is not set\n"; + } + + if (debugInfo.isSet()) { + strm << " debugInfo = " + << debugInfo.ref() << "\n"; + } + else { + strm << " debugInfo is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteMetadata( + ThriftBinaryBufferWriter & writer, + const NoteMetadata & s) +{ + writer.writeStructBegin(QStringLiteral("NoteMetadata")); + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.guid); + writer.writeFieldEnd(); + + if (s.title.isSet()) { + writer.writeFieldBegin( + QStringLiteral("title"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.title.ref()); + writer.writeFieldEnd(); + } + + if (s.contentLength.isSet()) { + writer.writeFieldBegin( + QStringLiteral("contentLength"), + ThriftFieldType::T_I32, + 5); + + writer.writeI32(s.contentLength.ref()); + writer.writeFieldEnd(); + } + + if (s.created.isSet()) { + writer.writeFieldBegin( + QStringLiteral("created"), + ThriftFieldType::T_I64, + 6); + + writer.writeI64(s.created.ref()); + writer.writeFieldEnd(); + } + + if (s.updated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updated"), + ThriftFieldType::T_I64, + 7); + + writer.writeI64(s.updated.ref()); + writer.writeFieldEnd(); + } + + if (s.deleted.isSet()) { + writer.writeFieldBegin( + QStringLiteral("deleted"), + ThriftFieldType::T_I64, + 8); + + writer.writeI64(s.deleted.ref()); + writer.writeFieldEnd(); + } + + if (s.updateSequenceNum.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updateSequenceNum"), + ThriftFieldType::T_I32, + 10); + + writer.writeI32(s.updateSequenceNum.ref()); + writer.writeFieldEnd(); + } + + if (s.notebookGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebookGuid"), + ThriftFieldType::T_STRING, + 11); + + writer.writeString(s.notebookGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.tagGuids.isSet()) { + writer.writeFieldBegin( + QStringLiteral("tagGuids"), + ThriftFieldType::T_LIST, + 12); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.tagGuids.ref().length()); + for(const auto & value: qAsConst(s.tagGuids.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.attributes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("attributes"), + ThriftFieldType::T_STRUCT, + 14); + + writeNoteAttributes(writer, s.attributes.ref()); + writer.writeFieldEnd(); + } + + if (s.largestResourceMime.isSet()) { + writer.writeFieldBegin( + QStringLiteral("largestResourceMime"), + ThriftFieldType::T_STRING, + 20); + + writer.writeString(s.largestResourceMime.ref()); + writer.writeFieldEnd(); + } + + if (s.largestResourceSize.isSet()) { + writer.writeFieldBegin( + QStringLiteral("largestResourceSize"), + ThriftFieldType::T_I32, + 21); + + writer.writeI32(s.largestResourceSize.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteMetadata( + ThriftBinaryBufferReader & reader, + NoteMetadata & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool guid_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + guid_isset = true; + Guid v; + reader.readString(v); + s.guid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.title = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.contentLength = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.created = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.updated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.deleted = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.updateSequenceNum = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.notebookGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NoteMetadata.tagGuids)")); + } + for(qint32 i = 0; i < size; i++) { + Guid elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.tagGuids = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 14) { + if (fieldType == ThriftFieldType::T_STRUCT) { + NoteAttributes v; + readNoteAttributes(reader, v); + s.attributes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 20) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.largestResourceMime = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 21) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.largestResourceSize = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!guid_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteMetadata.guid has no value")); +} + +void NoteMetadata::print(QTextStream & strm) const +{ + strm << "NoteMetadata: {\n"; + localData.print(strm); + strm << " guid = " + << guid << "\n"; + + if (title.isSet()) { + strm << " title = " + << title.ref() << "\n"; + } + else { + strm << " title is not set\n"; + } + + if (contentLength.isSet()) { + strm << " contentLength = " + << contentLength.ref() << "\n"; + } + else { + strm << " contentLength is not set\n"; + } + + if (created.isSet()) { + strm << " created = " + << created.ref() << "\n"; + } + else { + strm << " created is not set\n"; + } + + if (updated.isSet()) { + strm << " updated = " + << updated.ref() << "\n"; + } + else { + strm << " updated is not set\n"; + } + + if (deleted.isSet()) { + strm << " deleted = " + << deleted.ref() << "\n"; + } + else { + strm << " deleted is not set\n"; + } + + if (updateSequenceNum.isSet()) { + strm << " updateSequenceNum = " + << updateSequenceNum.ref() << "\n"; + } + else { + strm << " updateSequenceNum is not set\n"; + } + + if (notebookGuid.isSet()) { + strm << " notebookGuid = " + << notebookGuid.ref() << "\n"; + } + else { + strm << " notebookGuid is not set\n"; + } + + if (tagGuids.isSet()) { + strm << " tagGuids = " + << "QList {"; + for(const auto & v: tagGuids.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " tagGuids is not set\n"; + } + + if (attributes.isSet()) { + strm << " attributes = " + << attributes.ref() << "\n"; + } + else { + strm << " attributes is not set\n"; + } + + if (largestResourceMime.isSet()) { + strm << " largestResourceMime = " + << largestResourceMime.ref() << "\n"; + } + else { + strm << " largestResourceMime is not set\n"; + } + + if (largestResourceSize.isSet()) { + strm << " largestResourceSize = " + << largestResourceSize.ref() << "\n"; + } + else { + strm << " largestResourceSize is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNotesMetadataList( + ThriftBinaryBufferWriter & writer, + const NotesMetadataList & s) +{ + writer.writeStructBegin(QStringLiteral("NotesMetadataList")); + writer.writeFieldBegin( + QStringLiteral("startIndex"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.startIndex); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("totalNotes"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(s.totalNotes); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("notes"), + ThriftFieldType::T_LIST, + 3); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.notes.length()); + for(const auto & value: qAsConst(s.notes)) { + writeNoteMetadata(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + + if (s.stoppedWords.isSet()) { + writer.writeFieldBegin( + QStringLiteral("stoppedWords"), + ThriftFieldType::T_LIST, + 4); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.stoppedWords.ref().length()); + for(const auto & value: qAsConst(s.stoppedWords.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.searchedWords.isSet()) { + writer.writeFieldBegin( + QStringLiteral("searchedWords"), + ThriftFieldType::T_LIST, + 5); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.searchedWords.ref().length()); + for(const auto & value: qAsConst(s.searchedWords.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.updateCount.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updateCount"), + ThriftFieldType::T_I32, + 6); + + writer.writeI32(s.updateCount.ref()); + writer.writeFieldEnd(); + } + + if (s.searchContextBytes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("searchContextBytes"), + ThriftFieldType::T_STRING, + 7); + + writer.writeBinary(s.searchContextBytes.ref()); + writer.writeFieldEnd(); + } + + if (s.debugInfo.isSet()) { + writer.writeFieldBegin( + QStringLiteral("debugInfo"), + ThriftFieldType::T_STRING, + 9); + + writer.writeString(s.debugInfo.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNotesMetadataList( + ThriftBinaryBufferReader & reader, + NotesMetadataList & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool startIndex_isset = false; + bool totalNotes_isset = false; + bool notes_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + startIndex_isset = true; + qint32 v; + reader.readI32(v); + s.startIndex = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I32) { + totalNotes_isset = true; + qint32 v; + reader.readI32(v); + s.totalNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_LIST) { + notes_isset = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NotesMetadataList.notes)")); + } + for(qint32 i = 0; i < size; i++) { + NoteMetadata elem; + readNoteMetadata(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.notes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_LIST) { + QStringList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NotesMetadataList.stoppedWords)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.stoppedWords = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_LIST) { + QStringList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NotesMetadataList.searchedWords)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.searchedWords = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.updateCount = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_STRING) { + QByteArray v; + reader.readBinary(v); + s.searchContextBytes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.debugInfo = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!startIndex_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NotesMetadataList.startIndex has no value")); + if (!totalNotes_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NotesMetadataList.totalNotes has no value")); + if (!notes_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NotesMetadataList.notes has no value")); +} + +void NotesMetadataList::print(QTextStream & strm) const +{ + strm << "NotesMetadataList: {\n"; + localData.print(strm); + strm << " startIndex = " + << startIndex << "\n"; + strm << " totalNotes = " + << totalNotes << "\n"; + strm << " notes = " + << "QList {"; + for(const auto & v: notes) { + strm << " " << v << "\n"; + } + strm << "}\n"; + + if (stoppedWords.isSet()) { + strm << " stoppedWords = " + << "QList {"; + for(const auto & v: stoppedWords.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " stoppedWords is not set\n"; + } + + if (searchedWords.isSet()) { + strm << " searchedWords = " + << "QList {"; + for(const auto & v: searchedWords.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " searchedWords is not set\n"; + } + + if (updateCount.isSet()) { + strm << " updateCount = " + << updateCount.ref() << "\n"; + } + else { + strm << " updateCount is not set\n"; + } + + if (searchContextBytes.isSet()) { + strm << " searchContextBytes = " + << searchContextBytes.ref() << "\n"; + } + else { + strm << " searchContextBytes is not set\n"; + } + + if (debugInfo.isSet()) { + strm << " debugInfo = " + << debugInfo.ref() << "\n"; + } + else { + strm << " debugInfo is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNotesMetadataResultSpec( + ThriftBinaryBufferWriter & writer, + const NotesMetadataResultSpec & s) +{ + writer.writeStructBegin(QStringLiteral("NotesMetadataResultSpec")); + if (s.includeTitle.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeTitle"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(s.includeTitle.ref()); + writer.writeFieldEnd(); + } + + if (s.includeContentLength.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeContentLength"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(s.includeContentLength.ref()); + writer.writeFieldEnd(); + } + + if (s.includeCreated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeCreated"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(s.includeCreated.ref()); + writer.writeFieldEnd(); + } + + if (s.includeUpdated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeUpdated"), + ThriftFieldType::T_BOOL, + 7); + + writer.writeBool(s.includeUpdated.ref()); + writer.writeFieldEnd(); + } + + if (s.includeDeleted.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeDeleted"), + ThriftFieldType::T_BOOL, + 8); + + writer.writeBool(s.includeDeleted.ref()); + writer.writeFieldEnd(); + } + + if (s.includeUpdateSequenceNum.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeUpdateSequenceNum"), + ThriftFieldType::T_BOOL, + 10); + + writer.writeBool(s.includeUpdateSequenceNum.ref()); + writer.writeFieldEnd(); + } + + if (s.includeNotebookGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeNotebookGuid"), + ThriftFieldType::T_BOOL, + 11); + + writer.writeBool(s.includeNotebookGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.includeTagGuids.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeTagGuids"), + ThriftFieldType::T_BOOL, + 12); + + writer.writeBool(s.includeTagGuids.ref()); + writer.writeFieldEnd(); + } + + if (s.includeAttributes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeAttributes"), + ThriftFieldType::T_BOOL, + 14); + + writer.writeBool(s.includeAttributes.ref()); + writer.writeFieldEnd(); + } + + if (s.includeLargestResourceMime.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeLargestResourceMime"), + ThriftFieldType::T_BOOL, + 20); + + writer.writeBool(s.includeLargestResourceMime.ref()); + writer.writeFieldEnd(); + } + + if (s.includeLargestResourceSize.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeLargestResourceSize"), + ThriftFieldType::T_BOOL, + 21); + + writer.writeBool(s.includeLargestResourceSize.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNotesMetadataResultSpec( + ThriftBinaryBufferReader & reader, + NotesMetadataResultSpec & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeTitle = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeContentLength = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeCreated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeUpdated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeDeleted = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeUpdateSequenceNum = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeNotebookGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeTagGuids = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 14) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeAttributes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 20) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeLargestResourceMime = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 21) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeLargestResourceSize = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NotesMetadataResultSpec::print(QTextStream & strm) const +{ + strm << "NotesMetadataResultSpec: {\n"; + localData.print(strm); + + if (includeTitle.isSet()) { + strm << " includeTitle = " + << includeTitle.ref() << "\n"; + } + else { + strm << " includeTitle is not set\n"; + } + + if (includeContentLength.isSet()) { + strm << " includeContentLength = " + << includeContentLength.ref() << "\n"; + } + else { + strm << " includeContentLength is not set\n"; + } + + if (includeCreated.isSet()) { + strm << " includeCreated = " + << includeCreated.ref() << "\n"; + } + else { + strm << " includeCreated is not set\n"; + } + + if (includeUpdated.isSet()) { + strm << " includeUpdated = " + << includeUpdated.ref() << "\n"; + } + else { + strm << " includeUpdated is not set\n"; + } + + if (includeDeleted.isSet()) { + strm << " includeDeleted = " + << includeDeleted.ref() << "\n"; + } + else { + strm << " includeDeleted is not set\n"; + } + + if (includeUpdateSequenceNum.isSet()) { + strm << " includeUpdateSequenceNum = " + << includeUpdateSequenceNum.ref() << "\n"; + } + else { + strm << " includeUpdateSequenceNum is not set\n"; + } + + if (includeNotebookGuid.isSet()) { + strm << " includeNotebookGuid = " + << includeNotebookGuid.ref() << "\n"; + } + else { + strm << " includeNotebookGuid is not set\n"; + } + + if (includeTagGuids.isSet()) { + strm << " includeTagGuids = " + << includeTagGuids.ref() << "\n"; + } + else { + strm << " includeTagGuids is not set\n"; + } + + if (includeAttributes.isSet()) { + strm << " includeAttributes = " + << includeAttributes.ref() << "\n"; + } + else { + strm << " includeAttributes is not set\n"; + } + + if (includeLargestResourceMime.isSet()) { + strm << " includeLargestResourceMime = " + << includeLargestResourceMime.ref() << "\n"; + } + else { + strm << " includeLargestResourceMime is not set\n"; + } + + if (includeLargestResourceSize.isSet()) { + strm << " includeLargestResourceSize = " + << includeLargestResourceSize.ref() << "\n"; + } + else { + strm << " includeLargestResourceSize is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteCollectionCounts( + ThriftBinaryBufferWriter & writer, + const NoteCollectionCounts & s) +{ + writer.writeStructBegin(QStringLiteral("NoteCollectionCounts")); + if (s.notebookCounts.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebookCounts"), + ThriftFieldType::T_MAP, + 1); + + writer.writeMapBegin(ThriftFieldType::T_STRING, ThriftFieldType::T_I32, s.notebookCounts.ref().size()); + for(const auto & it: toRange(s.notebookCounts.ref())) { + writer.writeString(it.key()); + writer.writeI32(it.value()); + } + writer.writeMapEnd(); + + writer.writeFieldEnd(); + } + + if (s.tagCounts.isSet()) { + writer.writeFieldBegin( + QStringLiteral("tagCounts"), + ThriftFieldType::T_MAP, + 2); + + writer.writeMapBegin(ThriftFieldType::T_STRING, ThriftFieldType::T_I32, s.tagCounts.ref().size()); + for(const auto & it: toRange(s.tagCounts.ref())) { + writer.writeString(it.key()); + writer.writeI32(it.value()); + } + writer.writeMapEnd(); + + writer.writeFieldEnd(); + } + + if (s.trashCount.isSet()) { + writer.writeFieldBegin( + QStringLiteral("trashCount"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(s.trashCount.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteCollectionCounts( + ThriftBinaryBufferReader & reader, + NoteCollectionCounts & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_MAP) { + QMap v; + qint32 size; + ThriftFieldType keyType; + ThriftFieldType elemType; + reader.readMapBegin(keyType, elemType, size); + if (keyType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map key type (NoteCollectionCounts.notebookCounts)")); + if (elemType != ThriftFieldType::T_I32) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map value type (NoteCollectionCounts.notebookCounts)")); + for(qint32 i = 0; i < size; i++) { + Guid key; + reader.readString(key); + qint32 value; + reader.readI32(value); + v[key] = value; + } + reader.readMapEnd(); + s.notebookCounts = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_MAP) { + QMap v; + qint32 size; + ThriftFieldType keyType; + ThriftFieldType elemType; + reader.readMapBegin(keyType, elemType, size); + if (keyType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map key type (NoteCollectionCounts.tagCounts)")); + if (elemType != ThriftFieldType::T_I32) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map value type (NoteCollectionCounts.tagCounts)")); + for(qint32 i = 0; i < size; i++) { + Guid key; + reader.readString(key); + qint32 value; + reader.readI32(value); + v[key] = value; + } + reader.readMapEnd(); + s.tagCounts = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.trashCount = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NoteCollectionCounts::print(QTextStream & strm) const +{ + strm << "NoteCollectionCounts: {\n"; + localData.print(strm); + + if (notebookCounts.isSet()) { + strm << " notebookCounts = " + << "QMap {"; + for(const auto & it: toRange(notebookCounts.ref())) { + strm << " [" << it.key() << "] = " << it.value() << "\n"; + } + strm << " }\n"; + } + else { + strm << " notebookCounts is not set\n"; + } + + if (tagCounts.isSet()) { + strm << " tagCounts = " + << "QMap {"; + for(const auto & it: toRange(tagCounts.ref())) { + strm << " [" << it.key() << "] = " << it.value() << "\n"; + } + strm << " }\n"; + } + else { + strm << " tagCounts is not set\n"; + } + + if (trashCount.isSet()) { + strm << " trashCount = " + << trashCount.ref() << "\n"; + } + else { + strm << " trashCount is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteResultSpec( + ThriftBinaryBufferWriter & writer, + const NoteResultSpec & s) +{ + writer.writeStructBegin(QStringLiteral("NoteResultSpec")); + if (s.includeContent.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeContent"), + ThriftFieldType::T_BOOL, + 1); + + writer.writeBool(s.includeContent.ref()); + writer.writeFieldEnd(); + } + + if (s.includeResourcesData.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeResourcesData"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(s.includeResourcesData.ref()); + writer.writeFieldEnd(); + } + + if (s.includeResourcesRecognition.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeResourcesRecognition"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(s.includeResourcesRecognition.ref()); + writer.writeFieldEnd(); + } + + if (s.includeResourcesAlternateData.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeResourcesAlternateData"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(s.includeResourcesAlternateData.ref()); + writer.writeFieldEnd(); + } + + if (s.includeSharedNotes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeSharedNotes"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(s.includeSharedNotes.ref()); + writer.writeFieldEnd(); + } + + if (s.includeNoteAppDataValues.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeNoteAppDataValues"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(s.includeNoteAppDataValues.ref()); + writer.writeFieldEnd(); + } + + if (s.includeResourceAppDataValues.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeResourceAppDataValues"), + ThriftFieldType::T_BOOL, + 7); + + writer.writeBool(s.includeResourceAppDataValues.ref()); + writer.writeFieldEnd(); + } + + if (s.includeAccountLimits.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeAccountLimits"), + ThriftFieldType::T_BOOL, + 8); + + writer.writeBool(s.includeAccountLimits.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteResultSpec( + ThriftBinaryBufferReader & reader, + NoteResultSpec & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeContent = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeResourcesData = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeResourcesRecognition = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeResourcesAlternateData = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeSharedNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeNoteAppDataValues = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeResourceAppDataValues = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeAccountLimits = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NoteResultSpec::print(QTextStream & strm) const +{ + strm << "NoteResultSpec: {\n"; + localData.print(strm); + + if (includeContent.isSet()) { + strm << " includeContent = " + << includeContent.ref() << "\n"; + } + else { + strm << " includeContent is not set\n"; + } + + if (includeResourcesData.isSet()) { + strm << " includeResourcesData = " + << includeResourcesData.ref() << "\n"; + } + else { + strm << " includeResourcesData is not set\n"; + } + + if (includeResourcesRecognition.isSet()) { + strm << " includeResourcesRecognition = " + << includeResourcesRecognition.ref() << "\n"; + } + else { + strm << " includeResourcesRecognition is not set\n"; + } + + if (includeResourcesAlternateData.isSet()) { + strm << " includeResourcesAlternateData = " + << includeResourcesAlternateData.ref() << "\n"; + } + else { + strm << " includeResourcesAlternateData is not set\n"; + } + + if (includeSharedNotes.isSet()) { + strm << " includeSharedNotes = " + << includeSharedNotes.ref() << "\n"; + } + else { + strm << " includeSharedNotes is not set\n"; + } + + if (includeNoteAppDataValues.isSet()) { + strm << " includeNoteAppDataValues = " + << includeNoteAppDataValues.ref() << "\n"; + } + else { + strm << " includeNoteAppDataValues is not set\n"; + } + + if (includeResourceAppDataValues.isSet()) { + strm << " includeResourceAppDataValues = " + << includeResourceAppDataValues.ref() << "\n"; + } + else { + strm << " includeResourceAppDataValues is not set\n"; + } + + if (includeAccountLimits.isSet()) { + strm << " includeAccountLimits = " + << includeAccountLimits.ref() << "\n"; + } + else { + strm << " includeAccountLimits is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteEmailParameters( + ThriftBinaryBufferWriter & writer, + const NoteEmailParameters & s) +{ + writer.writeStructBegin(QStringLiteral("NoteEmailParameters")); + if (s.guid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.guid.ref()); + writer.writeFieldEnd(); + } + + if (s.note.isSet()) { + writer.writeFieldBegin( + QStringLiteral("note"), + ThriftFieldType::T_STRUCT, + 2); + + writeNote(writer, s.note.ref()); + writer.writeFieldEnd(); + } + + if (s.toAddresses.isSet()) { + writer.writeFieldBegin( + QStringLiteral("toAddresses"), + ThriftFieldType::T_LIST, + 3); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.toAddresses.ref().length()); + for(const auto & value: qAsConst(s.toAddresses.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.ccAddresses.isSet()) { + writer.writeFieldBegin( + QStringLiteral("ccAddresses"), + ThriftFieldType::T_LIST, + 4); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.ccAddresses.ref().length()); + for(const auto & value: qAsConst(s.ccAddresses.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.subject.isSet()) { + writer.writeFieldBegin( + QStringLiteral("subject"), + ThriftFieldType::T_STRING, + 5); + + writer.writeString(s.subject.ref()); + writer.writeFieldEnd(); + } + + if (s.message.isSet()) { + writer.writeFieldBegin( + QStringLiteral("message"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.message.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteEmailParameters( + ThriftBinaryBufferReader & reader, + NoteEmailParameters & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.guid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRUCT) { + Note v; + readNote(reader, v); + s.note = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_LIST) { + QStringList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NoteEmailParameters.toAddresses)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.toAddresses = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_LIST) { + QStringList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NoteEmailParameters.ccAddresses)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.ccAddresses = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.subject = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.message = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NoteEmailParameters::print(QTextStream & strm) const +{ + strm << "NoteEmailParameters: {\n"; + localData.print(strm); + + if (guid.isSet()) { + strm << " guid = " + << guid.ref() << "\n"; + } + else { + strm << " guid is not set\n"; + } + + if (note.isSet()) { + strm << " note = " + << note.ref() << "\n"; + } + else { + strm << " note is not set\n"; + } + + if (toAddresses.isSet()) { + strm << " toAddresses = " + << "QList {"; + for(const auto & v: toAddresses.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " toAddresses is not set\n"; + } + + if (ccAddresses.isSet()) { + strm << " ccAddresses = " + << "QList {"; + for(const auto & v: ccAddresses.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " ccAddresses is not set\n"; + } + + if (subject.isSet()) { + strm << " subject = " + << subject.ref() << "\n"; + } + else { + strm << " subject is not set\n"; + } + + if (message.isSet()) { + strm << " message = " + << message.ref() << "\n"; + } + else { + strm << " message is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteVersionId( + ThriftBinaryBufferWriter & writer, + const NoteVersionId & s) +{ + writer.writeStructBegin(QStringLiteral("NoteVersionId")); + writer.writeFieldBegin( + QStringLiteral("updateSequenceNum"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.updateSequenceNum); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("updated"), + ThriftFieldType::T_I64, + 2); + + writer.writeI64(s.updated); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("saved"), + ThriftFieldType::T_I64, + 3); + + writer.writeI64(s.saved); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("title"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.title); + writer.writeFieldEnd(); + + if (s.lastEditorId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("lastEditorId"), + ThriftFieldType::T_I32, + 5); + + writer.writeI32(s.lastEditorId.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteVersionId( + ThriftBinaryBufferReader & reader, + NoteVersionId & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool updateSequenceNum_isset = false; + bool updated_isset = false; + bool saved_isset = false; + bool title_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + updateSequenceNum_isset = true; + qint32 v; + reader.readI32(v); + s.updateSequenceNum = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I64) { + updated_isset = true; + qint64 v; + reader.readI64(v); + s.updated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I64) { + saved_isset = true; + qint64 v; + reader.readI64(v); + s.saved = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + title_isset = true; + QString v; + reader.readString(v); + s.title = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.lastEditorId = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!updateSequenceNum_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteVersionId.updateSequenceNum has no value")); + if (!updated_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteVersionId.updated has no value")); + if (!saved_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteVersionId.saved has no value")); + if (!title_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteVersionId.title has no value")); +} + +void NoteVersionId::print(QTextStream & strm) const +{ + strm << "NoteVersionId: {\n"; + localData.print(strm); + strm << " updateSequenceNum = " + << updateSequenceNum << "\n"; + strm << " updated = " + << updated << "\n"; + strm << " saved = " + << saved << "\n"; + strm << " title = " + << title << "\n"; + + if (lastEditorId.isSet()) { + strm << " lastEditorId = " + << lastEditorId.ref() << "\n"; + } + else { + strm << " lastEditorId is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeRelatedQuery( + ThriftBinaryBufferWriter & writer, + const RelatedQuery & s) +{ + writer.writeStructBegin(QStringLiteral("RelatedQuery")); + if (s.noteGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteGuid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.noteGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.plainText.isSet()) { + writer.writeFieldBegin( + QStringLiteral("plainText"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.plainText.ref()); + writer.writeFieldEnd(); + } + + if (s.filter.isSet()) { + writer.writeFieldBegin( + QStringLiteral("filter"), + ThriftFieldType::T_STRUCT, + 3); + + writeNoteFilter(writer, s.filter.ref()); + writer.writeFieldEnd(); + } + + if (s.referenceUri.isSet()) { + writer.writeFieldBegin( + QStringLiteral("referenceUri"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.referenceUri.ref()); + writer.writeFieldEnd(); + } + + if (s.context.isSet()) { + writer.writeFieldBegin( + QStringLiteral("context"), + ThriftFieldType::T_STRING, + 5); + + writer.writeString(s.context.ref()); + writer.writeFieldEnd(); + } + + if (s.cacheKey.isSet()) { + writer.writeFieldBegin( + QStringLiteral("cacheKey"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.cacheKey.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readRelatedQuery( + ThriftBinaryBufferReader & reader, + RelatedQuery & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.noteGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.plainText = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRUCT) { + NoteFilter v; + readNoteFilter(reader, v); + s.filter = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.referenceUri = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.context = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.cacheKey = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void RelatedQuery::print(QTextStream & strm) const +{ + strm << "RelatedQuery: {\n"; + localData.print(strm); + + if (noteGuid.isSet()) { + strm << " noteGuid = " + << noteGuid.ref() << "\n"; + } + else { + strm << " noteGuid is not set\n"; + } + + if (plainText.isSet()) { + strm << " plainText = " + << plainText.ref() << "\n"; + } + else { + strm << " plainText is not set\n"; + } + + if (filter.isSet()) { + strm << " filter = " + << filter.ref() << "\n"; + } + else { + strm << " filter is not set\n"; + } + + if (referenceUri.isSet()) { + strm << " referenceUri = " + << referenceUri.ref() << "\n"; + } + else { + strm << " referenceUri is not set\n"; + } + + if (context.isSet()) { + strm << " context = " + << context.ref() << "\n"; + } + else { + strm << " context is not set\n"; + } + + if (cacheKey.isSet()) { + strm << " cacheKey = " + << cacheKey.ref() << "\n"; + } + else { + strm << " cacheKey is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeRelatedResult( + ThriftBinaryBufferWriter & writer, + const RelatedResult & s) +{ + writer.writeStructBegin(QStringLiteral("RelatedResult")); + if (s.notes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notes"), + ThriftFieldType::T_LIST, + 1); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.notes.ref().length()); + for(const auto & value: qAsConst(s.notes.ref())) { + writeNote(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.notebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebooks"), + ThriftFieldType::T_LIST, + 2); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.notebooks.ref().length()); + for(const auto & value: qAsConst(s.notebooks.ref())) { + writeNotebook(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.tags.isSet()) { + writer.writeFieldBegin( + QStringLiteral("tags"), + ThriftFieldType::T_LIST, + 3); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.tags.ref().length()); + for(const auto & value: qAsConst(s.tags.ref())) { + writeTag(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.containingNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("containingNotebooks"), + ThriftFieldType::T_LIST, + 4); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.containingNotebooks.ref().length()); + for(const auto & value: qAsConst(s.containingNotebooks.ref())) { + writeNotebookDescriptor(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.debugInfo.isSet()) { + writer.writeFieldBegin( + QStringLiteral("debugInfo"), + ThriftFieldType::T_STRING, + 5); + + writer.writeString(s.debugInfo.ref()); + writer.writeFieldEnd(); + } + + if (s.experts.isSet()) { + writer.writeFieldBegin( + QStringLiteral("experts"), + ThriftFieldType::T_LIST, + 6); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.experts.ref().length()); + for(const auto & value: qAsConst(s.experts.ref())) { + writeUserProfile(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.relatedContent.isSet()) { + writer.writeFieldBegin( + QStringLiteral("relatedContent"), + ThriftFieldType::T_LIST, + 7); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.relatedContent.ref().length()); + for(const auto & value: qAsConst(s.relatedContent.ref())) { + writeRelatedContent(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.cacheKey.isSet()) { + writer.writeFieldBegin( + QStringLiteral("cacheKey"), + ThriftFieldType::T_STRING, + 8); + + writer.writeString(s.cacheKey.ref()); + writer.writeFieldEnd(); + } + + if (s.cacheExpires.isSet()) { + writer.writeFieldBegin( + QStringLiteral("cacheExpires"), + ThriftFieldType::T_I32, + 9); + + writer.writeI32(s.cacheExpires.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readRelatedResult( + ThriftBinaryBufferReader & reader, + RelatedResult & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (RelatedResult.notes)")); + } + for(qint32 i = 0; i < size; i++) { + Note elem; + readNote(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.notes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (RelatedResult.notebooks)")); + } + for(qint32 i = 0; i < size; i++) { + Notebook elem; + readNotebook(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.notebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (RelatedResult.tags)")); + } + for(qint32 i = 0; i < size; i++) { + Tag elem; + readTag(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.tags = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (RelatedResult.containingNotebooks)")); + } + for(qint32 i = 0; i < size; i++) { + NotebookDescriptor elem; + readNotebookDescriptor(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.containingNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.debugInfo = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (RelatedResult.experts)")); + } + for(qint32 i = 0; i < size; i++) { + UserProfile elem; + readUserProfile(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.experts = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (RelatedResult.relatedContent)")); + } + for(qint32 i = 0; i < size; i++) { + RelatedContent elem; + readRelatedContent(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.relatedContent = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.cacheKey = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.cacheExpires = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void RelatedResult::print(QTextStream & strm) const +{ + strm << "RelatedResult: {\n"; + localData.print(strm); + + if (notes.isSet()) { + strm << " notes = " + << "QList {"; + for(const auto & v: notes.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " notes is not set\n"; + } + + if (notebooks.isSet()) { + strm << " notebooks = " + << "QList {"; + for(const auto & v: notebooks.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " notebooks is not set\n"; + } + + if (tags.isSet()) { + strm << " tags = " + << "QList {"; + for(const auto & v: tags.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " tags is not set\n"; + } + + if (containingNotebooks.isSet()) { + strm << " containingNotebooks = " + << "QList {"; + for(const auto & v: containingNotebooks.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " containingNotebooks is not set\n"; + } + + if (debugInfo.isSet()) { + strm << " debugInfo = " + << debugInfo.ref() << "\n"; + } + else { + strm << " debugInfo is not set\n"; + } + + if (experts.isSet()) { + strm << " experts = " + << "QList {"; + for(const auto & v: experts.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " experts is not set\n"; + } + + if (relatedContent.isSet()) { + strm << " relatedContent = " + << "QList {"; + for(const auto & v: relatedContent.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " relatedContent is not set\n"; + } + + if (cacheKey.isSet()) { + strm << " cacheKey = " + << cacheKey.ref() << "\n"; + } + else { + strm << " cacheKey is not set\n"; + } + + if (cacheExpires.isSet()) { + strm << " cacheExpires = " + << cacheExpires.ref() << "\n"; + } + else { + strm << " cacheExpires is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeRelatedResultSpec( + ThriftBinaryBufferWriter & writer, + const RelatedResultSpec & s) +{ + writer.writeStructBegin(QStringLiteral("RelatedResultSpec")); + if (s.maxNotes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("maxNotes"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.maxNotes.ref()); + writer.writeFieldEnd(); + } + + if (s.maxNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("maxNotebooks"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(s.maxNotebooks.ref()); + writer.writeFieldEnd(); + } + + if (s.maxTags.isSet()) { + writer.writeFieldBegin( + QStringLiteral("maxTags"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(s.maxTags.ref()); + writer.writeFieldEnd(); + } + + if (s.writableNotebooksOnly.isSet()) { + writer.writeFieldBegin( + QStringLiteral("writableNotebooksOnly"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(s.writableNotebooksOnly.ref()); + writer.writeFieldEnd(); + } + + if (s.includeContainingNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeContainingNotebooks"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(s.includeContainingNotebooks.ref()); + writer.writeFieldEnd(); + } + + if (s.includeDebugInfo.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeDebugInfo"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(s.includeDebugInfo.ref()); + writer.writeFieldEnd(); + } + + if (s.maxExperts.isSet()) { + writer.writeFieldBegin( + QStringLiteral("maxExperts"), + ThriftFieldType::T_I32, + 7); + + writer.writeI32(s.maxExperts.ref()); + writer.writeFieldEnd(); + } + + if (s.maxRelatedContent.isSet()) { + writer.writeFieldBegin( + QStringLiteral("maxRelatedContent"), + ThriftFieldType::T_I32, + 8); + + writer.writeI32(s.maxRelatedContent.ref()); + writer.writeFieldEnd(); + } + + if (s.relatedContentTypes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("relatedContentTypes"), + ThriftFieldType::T_SET, + 9); + + writer.writeSetBegin(ThriftFieldType::T_I32, s.relatedContentTypes.ref().count()); + for(const auto & value: qAsConst(s.relatedContentTypes.ref())) { + writer.writeI32(static_cast(value)); + } + writer.writeSetEnd(); + + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readRelatedResultSpec( + ThriftBinaryBufferReader & reader, + RelatedResultSpec & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.maxNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.maxNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.maxTags = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.writableNotebooksOnly = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeContainingNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeDebugInfo = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.maxExperts = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.maxRelatedContent = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_SET) { + QSet v; + qint32 size; + ThriftFieldType elemType; + reader.readSetBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_I32) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect set type (RelatedResultSpec.relatedContentTypes)")); + } + for(qint32 i = 0; i < size; i++) { + RelatedContentType elem; + readEnumRelatedContentType(reader, elem); + v.insert(elem); + } + reader.readSetEnd(); + s.relatedContentTypes = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void RelatedResultSpec::print(QTextStream & strm) const +{ + strm << "RelatedResultSpec: {\n"; + localData.print(strm); + + if (maxNotes.isSet()) { + strm << " maxNotes = " + << maxNotes.ref() << "\n"; + } + else { + strm << " maxNotes is not set\n"; + } + + if (maxNotebooks.isSet()) { + strm << " maxNotebooks = " + << maxNotebooks.ref() << "\n"; + } + else { + strm << " maxNotebooks is not set\n"; + } + + if (maxTags.isSet()) { + strm << " maxTags = " + << maxTags.ref() << "\n"; + } + else { + strm << " maxTags is not set\n"; + } + + if (writableNotebooksOnly.isSet()) { + strm << " writableNotebooksOnly = " + << writableNotebooksOnly.ref() << "\n"; + } + else { + strm << " writableNotebooksOnly is not set\n"; + } + + if (includeContainingNotebooks.isSet()) { + strm << " includeContainingNotebooks = " + << includeContainingNotebooks.ref() << "\n"; + } + else { + strm << " includeContainingNotebooks is not set\n"; + } + + if (includeDebugInfo.isSet()) { + strm << " includeDebugInfo = " + << includeDebugInfo.ref() << "\n"; + } + else { + strm << " includeDebugInfo is not set\n"; + } + + if (maxExperts.isSet()) { + strm << " maxExperts = " + << maxExperts.ref() << "\n"; + } + else { + strm << " maxExperts is not set\n"; + } + + if (maxRelatedContent.isSet()) { + strm << " maxRelatedContent = " + << maxRelatedContent.ref() << "\n"; + } + else { + strm << " maxRelatedContent is not set\n"; + } + + if (relatedContentTypes.isSet()) { + strm << " relatedContentTypes = " + << "QSet {"; + for(const auto & v: relatedContentTypes.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " relatedContentTypes is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeUpdateNoteIfUsnMatchesResult( + ThriftBinaryBufferWriter & writer, + const UpdateNoteIfUsnMatchesResult & s) +{ + writer.writeStructBegin(QStringLiteral("UpdateNoteIfUsnMatchesResult")); + if (s.note.isSet()) { + writer.writeFieldBegin( + QStringLiteral("note"), + ThriftFieldType::T_STRUCT, + 1); + + writeNote(writer, s.note.ref()); + writer.writeFieldEnd(); + } + + if (s.updated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updated"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(s.updated.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readUpdateNoteIfUsnMatchesResult( + ThriftBinaryBufferReader & reader, + UpdateNoteIfUsnMatchesResult & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRUCT) { + Note v; + readNote(reader, v); + s.note = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.updated = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void UpdateNoteIfUsnMatchesResult::print(QTextStream & strm) const +{ + strm << "UpdateNoteIfUsnMatchesResult: {\n"; + localData.print(strm); + + if (note.isSet()) { + strm << " note = " + << note.ref() << "\n"; + } + else { + strm << " note is not set\n"; + } + + if (updated.isSet()) { + strm << " updated = " + << updated.ref() << "\n"; + } + else { + strm << " updated is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeShareRelationshipRestrictions( + ThriftBinaryBufferWriter & writer, + const ShareRelationshipRestrictions & s) +{ + writer.writeStructBegin(QStringLiteral("ShareRelationshipRestrictions")); + if (s.noSetReadOnly.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetReadOnly"), + ThriftFieldType::T_BOOL, + 1); + + writer.writeBool(s.noSetReadOnly.ref()); + writer.writeFieldEnd(); + } + + if (s.noSetReadPlusActivity.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetReadPlusActivity"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(s.noSetReadPlusActivity.ref()); + writer.writeFieldEnd(); + } + + if (s.noSetModify.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetModify"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(s.noSetModify.ref()); + writer.writeFieldEnd(); + } + + if (s.noSetFullAccess.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetFullAccess"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(s.noSetFullAccess.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readShareRelationshipRestrictions( + ThriftBinaryBufferReader & reader, + ShareRelationshipRestrictions & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetReadOnly = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetReadPlusActivity = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetModify = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetFullAccess = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void ShareRelationshipRestrictions::print(QTextStream & strm) const +{ + strm << "ShareRelationshipRestrictions: {\n"; + localData.print(strm); + + if (noSetReadOnly.isSet()) { + strm << " noSetReadOnly = " + << noSetReadOnly.ref() << "\n"; + } + else { + strm << " noSetReadOnly is not set\n"; + } + + if (noSetReadPlusActivity.isSet()) { + strm << " noSetReadPlusActivity = " + << noSetReadPlusActivity.ref() << "\n"; + } + else { + strm << " noSetReadPlusActivity is not set\n"; + } + + if (noSetModify.isSet()) { + strm << " noSetModify = " + << noSetModify.ref() << "\n"; + } + else { + strm << " noSetModify is not set\n"; + } + + if (noSetFullAccess.isSet()) { + strm << " noSetFullAccess = " + << noSetFullAccess.ref() << "\n"; + } + else { + strm << " noSetFullAccess is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeInvitationShareRelationship( + ThriftBinaryBufferWriter & writer, + const InvitationShareRelationship & s) +{ + writer.writeStructBegin(QStringLiteral("InvitationShareRelationship")); + if (s.displayName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("displayName"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.displayName.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientUserIdentity.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientUserIdentity"), + ThriftFieldType::T_STRUCT, + 2); + + writeUserIdentity(writer, s.recipientUserIdentity.ref()); + writer.writeFieldEnd(); + } + + if (s.privilege.isSet()) { + writer.writeFieldBegin( + QStringLiteral("privilege"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(static_cast(s.privilege.ref())); + writer.writeFieldEnd(); + } + + if (s.sharerUserId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sharerUserId"), + ThriftFieldType::T_I32, + 5); + + writer.writeI32(s.sharerUserId.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readInvitationShareRelationship( + ThriftBinaryBufferReader & reader, + InvitationShareRelationship & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.displayName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRUCT) { + UserIdentity v; + readUserIdentity(reader, v); + s.recipientUserIdentity = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + ShareRelationshipPrivilegeLevel v; + readEnumShareRelationshipPrivilegeLevel(reader, v); + s.privilege = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.sharerUserId = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void InvitationShareRelationship::print(QTextStream & strm) const +{ + strm << "InvitationShareRelationship: {\n"; + localData.print(strm); + + if (displayName.isSet()) { + strm << " displayName = " + << displayName.ref() << "\n"; + } + else { + strm << " displayName is not set\n"; + } + + if (recipientUserIdentity.isSet()) { + strm << " recipientUserIdentity = " + << recipientUserIdentity.ref() << "\n"; + } + else { + strm << " recipientUserIdentity is not set\n"; + } + + if (privilege.isSet()) { + strm << " privilege = " + << privilege.ref() << "\n"; + } + else { + strm << " privilege is not set\n"; + } + + if (sharerUserId.isSet()) { + strm << " sharerUserId = " + << sharerUserId.ref() << "\n"; + } + else { + strm << " sharerUserId is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeMemberShareRelationship( + ThriftBinaryBufferWriter & writer, + const MemberShareRelationship & s) +{ + writer.writeStructBegin(QStringLiteral("MemberShareRelationship")); + if (s.displayName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("displayName"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.displayName.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientUserId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientUserId"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(s.recipientUserId.ref()); + writer.writeFieldEnd(); + } + + if (s.bestPrivilege.isSet()) { + writer.writeFieldBegin( + QStringLiteral("bestPrivilege"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(static_cast(s.bestPrivilege.ref())); + writer.writeFieldEnd(); + } + + if (s.individualPrivilege.isSet()) { + writer.writeFieldBegin( + QStringLiteral("individualPrivilege"), + ThriftFieldType::T_I32, + 4); + + writer.writeI32(static_cast(s.individualPrivilege.ref())); + writer.writeFieldEnd(); + } + + if (s.restrictions.isSet()) { + writer.writeFieldBegin( + QStringLiteral("restrictions"), + ThriftFieldType::T_STRUCT, + 5); + + writeShareRelationshipRestrictions(writer, s.restrictions.ref()); + writer.writeFieldEnd(); + } + + if (s.sharerUserId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sharerUserId"), + ThriftFieldType::T_I32, + 6); + + writer.writeI32(s.sharerUserId.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readMemberShareRelationship( + ThriftBinaryBufferReader & reader, + MemberShareRelationship & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.displayName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.recipientUserId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + ShareRelationshipPrivilegeLevel v; + readEnumShareRelationshipPrivilegeLevel(reader, v); + s.bestPrivilege = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_I32) { + ShareRelationshipPrivilegeLevel v; + readEnumShareRelationshipPrivilegeLevel(reader, v); + s.individualPrivilege = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_STRUCT) { + ShareRelationshipRestrictions v; + readShareRelationshipRestrictions(reader, v); + s.restrictions = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.sharerUserId = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void MemberShareRelationship::print(QTextStream & strm) const +{ + strm << "MemberShareRelationship: {\n"; + localData.print(strm); + + if (displayName.isSet()) { + strm << " displayName = " + << displayName.ref() << "\n"; + } + else { + strm << " displayName is not set\n"; + } + + if (recipientUserId.isSet()) { + strm << " recipientUserId = " + << recipientUserId.ref() << "\n"; + } + else { + strm << " recipientUserId is not set\n"; + } + + if (bestPrivilege.isSet()) { + strm << " bestPrivilege = " + << bestPrivilege.ref() << "\n"; + } + else { + strm << " bestPrivilege is not set\n"; + } + + if (individualPrivilege.isSet()) { + strm << " individualPrivilege = " + << individualPrivilege.ref() << "\n"; + } + else { + strm << " individualPrivilege is not set\n"; + } + + if (restrictions.isSet()) { + strm << " restrictions = " + << restrictions.ref() << "\n"; + } + else { + strm << " restrictions is not set\n"; + } + + if (sharerUserId.isSet()) { + strm << " sharerUserId = " + << sharerUserId.ref() << "\n"; + } + else { + strm << " sharerUserId is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeShareRelationships( + ThriftBinaryBufferWriter & writer, + const ShareRelationships & s) +{ + writer.writeStructBegin(QStringLiteral("ShareRelationships")); + if (s.invitations.isSet()) { + writer.writeFieldBegin( + QStringLiteral("invitations"), + ThriftFieldType::T_LIST, + 1); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.invitations.ref().length()); + for(const auto & value: qAsConst(s.invitations.ref())) { + writeInvitationShareRelationship(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.memberships.isSet()) { + writer.writeFieldBegin( + QStringLiteral("memberships"), + ThriftFieldType::T_LIST, + 2); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.memberships.ref().length()); + for(const auto & value: qAsConst(s.memberships.ref())) { + writeMemberShareRelationship(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.invitationRestrictions.isSet()) { + writer.writeFieldBegin( + QStringLiteral("invitationRestrictions"), + ThriftFieldType::T_STRUCT, + 3); + + writeShareRelationshipRestrictions(writer, s.invitationRestrictions.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readShareRelationships( + ThriftBinaryBufferReader & reader, + ShareRelationships & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (ShareRelationships.invitations)")); + } + for(qint32 i = 0; i < size; i++) { + InvitationShareRelationship elem; + readInvitationShareRelationship(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.invitations = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (ShareRelationships.memberships)")); + } + for(qint32 i = 0; i < size; i++) { + MemberShareRelationship elem; + readMemberShareRelationship(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.memberships = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRUCT) { + ShareRelationshipRestrictions v; + readShareRelationshipRestrictions(reader, v); + s.invitationRestrictions = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void ShareRelationships::print(QTextStream & strm) const +{ + strm << "ShareRelationships: {\n"; + localData.print(strm); + + if (invitations.isSet()) { + strm << " invitations = " + << "QList {"; + for(const auto & v: invitations.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " invitations is not set\n"; + } + + if (memberships.isSet()) { + strm << " memberships = " + << "QList {"; + for(const auto & v: memberships.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " memberships is not set\n"; + } + + if (invitationRestrictions.isSet()) { + strm << " invitationRestrictions = " + << invitationRestrictions.ref() << "\n"; + } + else { + strm << " invitationRestrictions is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeManageNotebookSharesParameters( + ThriftBinaryBufferWriter & writer, + const ManageNotebookSharesParameters & s) +{ + writer.writeStructBegin(QStringLiteral("ManageNotebookSharesParameters")); + if (s.notebookGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebookGuid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.notebookGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.inviteMessage.isSet()) { + writer.writeFieldBegin( + QStringLiteral("inviteMessage"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.inviteMessage.ref()); + writer.writeFieldEnd(); + } + + if (s.membershipsToUpdate.isSet()) { + writer.writeFieldBegin( + QStringLiteral("membershipsToUpdate"), + ThriftFieldType::T_LIST, + 3); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.membershipsToUpdate.ref().length()); + for(const auto & value: qAsConst(s.membershipsToUpdate.ref())) { + writeMemberShareRelationship(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.invitationsToCreateOrUpdate.isSet()) { + writer.writeFieldBegin( + QStringLiteral("invitationsToCreateOrUpdate"), + ThriftFieldType::T_LIST, + 4); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.invitationsToCreateOrUpdate.ref().length()); + for(const auto & value: qAsConst(s.invitationsToCreateOrUpdate.ref())) { + writeInvitationShareRelationship(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.unshares.isSet()) { + writer.writeFieldBegin( + QStringLiteral("unshares"), + ThriftFieldType::T_LIST, + 5); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.unshares.ref().length()); + for(const auto & value: qAsConst(s.unshares.ref())) { + writeUserIdentity(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readManageNotebookSharesParameters( + ThriftBinaryBufferReader & reader, + ManageNotebookSharesParameters & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.notebookGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.inviteMessage = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (ManageNotebookSharesParameters.membershipsToUpdate)")); + } + for(qint32 i = 0; i < size; i++) { + MemberShareRelationship elem; + readMemberShareRelationship(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.membershipsToUpdate = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (ManageNotebookSharesParameters.invitationsToCreateOrUpdate)")); + } + for(qint32 i = 0; i < size; i++) { + InvitationShareRelationship elem; + readInvitationShareRelationship(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.invitationsToCreateOrUpdate = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (ManageNotebookSharesParameters.unshares)")); + } + for(qint32 i = 0; i < size; i++) { + UserIdentity elem; + readUserIdentity(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.unshares = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void ManageNotebookSharesParameters::print(QTextStream & strm) const +{ + strm << "ManageNotebookSharesParameters: {\n"; + localData.print(strm); + + if (notebookGuid.isSet()) { + strm << " notebookGuid = " + << notebookGuid.ref() << "\n"; + } + else { + strm << " notebookGuid is not set\n"; + } + + if (inviteMessage.isSet()) { + strm << " inviteMessage = " + << inviteMessage.ref() << "\n"; + } + else { + strm << " inviteMessage is not set\n"; + } + + if (membershipsToUpdate.isSet()) { + strm << " membershipsToUpdate = " + << "QList {"; + for(const auto & v: membershipsToUpdate.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " membershipsToUpdate is not set\n"; + } + + if (invitationsToCreateOrUpdate.isSet()) { + strm << " invitationsToCreateOrUpdate = " + << "QList {"; + for(const auto & v: invitationsToCreateOrUpdate.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " invitationsToCreateOrUpdate is not set\n"; + } + + if (unshares.isSet()) { + strm << " unshares = " + << "QList {"; + for(const auto & v: unshares.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " unshares is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeManageNotebookSharesError( + ThriftBinaryBufferWriter & writer, + const ManageNotebookSharesError & s) +{ + writer.writeStructBegin(QStringLiteral("ManageNotebookSharesError")); + if (s.userIdentity.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userIdentity"), + ThriftFieldType::T_STRUCT, + 1); + + writeUserIdentity(writer, s.userIdentity.ref()); + writer.writeFieldEnd(); + } + + if (s.userException.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userException"), + ThriftFieldType::T_STRUCT, + 2); + + writeEDAMUserException(writer, s.userException.ref()); + writer.writeFieldEnd(); + } + + if (s.notFoundException.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notFoundException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMNotFoundException(writer, s.notFoundException.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readManageNotebookSharesError( + ThriftBinaryBufferReader & reader, + ManageNotebookSharesError & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRUCT) { + UserIdentity v; + readUserIdentity(reader, v); + s.userIdentity = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException v; + readEDAMUserException(reader, v); + s.userException = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException v; + readEDAMNotFoundException(reader, v); + s.notFoundException = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void ManageNotebookSharesError::print(QTextStream & strm) const +{ + strm << "ManageNotebookSharesError: {\n"; + localData.print(strm); + + if (userIdentity.isSet()) { + strm << " userIdentity = " + << userIdentity.ref() << "\n"; + } + else { + strm << " userIdentity is not set\n"; + } + + if (userException.isSet()) { + strm << " userException = " + << userException.ref() << "\n"; + } + else { + strm << " userException is not set\n"; + } + + if (notFoundException.isSet()) { + strm << " notFoundException = " + << notFoundException.ref() << "\n"; + } + else { + strm << " notFoundException is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeManageNotebookSharesResult( + ThriftBinaryBufferWriter & writer, + const ManageNotebookSharesResult & s) +{ + writer.writeStructBegin(QStringLiteral("ManageNotebookSharesResult")); + if (s.errors.isSet()) { + writer.writeFieldBegin( + QStringLiteral("errors"), + ThriftFieldType::T_LIST, + 1); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.errors.ref().length()); + for(const auto & value: qAsConst(s.errors.ref())) { + writeManageNotebookSharesError(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readManageNotebookSharesResult( + ThriftBinaryBufferReader & reader, + ManageNotebookSharesResult & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (ManageNotebookSharesResult.errors)")); + } + for(qint32 i = 0; i < size; i++) { + ManageNotebookSharesError elem; + readManageNotebookSharesError(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.errors = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void ManageNotebookSharesResult::print(QTextStream & strm) const +{ + strm << "ManageNotebookSharesResult: {\n"; + localData.print(strm); + + if (errors.isSet()) { + strm << " errors = " + << "QList {"; + for(const auto & v: errors.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " errors is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeSharedNoteTemplate( + ThriftBinaryBufferWriter & writer, + const SharedNoteTemplate & s) +{ + writer.writeStructBegin(QStringLiteral("SharedNoteTemplate")); + if (s.noteGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteGuid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.noteGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientThreadId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientThreadId"), + ThriftFieldType::T_I64, + 4); + + writer.writeI64(s.recipientThreadId.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientContacts.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientContacts"), + ThriftFieldType::T_LIST, + 2); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.recipientContacts.ref().length()); + for(const auto & value: qAsConst(s.recipientContacts.ref())) { + writeContact(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.privilege.isSet()) { + writer.writeFieldBegin( + QStringLiteral("privilege"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(static_cast(s.privilege.ref())); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readSharedNoteTemplate( + ThriftBinaryBufferReader & reader, + SharedNoteTemplate & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.noteGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_I64) { + MessageThreadID v; + reader.readI64(v); + s.recipientThreadId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (SharedNoteTemplate.recipientContacts)")); + } + for(qint32 i = 0; i < size; i++) { + Contact elem; + readContact(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.recipientContacts = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + SharedNotePrivilegeLevel v; + readEnumSharedNotePrivilegeLevel(reader, v); + s.privilege = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void SharedNoteTemplate::print(QTextStream & strm) const +{ + strm << "SharedNoteTemplate: {\n"; + localData.print(strm); + + if (noteGuid.isSet()) { + strm << " noteGuid = " + << noteGuid.ref() << "\n"; + } + else { + strm << " noteGuid is not set\n"; + } + + if (recipientThreadId.isSet()) { + strm << " recipientThreadId = " + << recipientThreadId.ref() << "\n"; + } + else { + strm << " recipientThreadId is not set\n"; + } + + if (recipientContacts.isSet()) { + strm << " recipientContacts = " + << "QList {"; + for(const auto & v: recipientContacts.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " recipientContacts is not set\n"; + } + + if (privilege.isSet()) { + strm << " privilege = " + << privilege.ref() << "\n"; + } + else { + strm << " privilege is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNotebookShareTemplate( + ThriftBinaryBufferWriter & writer, + const NotebookShareTemplate & s) +{ + writer.writeStructBegin(QStringLiteral("NotebookShareTemplate")); + if (s.notebookGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebookGuid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.notebookGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientThreadId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientThreadId"), + ThriftFieldType::T_I64, + 4); + + writer.writeI64(s.recipientThreadId.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientContacts.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientContacts"), + ThriftFieldType::T_LIST, + 2); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.recipientContacts.ref().length()); + for(const auto & value: qAsConst(s.recipientContacts.ref())) { + writeContact(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.privilege.isSet()) { + writer.writeFieldBegin( + QStringLiteral("privilege"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(static_cast(s.privilege.ref())); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNotebookShareTemplate( + ThriftBinaryBufferReader & reader, + NotebookShareTemplate & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.notebookGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_I64) { + MessageThreadID v; + reader.readI64(v); + s.recipientThreadId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NotebookShareTemplate.recipientContacts)")); + } + for(qint32 i = 0; i < size; i++) { + Contact elem; + readContact(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.recipientContacts = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + SharedNotebookPrivilegeLevel v; + readEnumSharedNotebookPrivilegeLevel(reader, v); + s.privilege = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NotebookShareTemplate::print(QTextStream & strm) const +{ + strm << "NotebookShareTemplate: {\n"; + localData.print(strm); + + if (notebookGuid.isSet()) { + strm << " notebookGuid = " + << notebookGuid.ref() << "\n"; + } + else { + strm << " notebookGuid is not set\n"; + } + + if (recipientThreadId.isSet()) { + strm << " recipientThreadId = " + << recipientThreadId.ref() << "\n"; + } + else { + strm << " recipientThreadId is not set\n"; + } + + if (recipientContacts.isSet()) { + strm << " recipientContacts = " + << "QList {"; + for(const auto & v: recipientContacts.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " recipientContacts is not set\n"; + } + + if (privilege.isSet()) { + strm << " privilege = " + << privilege.ref() << "\n"; + } + else { + strm << " privilege is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeCreateOrUpdateNotebookSharesResult( + ThriftBinaryBufferWriter & writer, + const CreateOrUpdateNotebookSharesResult & s) +{ + writer.writeStructBegin(QStringLiteral("CreateOrUpdateNotebookSharesResult")); + if (s.updateSequenceNum.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updateSequenceNum"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.updateSequenceNum.ref()); + writer.writeFieldEnd(); + } + + if (s.matchingShares.isSet()) { + writer.writeFieldBegin( + QStringLiteral("matchingShares"), + ThriftFieldType::T_LIST, + 2); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.matchingShares.ref().length()); + for(const auto & value: qAsConst(s.matchingShares.ref())) { + writeSharedNotebook(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readCreateOrUpdateNotebookSharesResult( + ThriftBinaryBufferReader & reader, + CreateOrUpdateNotebookSharesResult & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.updateSequenceNum = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (CreateOrUpdateNotebookSharesResult.matchingShares)")); + } + for(qint32 i = 0; i < size; i++) { + SharedNotebook elem; + readSharedNotebook(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.matchingShares = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void CreateOrUpdateNotebookSharesResult::print(QTextStream & strm) const +{ + strm << "CreateOrUpdateNotebookSharesResult: {\n"; + localData.print(strm); + + if (updateSequenceNum.isSet()) { + strm << " updateSequenceNum = " + << updateSequenceNum.ref() << "\n"; + } + else { + strm << " updateSequenceNum is not set\n"; + } + + if (matchingShares.isSet()) { + strm << " matchingShares = " + << "QList {"; + for(const auto & v: matchingShares.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " matchingShares is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteShareRelationshipRestrictions( + ThriftBinaryBufferWriter & writer, + const NoteShareRelationshipRestrictions & s) +{ + writer.writeStructBegin(QStringLiteral("NoteShareRelationshipRestrictions")); + if (s.noSetReadNote.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetReadNote"), + ThriftFieldType::T_BOOL, + 1); + + writer.writeBool(s.noSetReadNote.ref()); + writer.writeFieldEnd(); + } + + if (s.noSetModifyNote.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetModifyNote"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(s.noSetModifyNote.ref()); + writer.writeFieldEnd(); + } + + if (s.noSetFullAccess.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetFullAccess"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(s.noSetFullAccess.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteShareRelationshipRestrictions( + ThriftBinaryBufferReader & reader, + NoteShareRelationshipRestrictions & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetReadNote = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetModifyNote = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetFullAccess = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NoteShareRelationshipRestrictions::print(QTextStream & strm) const +{ + strm << "NoteShareRelationshipRestrictions: {\n"; + localData.print(strm); + + if (noSetReadNote.isSet()) { + strm << " noSetReadNote = " + << noSetReadNote.ref() << "\n"; + } + else { + strm << " noSetReadNote is not set\n"; + } + + if (noSetModifyNote.isSet()) { + strm << " noSetModifyNote = " + << noSetModifyNote.ref() << "\n"; + } + else { + strm << " noSetModifyNote is not set\n"; + } + + if (noSetFullAccess.isSet()) { + strm << " noSetFullAccess = " + << noSetFullAccess.ref() << "\n"; + } + else { + strm << " noSetFullAccess is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteMemberShareRelationship( + ThriftBinaryBufferWriter & writer, + const NoteMemberShareRelationship & s) +{ + writer.writeStructBegin(QStringLiteral("NoteMemberShareRelationship")); + if (s.displayName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("displayName"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.displayName.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientUserId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientUserId"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(s.recipientUserId.ref()); + writer.writeFieldEnd(); + } + + if (s.privilege.isSet()) { + writer.writeFieldBegin( + QStringLiteral("privilege"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(static_cast(s.privilege.ref())); + writer.writeFieldEnd(); + } + + if (s.restrictions.isSet()) { + writer.writeFieldBegin( + QStringLiteral("restrictions"), + ThriftFieldType::T_STRUCT, + 4); + + writeNoteShareRelationshipRestrictions(writer, s.restrictions.ref()); + writer.writeFieldEnd(); + } + + if (s.sharerUserId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sharerUserId"), + ThriftFieldType::T_I32, + 5); + + writer.writeI32(s.sharerUserId.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteMemberShareRelationship( + ThriftBinaryBufferReader & reader, + NoteMemberShareRelationship & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.displayName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.recipientUserId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + SharedNotePrivilegeLevel v; + readEnumSharedNotePrivilegeLevel(reader, v); + s.privilege = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRUCT) { + NoteShareRelationshipRestrictions v; + readNoteShareRelationshipRestrictions(reader, v); + s.restrictions = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.sharerUserId = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NoteMemberShareRelationship::print(QTextStream & strm) const +{ + strm << "NoteMemberShareRelationship: {\n"; + localData.print(strm); + + if (displayName.isSet()) { + strm << " displayName = " + << displayName.ref() << "\n"; + } + else { + strm << " displayName is not set\n"; + } + + if (recipientUserId.isSet()) { + strm << " recipientUserId = " + << recipientUserId.ref() << "\n"; + } + else { + strm << " recipientUserId is not set\n"; + } + + if (privilege.isSet()) { + strm << " privilege = " + << privilege.ref() << "\n"; + } + else { + strm << " privilege is not set\n"; + } + + if (restrictions.isSet()) { + strm << " restrictions = " + << restrictions.ref() << "\n"; + } + else { + strm << " restrictions is not set\n"; + } + + if (sharerUserId.isSet()) { + strm << " sharerUserId = " + << sharerUserId.ref() << "\n"; + } + else { + strm << " sharerUserId is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteInvitationShareRelationship( + ThriftBinaryBufferWriter & writer, + const NoteInvitationShareRelationship & s) +{ + writer.writeStructBegin(QStringLiteral("NoteInvitationShareRelationship")); + if (s.displayName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("displayName"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.displayName.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientIdentityId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientIdentityId"), + ThriftFieldType::T_I64, + 2); + + writer.writeI64(s.recipientIdentityId.ref()); + writer.writeFieldEnd(); + } + + if (s.privilege.isSet()) { + writer.writeFieldBegin( + QStringLiteral("privilege"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(static_cast(s.privilege.ref())); + writer.writeFieldEnd(); + } + + if (s.sharerUserId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sharerUserId"), + ThriftFieldType::T_I32, + 5); + + writer.writeI32(s.sharerUserId.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteInvitationShareRelationship( + ThriftBinaryBufferReader & reader, + NoteInvitationShareRelationship & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.displayName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I64) { + IdentityID v; + reader.readI64(v); + s.recipientIdentityId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + SharedNotePrivilegeLevel v; + readEnumSharedNotePrivilegeLevel(reader, v); + s.privilege = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.sharerUserId = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NoteInvitationShareRelationship::print(QTextStream & strm) const +{ + strm << "NoteInvitationShareRelationship: {\n"; + localData.print(strm); + + if (displayName.isSet()) { + strm << " displayName = " + << displayName.ref() << "\n"; + } + else { + strm << " displayName is not set\n"; + } + + if (recipientIdentityId.isSet()) { + strm << " recipientIdentityId = " + << recipientIdentityId.ref() << "\n"; + } + else { + strm << " recipientIdentityId is not set\n"; + } + + if (privilege.isSet()) { + strm << " privilege = " + << privilege.ref() << "\n"; + } + else { + strm << " privilege is not set\n"; + } + + if (sharerUserId.isSet()) { + strm << " sharerUserId = " + << sharerUserId.ref() << "\n"; + } + else { + strm << " sharerUserId is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteShareRelationships( + ThriftBinaryBufferWriter & writer, + const NoteShareRelationships & s) +{ + writer.writeStructBegin(QStringLiteral("NoteShareRelationships")); + if (s.invitations.isSet()) { + writer.writeFieldBegin( + QStringLiteral("invitations"), + ThriftFieldType::T_LIST, + 1); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.invitations.ref().length()); + for(const auto & value: qAsConst(s.invitations.ref())) { + writeNoteInvitationShareRelationship(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.memberships.isSet()) { + writer.writeFieldBegin( + QStringLiteral("memberships"), + ThriftFieldType::T_LIST, + 2); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.memberships.ref().length()); + for(const auto & value: qAsConst(s.memberships.ref())) { + writeNoteMemberShareRelationship(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.invitationRestrictions.isSet()) { + writer.writeFieldBegin( + QStringLiteral("invitationRestrictions"), + ThriftFieldType::T_STRUCT, + 3); + + writeNoteShareRelationshipRestrictions(writer, s.invitationRestrictions.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteShareRelationships( + ThriftBinaryBufferReader & reader, + NoteShareRelationships & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NoteShareRelationships.invitations)")); + } + for(qint32 i = 0; i < size; i++) { + NoteInvitationShareRelationship elem; + readNoteInvitationShareRelationship(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.invitations = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (NoteShareRelationships.memberships)")); + } + for(qint32 i = 0; i < size; i++) { + NoteMemberShareRelationship elem; + readNoteMemberShareRelationship(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.memberships = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRUCT) { + NoteShareRelationshipRestrictions v; + readNoteShareRelationshipRestrictions(reader, v); + s.invitationRestrictions = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NoteShareRelationships::print(QTextStream & strm) const +{ + strm << "NoteShareRelationships: {\n"; + localData.print(strm); + + if (invitations.isSet()) { + strm << " invitations = " + << "QList {"; + for(const auto & v: invitations.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " invitations is not set\n"; + } + + if (memberships.isSet()) { + strm << " memberships = " + << "QList {"; + for(const auto & v: memberships.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " memberships is not set\n"; + } + + if (invitationRestrictions.isSet()) { + strm << " invitationRestrictions = " + << invitationRestrictions.ref() << "\n"; + } + else { + strm << " invitationRestrictions is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeManageNoteSharesParameters( + ThriftBinaryBufferWriter & writer, + const ManageNoteSharesParameters & s) +{ + writer.writeStructBegin(QStringLiteral("ManageNoteSharesParameters")); + if (s.noteGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteGuid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.noteGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.membershipsToUpdate.isSet()) { + writer.writeFieldBegin( + QStringLiteral("membershipsToUpdate"), + ThriftFieldType::T_LIST, + 2); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.membershipsToUpdate.ref().length()); + for(const auto & value: qAsConst(s.membershipsToUpdate.ref())) { + writeNoteMemberShareRelationship(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.invitationsToUpdate.isSet()) { + writer.writeFieldBegin( + QStringLiteral("invitationsToUpdate"), + ThriftFieldType::T_LIST, + 3); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.invitationsToUpdate.ref().length()); + for(const auto & value: qAsConst(s.invitationsToUpdate.ref())) { + writeNoteInvitationShareRelationship(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.membershipsToUnshare.isSet()) { + writer.writeFieldBegin( + QStringLiteral("membershipsToUnshare"), + ThriftFieldType::T_LIST, + 4); + + writer.writeListBegin(ThriftFieldType::T_I32, s.membershipsToUnshare.ref().length()); + for(const auto & value: qAsConst(s.membershipsToUnshare.ref())) { + writer.writeI32(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.invitationsToUnshare.isSet()) { + writer.writeFieldBegin( + QStringLiteral("invitationsToUnshare"), + ThriftFieldType::T_LIST, + 5); + + writer.writeListBegin(ThriftFieldType::T_I64, s.invitationsToUnshare.ref().length()); + for(const auto & value: qAsConst(s.invitationsToUnshare.ref())) { + writer.writeI64(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readManageNoteSharesParameters( + ThriftBinaryBufferReader & reader, + ManageNoteSharesParameters & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.noteGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (ManageNoteSharesParameters.membershipsToUpdate)")); + } + for(qint32 i = 0; i < size; i++) { + NoteMemberShareRelationship elem; + readNoteMemberShareRelationship(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.membershipsToUpdate = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (ManageNoteSharesParameters.invitationsToUpdate)")); + } + for(qint32 i = 0; i < size; i++) { + NoteInvitationShareRelationship elem; + readNoteInvitationShareRelationship(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.invitationsToUpdate = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_I32) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (ManageNoteSharesParameters.membershipsToUnshare)")); + } + for(qint32 i = 0; i < size; i++) { + UserID elem; + reader.readI32(elem); + v.append(elem); + } + reader.readListEnd(); + s.membershipsToUnshare = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_I64) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (ManageNoteSharesParameters.invitationsToUnshare)")); + } + for(qint32 i = 0; i < size; i++) { + IdentityID elem; + reader.readI64(elem); + v.append(elem); + } + reader.readListEnd(); + s.invitationsToUnshare = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void ManageNoteSharesParameters::print(QTextStream & strm) const +{ + strm << "ManageNoteSharesParameters: {\n"; + localData.print(strm); + + if (noteGuid.isSet()) { + strm << " noteGuid = " + << noteGuid.ref() << "\n"; + } + else { + strm << " noteGuid is not set\n"; + } + + if (membershipsToUpdate.isSet()) { + strm << " membershipsToUpdate = " + << "QList {"; + for(const auto & v: membershipsToUpdate.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " membershipsToUpdate is not set\n"; + } + + if (invitationsToUpdate.isSet()) { + strm << " invitationsToUpdate = " + << "QList {"; + for(const auto & v: invitationsToUpdate.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " invitationsToUpdate is not set\n"; + } + + if (membershipsToUnshare.isSet()) { + strm << " membershipsToUnshare = " + << "QList {"; + for(const auto & v: membershipsToUnshare.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " membershipsToUnshare is not set\n"; + } + + if (invitationsToUnshare.isSet()) { + strm << " invitationsToUnshare = " + << "QList {"; + for(const auto & v: invitationsToUnshare.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " invitationsToUnshare is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeManageNoteSharesError( + ThriftBinaryBufferWriter & writer, + const ManageNoteSharesError & s) +{ + writer.writeStructBegin(QStringLiteral("ManageNoteSharesError")); + if (s.identityID.isSet()) { + writer.writeFieldBegin( + QStringLiteral("identityID"), + ThriftFieldType::T_I64, + 1); + + writer.writeI64(s.identityID.ref()); + writer.writeFieldEnd(); + } + + if (s.userID.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userID"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(s.userID.ref()); + writer.writeFieldEnd(); + } + + if (s.userException.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userException"), + ThriftFieldType::T_STRUCT, + 3); + + writeEDAMUserException(writer, s.userException.ref()); + writer.writeFieldEnd(); + } + + if (s.notFoundException.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notFoundException"), + ThriftFieldType::T_STRUCT, + 4); + + writeEDAMNotFoundException(writer, s.notFoundException.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readManageNoteSharesError( + ThriftBinaryBufferReader & reader, + ManageNoteSharesError & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I64) { + IdentityID v; + reader.readI64(v); + s.identityID = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.userID = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMUserException v; + readEDAMUserException(reader, v); + s.userException = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRUCT) { + EDAMNotFoundException v; + readEDAMNotFoundException(reader, v); + s.notFoundException = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void ManageNoteSharesError::print(QTextStream & strm) const +{ + strm << "ManageNoteSharesError: {\n"; + localData.print(strm); + + if (identityID.isSet()) { + strm << " identityID = " + << identityID.ref() << "\n"; + } + else { + strm << " identityID is not set\n"; + } + + if (userID.isSet()) { + strm << " userID = " + << userID.ref() << "\n"; + } + else { + strm << " userID is not set\n"; + } + + if (userException.isSet()) { + strm << " userException = " + << userException.ref() << "\n"; + } + else { + strm << " userException is not set\n"; + } + + if (notFoundException.isSet()) { + strm << " notFoundException = " + << notFoundException.ref() << "\n"; + } + else { + strm << " notFoundException is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeManageNoteSharesResult( + ThriftBinaryBufferWriter & writer, + const ManageNoteSharesResult & s) +{ + writer.writeStructBegin(QStringLiteral("ManageNoteSharesResult")); + if (s.errors.isSet()) { + writer.writeFieldBegin( + QStringLiteral("errors"), + ThriftFieldType::T_LIST, + 1); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.errors.ref().length()); + for(const auto & value: qAsConst(s.errors.ref())) { + writeManageNoteSharesError(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readManageNoteSharesResult( + ThriftBinaryBufferReader & reader, + ManageNoteSharesResult & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (ManageNoteSharesResult.errors)")); + } + for(qint32 i = 0; i < size; i++) { + ManageNoteSharesError elem; + readManageNoteSharesError(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.errors = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void ManageNoteSharesResult::print(QTextStream & strm) const +{ + strm << "ManageNoteSharesResult: {\n"; + localData.print(strm); + + if (errors.isSet()) { + strm << " errors = " + << "QList {"; + for(const auto & v: errors.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " errors is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeData( + ThriftBinaryBufferWriter & writer, + const Data & s) +{ + writer.writeStructBegin(QStringLiteral("Data")); + if (s.bodyHash.isSet()) { + writer.writeFieldBegin( + QStringLiteral("bodyHash"), + ThriftFieldType::T_STRING, + 1); + + writer.writeBinary(s.bodyHash.ref()); + writer.writeFieldEnd(); + } + + if (s.size.isSet()) { + writer.writeFieldBegin( + QStringLiteral("size"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(s.size.ref()); + writer.writeFieldEnd(); + } + + if (s.body.isSet()) { + writer.writeFieldBegin( + QStringLiteral("body"), + ThriftFieldType::T_STRING, + 3); + + writer.writeBinary(s.body.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readData( + ThriftBinaryBufferReader & reader, + Data & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QByteArray v; + reader.readBinary(v); + s.bodyHash = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.size = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + QByteArray v; + reader.readBinary(v); + s.body = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void Data::print(QTextStream & strm) const +{ + strm << "Data: {\n"; + localData.print(strm); + + if (bodyHash.isSet()) { + strm << " bodyHash = " + << bodyHash.ref() << "\n"; + } + else { + strm << " bodyHash is not set\n"; + } + + if (size.isSet()) { + strm << " size = " + << size.ref() << "\n"; + } + else { + strm << " size is not set\n"; + } + + if (body.isSet()) { + strm << " body = " + << body.ref() << "\n"; + } + else { + strm << " body is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeUserAttributes( + ThriftBinaryBufferWriter & writer, + const UserAttributes & s) +{ + writer.writeStructBegin(QStringLiteral("UserAttributes")); + if (s.defaultLocationName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("defaultLocationName"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.defaultLocationName.ref()); + writer.writeFieldEnd(); + } + + if (s.defaultLatitude.isSet()) { + writer.writeFieldBegin( + QStringLiteral("defaultLatitude"), + ThriftFieldType::T_DOUBLE, + 2); + + writer.writeDouble(s.defaultLatitude.ref()); + writer.writeFieldEnd(); + } + + if (s.defaultLongitude.isSet()) { + writer.writeFieldBegin( + QStringLiteral("defaultLongitude"), + ThriftFieldType::T_DOUBLE, + 3); + + writer.writeDouble(s.defaultLongitude.ref()); + writer.writeFieldEnd(); + } + + if (s.preactivation.isSet()) { + writer.writeFieldBegin( + QStringLiteral("preactivation"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(s.preactivation.ref()); + writer.writeFieldEnd(); + } + + if (s.viewedPromotions.isSet()) { + writer.writeFieldBegin( + QStringLiteral("viewedPromotions"), + ThriftFieldType::T_LIST, + 5); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.viewedPromotions.ref().length()); + for(const auto & value: qAsConst(s.viewedPromotions.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.incomingEmailAddress.isSet()) { + writer.writeFieldBegin( + QStringLiteral("incomingEmailAddress"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.incomingEmailAddress.ref()); + writer.writeFieldEnd(); + } + + if (s.recentMailedAddresses.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recentMailedAddresses"), + ThriftFieldType::T_LIST, + 7); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.recentMailedAddresses.ref().length()); + for(const auto & value: qAsConst(s.recentMailedAddresses.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.comments.isSet()) { + writer.writeFieldBegin( + QStringLiteral("comments"), + ThriftFieldType::T_STRING, + 9); + + writer.writeString(s.comments.ref()); + writer.writeFieldEnd(); + } + + if (s.dateAgreedToTermsOfService.isSet()) { + writer.writeFieldBegin( + QStringLiteral("dateAgreedToTermsOfService"), + ThriftFieldType::T_I64, + 11); + + writer.writeI64(s.dateAgreedToTermsOfService.ref()); + writer.writeFieldEnd(); + } + + if (s.maxReferrals.isSet()) { + writer.writeFieldBegin( + QStringLiteral("maxReferrals"), + ThriftFieldType::T_I32, + 12); + + writer.writeI32(s.maxReferrals.ref()); + writer.writeFieldEnd(); + } + + if (s.referralCount.isSet()) { + writer.writeFieldBegin( + QStringLiteral("referralCount"), + ThriftFieldType::T_I32, + 13); + + writer.writeI32(s.referralCount.ref()); + writer.writeFieldEnd(); + } + + if (s.refererCode.isSet()) { + writer.writeFieldBegin( + QStringLiteral("refererCode"), + ThriftFieldType::T_STRING, + 14); + + writer.writeString(s.refererCode.ref()); + writer.writeFieldEnd(); + } + + if (s.sentEmailDate.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sentEmailDate"), + ThriftFieldType::T_I64, + 15); + + writer.writeI64(s.sentEmailDate.ref()); + writer.writeFieldEnd(); + } + + if (s.sentEmailCount.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sentEmailCount"), + ThriftFieldType::T_I32, + 16); + + writer.writeI32(s.sentEmailCount.ref()); + writer.writeFieldEnd(); + } + + if (s.dailyEmailLimit.isSet()) { + writer.writeFieldBegin( + QStringLiteral("dailyEmailLimit"), + ThriftFieldType::T_I32, + 17); + + writer.writeI32(s.dailyEmailLimit.ref()); + writer.writeFieldEnd(); + } + + if (s.emailOptOutDate.isSet()) { + writer.writeFieldBegin( + QStringLiteral("emailOptOutDate"), + ThriftFieldType::T_I64, + 18); + + writer.writeI64(s.emailOptOutDate.ref()); + writer.writeFieldEnd(); + } + + if (s.partnerEmailOptInDate.isSet()) { + writer.writeFieldBegin( + QStringLiteral("partnerEmailOptInDate"), + ThriftFieldType::T_I64, + 19); + + writer.writeI64(s.partnerEmailOptInDate.ref()); + writer.writeFieldEnd(); + } + + if (s.preferredLanguage.isSet()) { + writer.writeFieldBegin( + QStringLiteral("preferredLanguage"), + ThriftFieldType::T_STRING, + 20); + + writer.writeString(s.preferredLanguage.ref()); + writer.writeFieldEnd(); + } + + if (s.preferredCountry.isSet()) { + writer.writeFieldBegin( + QStringLiteral("preferredCountry"), + ThriftFieldType::T_STRING, + 21); + + writer.writeString(s.preferredCountry.ref()); + writer.writeFieldEnd(); + } + + if (s.clipFullPage.isSet()) { + writer.writeFieldBegin( + QStringLiteral("clipFullPage"), + ThriftFieldType::T_BOOL, + 22); + + writer.writeBool(s.clipFullPage.ref()); + writer.writeFieldEnd(); + } + + if (s.twitterUserName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("twitterUserName"), + ThriftFieldType::T_STRING, + 23); + + writer.writeString(s.twitterUserName.ref()); + writer.writeFieldEnd(); + } + + if (s.twitterId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("twitterId"), + ThriftFieldType::T_STRING, + 24); + + writer.writeString(s.twitterId.ref()); + writer.writeFieldEnd(); + } + + if (s.groupName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("groupName"), + ThriftFieldType::T_STRING, + 25); + + writer.writeString(s.groupName.ref()); + writer.writeFieldEnd(); + } + + if (s.recognitionLanguage.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recognitionLanguage"), + ThriftFieldType::T_STRING, + 26); + + writer.writeString(s.recognitionLanguage.ref()); + writer.writeFieldEnd(); + } + + if (s.referralProof.isSet()) { + writer.writeFieldBegin( + QStringLiteral("referralProof"), + ThriftFieldType::T_STRING, + 28); + + writer.writeString(s.referralProof.ref()); + writer.writeFieldEnd(); + } + + if (s.educationalDiscount.isSet()) { + writer.writeFieldBegin( + QStringLiteral("educationalDiscount"), + ThriftFieldType::T_BOOL, + 29); + + writer.writeBool(s.educationalDiscount.ref()); + writer.writeFieldEnd(); + } + + if (s.businessAddress.isSet()) { + writer.writeFieldBegin( + QStringLiteral("businessAddress"), + ThriftFieldType::T_STRING, + 30); + + writer.writeString(s.businessAddress.ref()); + writer.writeFieldEnd(); + } + + if (s.hideSponsorBilling.isSet()) { + writer.writeFieldBegin( + QStringLiteral("hideSponsorBilling"), + ThriftFieldType::T_BOOL, + 31); + + writer.writeBool(s.hideSponsorBilling.ref()); + writer.writeFieldEnd(); + } + + if (s.useEmailAutoFiling.isSet()) { + writer.writeFieldBegin( + QStringLiteral("useEmailAutoFiling"), + ThriftFieldType::T_BOOL, + 33); + + writer.writeBool(s.useEmailAutoFiling.ref()); + writer.writeFieldEnd(); + } + + if (s.reminderEmailConfig.isSet()) { + writer.writeFieldBegin( + QStringLiteral("reminderEmailConfig"), + ThriftFieldType::T_I32, + 34); + + writer.writeI32(static_cast(s.reminderEmailConfig.ref())); + writer.writeFieldEnd(); + } + + if (s.emailAddressLastConfirmed.isSet()) { + writer.writeFieldBegin( + QStringLiteral("emailAddressLastConfirmed"), + ThriftFieldType::T_I64, + 35); + + writer.writeI64(s.emailAddressLastConfirmed.ref()); + writer.writeFieldEnd(); + } + + if (s.passwordUpdated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("passwordUpdated"), + ThriftFieldType::T_I64, + 36); + + writer.writeI64(s.passwordUpdated.ref()); + writer.writeFieldEnd(); + } + + if (s.salesforcePushEnabled.isSet()) { + writer.writeFieldBegin( + QStringLiteral("salesforcePushEnabled"), + ThriftFieldType::T_BOOL, + 37); + + writer.writeBool(s.salesforcePushEnabled.ref()); + writer.writeFieldEnd(); + } + + if (s.shouldLogClientEvent.isSet()) { + writer.writeFieldBegin( + QStringLiteral("shouldLogClientEvent"), + ThriftFieldType::T_BOOL, + 38); + + writer.writeBool(s.shouldLogClientEvent.ref()); + writer.writeFieldEnd(); + } + + if (s.optOutMachineLearning.isSet()) { + writer.writeFieldBegin( + QStringLiteral("optOutMachineLearning"), + ThriftFieldType::T_BOOL, + 39); + + writer.writeBool(s.optOutMachineLearning.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readUserAttributes( + ThriftBinaryBufferReader & reader, + UserAttributes & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.defaultLocationName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_DOUBLE) { + double v; + reader.readDouble(v); + s.defaultLatitude = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_DOUBLE) { + double v; + reader.readDouble(v); + s.defaultLongitude = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.preactivation = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_LIST) { + QStringList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (UserAttributes.viewedPromotions)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.viewedPromotions = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.incomingEmailAddress = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_LIST) { + QStringList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (UserAttributes.recentMailedAddresses)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.recentMailedAddresses = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.comments = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.dateAgreedToTermsOfService = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.maxReferrals = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.referralCount = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 14) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.refererCode = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 15) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.sentEmailDate = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 16) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.sentEmailCount = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 17) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.dailyEmailLimit = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 18) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.emailOptOutDate = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 19) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.partnerEmailOptInDate = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 20) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.preferredLanguage = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 21) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.preferredCountry = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 22) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.clipFullPage = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 23) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.twitterUserName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 24) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.twitterId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 25) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.groupName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 26) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.recognitionLanguage = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 28) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.referralProof = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 29) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.educationalDiscount = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 30) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.businessAddress = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 31) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.hideSponsorBilling = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 33) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.useEmailAutoFiling = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 34) { + if (fieldType == ThriftFieldType::T_I32) { + ReminderEmailConfig v; + readEnumReminderEmailConfig(reader, v); + s.reminderEmailConfig = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 35) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.emailAddressLastConfirmed = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 36) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.passwordUpdated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 37) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.salesforcePushEnabled = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 38) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.shouldLogClientEvent = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 39) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.optOutMachineLearning = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void UserAttributes::print(QTextStream & strm) const +{ + strm << "UserAttributes: {\n"; + localData.print(strm); + + if (defaultLocationName.isSet()) { + strm << " defaultLocationName = " + << defaultLocationName.ref() << "\n"; + } + else { + strm << " defaultLocationName is not set\n"; + } + + if (defaultLatitude.isSet()) { + strm << " defaultLatitude = " + << defaultLatitude.ref() << "\n"; + } + else { + strm << " defaultLatitude is not set\n"; + } + + if (defaultLongitude.isSet()) { + strm << " defaultLongitude = " + << defaultLongitude.ref() << "\n"; + } + else { + strm << " defaultLongitude is not set\n"; + } + + if (preactivation.isSet()) { + strm << " preactivation = " + << preactivation.ref() << "\n"; + } + else { + strm << " preactivation is not set\n"; + } + + if (viewedPromotions.isSet()) { + strm << " viewedPromotions = " + << "QList {"; + for(const auto & v: viewedPromotions.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " viewedPromotions is not set\n"; + } + + if (incomingEmailAddress.isSet()) { + strm << " incomingEmailAddress = " + << incomingEmailAddress.ref() << "\n"; + } + else { + strm << " incomingEmailAddress is not set\n"; + } + + if (recentMailedAddresses.isSet()) { + strm << " recentMailedAddresses = " + << "QList {"; + for(const auto & v: recentMailedAddresses.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " recentMailedAddresses is not set\n"; + } + + if (comments.isSet()) { + strm << " comments = " + << comments.ref() << "\n"; + } + else { + strm << " comments is not set\n"; + } + + if (dateAgreedToTermsOfService.isSet()) { + strm << " dateAgreedToTermsOfService = " + << dateAgreedToTermsOfService.ref() << "\n"; + } + else { + strm << " dateAgreedToTermsOfService is not set\n"; + } + + if (maxReferrals.isSet()) { + strm << " maxReferrals = " + << maxReferrals.ref() << "\n"; + } + else { + strm << " maxReferrals is not set\n"; + } + + if (referralCount.isSet()) { + strm << " referralCount = " + << referralCount.ref() << "\n"; + } + else { + strm << " referralCount is not set\n"; + } + + if (refererCode.isSet()) { + strm << " refererCode = " + << refererCode.ref() << "\n"; + } + else { + strm << " refererCode is not set\n"; + } + + if (sentEmailDate.isSet()) { + strm << " sentEmailDate = " + << sentEmailDate.ref() << "\n"; + } + else { + strm << " sentEmailDate is not set\n"; + } + + if (sentEmailCount.isSet()) { + strm << " sentEmailCount = " + << sentEmailCount.ref() << "\n"; + } + else { + strm << " sentEmailCount is not set\n"; + } + + if (dailyEmailLimit.isSet()) { + strm << " dailyEmailLimit = " + << dailyEmailLimit.ref() << "\n"; + } + else { + strm << " dailyEmailLimit is not set\n"; + } + + if (emailOptOutDate.isSet()) { + strm << " emailOptOutDate = " + << emailOptOutDate.ref() << "\n"; + } + else { + strm << " emailOptOutDate is not set\n"; + } + + if (partnerEmailOptInDate.isSet()) { + strm << " partnerEmailOptInDate = " + << partnerEmailOptInDate.ref() << "\n"; + } + else { + strm << " partnerEmailOptInDate is not set\n"; + } + + if (preferredLanguage.isSet()) { + strm << " preferredLanguage = " + << preferredLanguage.ref() << "\n"; + } + else { + strm << " preferredLanguage is not set\n"; + } + + if (preferredCountry.isSet()) { + strm << " preferredCountry = " + << preferredCountry.ref() << "\n"; + } + else { + strm << " preferredCountry is not set\n"; + } + + if (clipFullPage.isSet()) { + strm << " clipFullPage = " + << clipFullPage.ref() << "\n"; + } + else { + strm << " clipFullPage is not set\n"; + } + + if (twitterUserName.isSet()) { + strm << " twitterUserName = " + << twitterUserName.ref() << "\n"; + } + else { + strm << " twitterUserName is not set\n"; + } + + if (twitterId.isSet()) { + strm << " twitterId = " + << twitterId.ref() << "\n"; + } + else { + strm << " twitterId is not set\n"; + } + + if (groupName.isSet()) { + strm << " groupName = " + << groupName.ref() << "\n"; + } + else { + strm << " groupName is not set\n"; + } + + if (recognitionLanguage.isSet()) { + strm << " recognitionLanguage = " + << recognitionLanguage.ref() << "\n"; + } + else { + strm << " recognitionLanguage is not set\n"; + } + + if (referralProof.isSet()) { + strm << " referralProof = " + << referralProof.ref() << "\n"; + } + else { + strm << " referralProof is not set\n"; + } + + if (educationalDiscount.isSet()) { + strm << " educationalDiscount = " + << educationalDiscount.ref() << "\n"; + } + else { + strm << " educationalDiscount is not set\n"; + } + + if (businessAddress.isSet()) { + strm << " businessAddress = " + << businessAddress.ref() << "\n"; + } + else { + strm << " businessAddress is not set\n"; + } + + if (hideSponsorBilling.isSet()) { + strm << " hideSponsorBilling = " + << hideSponsorBilling.ref() << "\n"; + } + else { + strm << " hideSponsorBilling is not set\n"; + } + + if (useEmailAutoFiling.isSet()) { + strm << " useEmailAutoFiling = " + << useEmailAutoFiling.ref() << "\n"; + } + else { + strm << " useEmailAutoFiling is not set\n"; + } + + if (reminderEmailConfig.isSet()) { + strm << " reminderEmailConfig = " + << reminderEmailConfig.ref() << "\n"; + } + else { + strm << " reminderEmailConfig is not set\n"; + } + + if (emailAddressLastConfirmed.isSet()) { + strm << " emailAddressLastConfirmed = " + << emailAddressLastConfirmed.ref() << "\n"; + } + else { + strm << " emailAddressLastConfirmed is not set\n"; + } + + if (passwordUpdated.isSet()) { + strm << " passwordUpdated = " + << passwordUpdated.ref() << "\n"; + } + else { + strm << " passwordUpdated is not set\n"; + } + + if (salesforcePushEnabled.isSet()) { + strm << " salesforcePushEnabled = " + << salesforcePushEnabled.ref() << "\n"; + } + else { + strm << " salesforcePushEnabled is not set\n"; + } + + if (shouldLogClientEvent.isSet()) { + strm << " shouldLogClientEvent = " + << shouldLogClientEvent.ref() << "\n"; + } + else { + strm << " shouldLogClientEvent is not set\n"; + } + + if (optOutMachineLearning.isSet()) { + strm << " optOutMachineLearning = " + << optOutMachineLearning.ref() << "\n"; + } + else { + strm << " optOutMachineLearning is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeBusinessUserAttributes( + ThriftBinaryBufferWriter & writer, + const BusinessUserAttributes & s) +{ + writer.writeStructBegin(QStringLiteral("BusinessUserAttributes")); + if (s.title.isSet()) { + writer.writeFieldBegin( + QStringLiteral("title"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.title.ref()); + writer.writeFieldEnd(); + } + + if (s.location.isSet()) { + writer.writeFieldBegin( + QStringLiteral("location"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.location.ref()); + writer.writeFieldEnd(); + } + + if (s.department.isSet()) { + writer.writeFieldBegin( + QStringLiteral("department"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.department.ref()); + writer.writeFieldEnd(); + } + + if (s.mobilePhone.isSet()) { + writer.writeFieldBegin( + QStringLiteral("mobilePhone"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.mobilePhone.ref()); + writer.writeFieldEnd(); + } + + if (s.linkedInProfileUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("linkedInProfileUrl"), + ThriftFieldType::T_STRING, + 5); + + writer.writeString(s.linkedInProfileUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.workPhone.isSet()) { + writer.writeFieldBegin( + QStringLiteral("workPhone"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.workPhone.ref()); + writer.writeFieldEnd(); + } + + if (s.companyStartDate.isSet()) { + writer.writeFieldBegin( + QStringLiteral("companyStartDate"), + ThriftFieldType::T_I64, + 7); + + writer.writeI64(s.companyStartDate.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readBusinessUserAttributes( + ThriftBinaryBufferReader & reader, + BusinessUserAttributes & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.title = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.location = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.department = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.mobilePhone = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.linkedInProfileUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.workPhone = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.companyStartDate = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void BusinessUserAttributes::print(QTextStream & strm) const +{ + strm << "BusinessUserAttributes: {\n"; + localData.print(strm); + + if (title.isSet()) { + strm << " title = " + << title.ref() << "\n"; + } + else { + strm << " title is not set\n"; + } + + if (location.isSet()) { + strm << " location = " + << location.ref() << "\n"; + } + else { + strm << " location is not set\n"; + } + + if (department.isSet()) { + strm << " department = " + << department.ref() << "\n"; + } + else { + strm << " department is not set\n"; + } + + if (mobilePhone.isSet()) { + strm << " mobilePhone = " + << mobilePhone.ref() << "\n"; + } + else { + strm << " mobilePhone is not set\n"; + } + + if (linkedInProfileUrl.isSet()) { + strm << " linkedInProfileUrl = " + << linkedInProfileUrl.ref() << "\n"; + } + else { + strm << " linkedInProfileUrl is not set\n"; + } + + if (workPhone.isSet()) { + strm << " workPhone = " + << workPhone.ref() << "\n"; + } + else { + strm << " workPhone is not set\n"; + } + + if (companyStartDate.isSet()) { + strm << " companyStartDate = " + << companyStartDate.ref() << "\n"; + } + else { + strm << " companyStartDate is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeAccounting( + ThriftBinaryBufferWriter & writer, + const Accounting & s) +{ + writer.writeStructBegin(QStringLiteral("Accounting")); + if (s.uploadLimitEnd.isSet()) { + writer.writeFieldBegin( + QStringLiteral("uploadLimitEnd"), + ThriftFieldType::T_I64, + 2); + + writer.writeI64(s.uploadLimitEnd.ref()); + writer.writeFieldEnd(); + } + + if (s.uploadLimitNextMonth.isSet()) { + writer.writeFieldBegin( + QStringLiteral("uploadLimitNextMonth"), + ThriftFieldType::T_I64, + 3); + + writer.writeI64(s.uploadLimitNextMonth.ref()); + writer.writeFieldEnd(); + } + + if (s.premiumServiceStatus.isSet()) { + writer.writeFieldBegin( + QStringLiteral("premiumServiceStatus"), + ThriftFieldType::T_I32, + 4); + + writer.writeI32(static_cast(s.premiumServiceStatus.ref())); + writer.writeFieldEnd(); + } + + if (s.premiumOrderNumber.isSet()) { + writer.writeFieldBegin( + QStringLiteral("premiumOrderNumber"), + ThriftFieldType::T_STRING, + 5); + + writer.writeString(s.premiumOrderNumber.ref()); + writer.writeFieldEnd(); + } + + if (s.premiumCommerceService.isSet()) { + writer.writeFieldBegin( + QStringLiteral("premiumCommerceService"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.premiumCommerceService.ref()); + writer.writeFieldEnd(); + } + + if (s.premiumServiceStart.isSet()) { + writer.writeFieldBegin( + QStringLiteral("premiumServiceStart"), + ThriftFieldType::T_I64, + 7); + + writer.writeI64(s.premiumServiceStart.ref()); + writer.writeFieldEnd(); + } + + if (s.premiumServiceSKU.isSet()) { + writer.writeFieldBegin( + QStringLiteral("premiumServiceSKU"), + ThriftFieldType::T_STRING, + 8); + + writer.writeString(s.premiumServiceSKU.ref()); + writer.writeFieldEnd(); + } + + if (s.lastSuccessfulCharge.isSet()) { + writer.writeFieldBegin( + QStringLiteral("lastSuccessfulCharge"), + ThriftFieldType::T_I64, + 9); + + writer.writeI64(s.lastSuccessfulCharge.ref()); + writer.writeFieldEnd(); + } + + if (s.lastFailedCharge.isSet()) { + writer.writeFieldBegin( + QStringLiteral("lastFailedCharge"), + ThriftFieldType::T_I64, + 10); + + writer.writeI64(s.lastFailedCharge.ref()); + writer.writeFieldEnd(); + } + + if (s.lastFailedChargeReason.isSet()) { + writer.writeFieldBegin( + QStringLiteral("lastFailedChargeReason"), + ThriftFieldType::T_STRING, + 11); + + writer.writeString(s.lastFailedChargeReason.ref()); + writer.writeFieldEnd(); + } + + if (s.nextPaymentDue.isSet()) { + writer.writeFieldBegin( + QStringLiteral("nextPaymentDue"), + ThriftFieldType::T_I64, + 12); + + writer.writeI64(s.nextPaymentDue.ref()); + writer.writeFieldEnd(); + } + + if (s.premiumLockUntil.isSet()) { + writer.writeFieldBegin( + QStringLiteral("premiumLockUntil"), + ThriftFieldType::T_I64, + 13); + + writer.writeI64(s.premiumLockUntil.ref()); + writer.writeFieldEnd(); + } + + if (s.updated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updated"), + ThriftFieldType::T_I64, + 14); + + writer.writeI64(s.updated.ref()); + writer.writeFieldEnd(); + } + + if (s.premiumSubscriptionNumber.isSet()) { + writer.writeFieldBegin( + QStringLiteral("premiumSubscriptionNumber"), + ThriftFieldType::T_STRING, + 16); + + writer.writeString(s.premiumSubscriptionNumber.ref()); + writer.writeFieldEnd(); + } + + if (s.lastRequestedCharge.isSet()) { + writer.writeFieldBegin( + QStringLiteral("lastRequestedCharge"), + ThriftFieldType::T_I64, + 17); + + writer.writeI64(s.lastRequestedCharge.ref()); + writer.writeFieldEnd(); + } + + if (s.currency.isSet()) { + writer.writeFieldBegin( + QStringLiteral("currency"), + ThriftFieldType::T_STRING, + 18); + + writer.writeString(s.currency.ref()); + writer.writeFieldEnd(); + } + + if (s.unitPrice.isSet()) { + writer.writeFieldBegin( + QStringLiteral("unitPrice"), + ThriftFieldType::T_I32, + 19); + + writer.writeI32(s.unitPrice.ref()); + writer.writeFieldEnd(); + } + + if (s.businessId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("businessId"), + ThriftFieldType::T_I32, + 20); + + writer.writeI32(s.businessId.ref()); + writer.writeFieldEnd(); + } + + if (s.businessName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("businessName"), + ThriftFieldType::T_STRING, + 21); + + writer.writeString(s.businessName.ref()); + writer.writeFieldEnd(); + } + + if (s.businessRole.isSet()) { + writer.writeFieldBegin( + QStringLiteral("businessRole"), + ThriftFieldType::T_I32, + 22); + + writer.writeI32(static_cast(s.businessRole.ref())); + writer.writeFieldEnd(); + } + + if (s.unitDiscount.isSet()) { + writer.writeFieldBegin( + QStringLiteral("unitDiscount"), + ThriftFieldType::T_I32, + 23); + + writer.writeI32(s.unitDiscount.ref()); + writer.writeFieldEnd(); + } + + if (s.nextChargeDate.isSet()) { + writer.writeFieldBegin( + QStringLiteral("nextChargeDate"), + ThriftFieldType::T_I64, + 24); + + writer.writeI64(s.nextChargeDate.ref()); + writer.writeFieldEnd(); + } + + if (s.availablePoints.isSet()) { + writer.writeFieldBegin( + QStringLiteral("availablePoints"), + ThriftFieldType::T_I32, + 25); + + writer.writeI32(s.availablePoints.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readAccounting( + ThriftBinaryBufferReader & reader, + Accounting & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.uploadLimitEnd = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.uploadLimitNextMonth = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_I32) { + PremiumOrderStatus v; + readEnumPremiumOrderStatus(reader, v); + s.premiumServiceStatus = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.premiumOrderNumber = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.premiumCommerceService = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.premiumServiceStart = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.premiumServiceSKU = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.lastSuccessfulCharge = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.lastFailedCharge = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.lastFailedChargeReason = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.nextPaymentDue = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.premiumLockUntil = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 14) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.updated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 16) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.premiumSubscriptionNumber = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 17) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.lastRequestedCharge = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 18) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.currency = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 19) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.unitPrice = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 20) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.businessId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 21) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.businessName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 22) { + if (fieldType == ThriftFieldType::T_I32) { + BusinessUserRole v; + readEnumBusinessUserRole(reader, v); + s.businessRole = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 23) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.unitDiscount = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 24) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.nextChargeDate = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 25) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.availablePoints = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void Accounting::print(QTextStream & strm) const +{ + strm << "Accounting: {\n"; + localData.print(strm); + + if (uploadLimitEnd.isSet()) { + strm << " uploadLimitEnd = " + << uploadLimitEnd.ref() << "\n"; + } + else { + strm << " uploadLimitEnd is not set\n"; + } + + if (uploadLimitNextMonth.isSet()) { + strm << " uploadLimitNextMonth = " + << uploadLimitNextMonth.ref() << "\n"; + } + else { + strm << " uploadLimitNextMonth is not set\n"; + } + + if (premiumServiceStatus.isSet()) { + strm << " premiumServiceStatus = " + << premiumServiceStatus.ref() << "\n"; + } + else { + strm << " premiumServiceStatus is not set\n"; + } + + if (premiumOrderNumber.isSet()) { + strm << " premiumOrderNumber = " + << premiumOrderNumber.ref() << "\n"; + } + else { + strm << " premiumOrderNumber is not set\n"; + } + + if (premiumCommerceService.isSet()) { + strm << " premiumCommerceService = " + << premiumCommerceService.ref() << "\n"; + } + else { + strm << " premiumCommerceService is not set\n"; + } + + if (premiumServiceStart.isSet()) { + strm << " premiumServiceStart = " + << premiumServiceStart.ref() << "\n"; + } + else { + strm << " premiumServiceStart is not set\n"; + } + + if (premiumServiceSKU.isSet()) { + strm << " premiumServiceSKU = " + << premiumServiceSKU.ref() << "\n"; + } + else { + strm << " premiumServiceSKU is not set\n"; + } + + if (lastSuccessfulCharge.isSet()) { + strm << " lastSuccessfulCharge = " + << lastSuccessfulCharge.ref() << "\n"; + } + else { + strm << " lastSuccessfulCharge is not set\n"; + } + + if (lastFailedCharge.isSet()) { + strm << " lastFailedCharge = " + << lastFailedCharge.ref() << "\n"; + } + else { + strm << " lastFailedCharge is not set\n"; + } + + if (lastFailedChargeReason.isSet()) { + strm << " lastFailedChargeReason = " + << lastFailedChargeReason.ref() << "\n"; + } + else { + strm << " lastFailedChargeReason is not set\n"; + } + + if (nextPaymentDue.isSet()) { + strm << " nextPaymentDue = " + << nextPaymentDue.ref() << "\n"; + } + else { + strm << " nextPaymentDue is not set\n"; + } + + if (premiumLockUntil.isSet()) { + strm << " premiumLockUntil = " + << premiumLockUntil.ref() << "\n"; + } + else { + strm << " premiumLockUntil is not set\n"; + } + + if (updated.isSet()) { + strm << " updated = " + << updated.ref() << "\n"; + } + else { + strm << " updated is not set\n"; + } + + if (premiumSubscriptionNumber.isSet()) { + strm << " premiumSubscriptionNumber = " + << premiumSubscriptionNumber.ref() << "\n"; + } + else { + strm << " premiumSubscriptionNumber is not set\n"; + } + + if (lastRequestedCharge.isSet()) { + strm << " lastRequestedCharge = " + << lastRequestedCharge.ref() << "\n"; + } + else { + strm << " lastRequestedCharge is not set\n"; + } + + if (currency.isSet()) { + strm << " currency = " + << currency.ref() << "\n"; + } + else { + strm << " currency is not set\n"; + } + + if (unitPrice.isSet()) { + strm << " unitPrice = " + << unitPrice.ref() << "\n"; + } + else { + strm << " unitPrice is not set\n"; + } + + if (businessId.isSet()) { + strm << " businessId = " + << businessId.ref() << "\n"; + } + else { + strm << " businessId is not set\n"; + } + + if (businessName.isSet()) { + strm << " businessName = " + << businessName.ref() << "\n"; + } + else { + strm << " businessName is not set\n"; + } + + if (businessRole.isSet()) { + strm << " businessRole = " + << businessRole.ref() << "\n"; + } + else { + strm << " businessRole is not set\n"; + } + + if (unitDiscount.isSet()) { + strm << " unitDiscount = " + << unitDiscount.ref() << "\n"; + } + else { + strm << " unitDiscount is not set\n"; + } + + if (nextChargeDate.isSet()) { + strm << " nextChargeDate = " + << nextChargeDate.ref() << "\n"; + } + else { + strm << " nextChargeDate is not set\n"; + } + + if (availablePoints.isSet()) { + strm << " availablePoints = " + << availablePoints.ref() << "\n"; + } + else { + strm << " availablePoints is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeBusinessUserInfo( + ThriftBinaryBufferWriter & writer, + const BusinessUserInfo & s) +{ + writer.writeStructBegin(QStringLiteral("BusinessUserInfo")); + if (s.businessId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("businessId"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.businessId.ref()); + writer.writeFieldEnd(); + } + + if (s.businessName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("businessName"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.businessName.ref()); + writer.writeFieldEnd(); + } + + if (s.role.isSet()) { + writer.writeFieldBegin( + QStringLiteral("role"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(static_cast(s.role.ref())); + writer.writeFieldEnd(); + } + + if (s.email.isSet()) { + writer.writeFieldBegin( + QStringLiteral("email"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.email.ref()); + writer.writeFieldEnd(); + } + + if (s.updated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updated"), + ThriftFieldType::T_I64, + 5); + + writer.writeI64(s.updated.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readBusinessUserInfo( + ThriftBinaryBufferReader & reader, + BusinessUserInfo & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.businessId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.businessName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + BusinessUserRole v; + readEnumBusinessUserRole(reader, v); + s.role = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.email = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.updated = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void BusinessUserInfo::print(QTextStream & strm) const +{ + strm << "BusinessUserInfo: {\n"; + localData.print(strm); + + if (businessId.isSet()) { + strm << " businessId = " + << businessId.ref() << "\n"; + } + else { + strm << " businessId is not set\n"; + } + + if (businessName.isSet()) { + strm << " businessName = " + << businessName.ref() << "\n"; + } + else { + strm << " businessName is not set\n"; + } + + if (role.isSet()) { + strm << " role = " + << role.ref() << "\n"; + } + else { + strm << " role is not set\n"; + } + + if (email.isSet()) { + strm << " email = " + << email.ref() << "\n"; + } + else { + strm << " email is not set\n"; + } + + if (updated.isSet()) { + strm << " updated = " + << updated.ref() << "\n"; + } + else { + strm << " updated is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeAccountLimits( + ThriftBinaryBufferWriter & writer, + const AccountLimits & s) +{ + writer.writeStructBegin(QStringLiteral("AccountLimits")); + if (s.userMailLimitDaily.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userMailLimitDaily"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.userMailLimitDaily.ref()); + writer.writeFieldEnd(); + } + + if (s.noteSizeMax.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteSizeMax"), + ThriftFieldType::T_I64, + 2); + + writer.writeI64(s.noteSizeMax.ref()); + writer.writeFieldEnd(); + } + + if (s.resourceSizeMax.isSet()) { + writer.writeFieldBegin( + QStringLiteral("resourceSizeMax"), + ThriftFieldType::T_I64, + 3); + + writer.writeI64(s.resourceSizeMax.ref()); + writer.writeFieldEnd(); + } + + if (s.userLinkedNotebookMax.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userLinkedNotebookMax"), + ThriftFieldType::T_I32, + 4); + + writer.writeI32(s.userLinkedNotebookMax.ref()); + writer.writeFieldEnd(); + } + + if (s.uploadLimit.isSet()) { + writer.writeFieldBegin( + QStringLiteral("uploadLimit"), + ThriftFieldType::T_I64, + 5); + + writer.writeI64(s.uploadLimit.ref()); + writer.writeFieldEnd(); + } + + if (s.userNoteCountMax.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userNoteCountMax"), + ThriftFieldType::T_I32, + 6); + + writer.writeI32(s.userNoteCountMax.ref()); + writer.writeFieldEnd(); + } + + if (s.userNotebookCountMax.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userNotebookCountMax"), + ThriftFieldType::T_I32, + 7); + + writer.writeI32(s.userNotebookCountMax.ref()); + writer.writeFieldEnd(); + } + + if (s.userTagCountMax.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userTagCountMax"), + ThriftFieldType::T_I32, + 8); + + writer.writeI32(s.userTagCountMax.ref()); + writer.writeFieldEnd(); + } + + if (s.noteTagCountMax.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteTagCountMax"), + ThriftFieldType::T_I32, + 9); + + writer.writeI32(s.noteTagCountMax.ref()); + writer.writeFieldEnd(); + } + + if (s.userSavedSearchesMax.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userSavedSearchesMax"), + ThriftFieldType::T_I32, + 10); + + writer.writeI32(s.userSavedSearchesMax.ref()); + writer.writeFieldEnd(); + } + + if (s.noteResourceCountMax.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteResourceCountMax"), + ThriftFieldType::T_I32, + 11); + + writer.writeI32(s.noteResourceCountMax.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readAccountLimits( + ThriftBinaryBufferReader & reader, + AccountLimits & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.userMailLimitDaily = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.noteSizeMax = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.resourceSizeMax = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.userLinkedNotebookMax = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.uploadLimit = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.userNoteCountMax = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.userNotebookCountMax = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.userTagCountMax = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.noteTagCountMax = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.userSavedSearchesMax = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.noteResourceCountMax = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void AccountLimits::print(QTextStream & strm) const +{ + strm << "AccountLimits: {\n"; + localData.print(strm); + + if (userMailLimitDaily.isSet()) { + strm << " userMailLimitDaily = " + << userMailLimitDaily.ref() << "\n"; + } + else { + strm << " userMailLimitDaily is not set\n"; + } + + if (noteSizeMax.isSet()) { + strm << " noteSizeMax = " + << noteSizeMax.ref() << "\n"; + } + else { + strm << " noteSizeMax is not set\n"; + } + + if (resourceSizeMax.isSet()) { + strm << " resourceSizeMax = " + << resourceSizeMax.ref() << "\n"; + } + else { + strm << " resourceSizeMax is not set\n"; + } + + if (userLinkedNotebookMax.isSet()) { + strm << " userLinkedNotebookMax = " + << userLinkedNotebookMax.ref() << "\n"; + } + else { + strm << " userLinkedNotebookMax is not set\n"; + } + + if (uploadLimit.isSet()) { + strm << " uploadLimit = " + << uploadLimit.ref() << "\n"; + } + else { + strm << " uploadLimit is not set\n"; + } + + if (userNoteCountMax.isSet()) { + strm << " userNoteCountMax = " + << userNoteCountMax.ref() << "\n"; + } + else { + strm << " userNoteCountMax is not set\n"; + } + + if (userNotebookCountMax.isSet()) { + strm << " userNotebookCountMax = " + << userNotebookCountMax.ref() << "\n"; + } + else { + strm << " userNotebookCountMax is not set\n"; + } + + if (userTagCountMax.isSet()) { + strm << " userTagCountMax = " + << userTagCountMax.ref() << "\n"; + } + else { + strm << " userTagCountMax is not set\n"; + } + + if (noteTagCountMax.isSet()) { + strm << " noteTagCountMax = " + << noteTagCountMax.ref() << "\n"; + } + else { + strm << " noteTagCountMax is not set\n"; + } + + if (userSavedSearchesMax.isSet()) { + strm << " userSavedSearchesMax = " + << userSavedSearchesMax.ref() << "\n"; + } + else { + strm << " userSavedSearchesMax is not set\n"; + } + + if (noteResourceCountMax.isSet()) { + strm << " noteResourceCountMax = " + << noteResourceCountMax.ref() << "\n"; + } + else { + strm << " noteResourceCountMax is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeUser( + ThriftBinaryBufferWriter & writer, + const User & s) +{ + writer.writeStructBegin(QStringLiteral("User")); + if (s.id.isSet()) { + writer.writeFieldBegin( + QStringLiteral("id"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.id.ref()); + writer.writeFieldEnd(); + } + + if (s.username.isSet()) { + writer.writeFieldBegin( + QStringLiteral("username"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.username.ref()); + writer.writeFieldEnd(); + } + + if (s.email.isSet()) { + writer.writeFieldBegin( + QStringLiteral("email"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.email.ref()); + writer.writeFieldEnd(); + } + + if (s.name.isSet()) { + writer.writeFieldBegin( + QStringLiteral("name"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.name.ref()); + writer.writeFieldEnd(); + } + + if (s.timezone.isSet()) { + writer.writeFieldBegin( + QStringLiteral("timezone"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.timezone.ref()); + writer.writeFieldEnd(); + } + + if (s.privilege.isSet()) { + writer.writeFieldBegin( + QStringLiteral("privilege"), + ThriftFieldType::T_I32, + 7); + + writer.writeI32(static_cast(s.privilege.ref())); + writer.writeFieldEnd(); + } + + if (s.serviceLevel.isSet()) { + writer.writeFieldBegin( + QStringLiteral("serviceLevel"), + ThriftFieldType::T_I32, + 21); + + writer.writeI32(static_cast(s.serviceLevel.ref())); + writer.writeFieldEnd(); + } + + if (s.created.isSet()) { + writer.writeFieldBegin( + QStringLiteral("created"), + ThriftFieldType::T_I64, + 9); + + writer.writeI64(s.created.ref()); + writer.writeFieldEnd(); + } + + if (s.updated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updated"), + ThriftFieldType::T_I64, + 10); + + writer.writeI64(s.updated.ref()); + writer.writeFieldEnd(); + } + + if (s.deleted.isSet()) { + writer.writeFieldBegin( + QStringLiteral("deleted"), + ThriftFieldType::T_I64, + 11); + + writer.writeI64(s.deleted.ref()); + writer.writeFieldEnd(); + } + + if (s.active.isSet()) { + writer.writeFieldBegin( + QStringLiteral("active"), + ThriftFieldType::T_BOOL, + 13); + + writer.writeBool(s.active.ref()); + writer.writeFieldEnd(); + } + + if (s.shardId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("shardId"), + ThriftFieldType::T_STRING, + 14); + + writer.writeString(s.shardId.ref()); + writer.writeFieldEnd(); + } + + if (s.attributes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("attributes"), + ThriftFieldType::T_STRUCT, + 15); + + writeUserAttributes(writer, s.attributes.ref()); + writer.writeFieldEnd(); + } + + if (s.accounting.isSet()) { + writer.writeFieldBegin( + QStringLiteral("accounting"), + ThriftFieldType::T_STRUCT, + 16); + + writeAccounting(writer, s.accounting.ref()); + writer.writeFieldEnd(); + } + + if (s.businessUserInfo.isSet()) { + writer.writeFieldBegin( + QStringLiteral("businessUserInfo"), + ThriftFieldType::T_STRUCT, + 18); + + writeBusinessUserInfo(writer, s.businessUserInfo.ref()); + writer.writeFieldEnd(); + } + + if (s.photoUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("photoUrl"), + ThriftFieldType::T_STRING, + 19); + + writer.writeString(s.photoUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.photoLastUpdated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("photoLastUpdated"), + ThriftFieldType::T_I64, + 20); + + writer.writeI64(s.photoLastUpdated.ref()); + writer.writeFieldEnd(); + } + + if (s.accountLimits.isSet()) { + writer.writeFieldBegin( + QStringLiteral("accountLimits"), + ThriftFieldType::T_STRUCT, + 22); + + writeAccountLimits(writer, s.accountLimits.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readUser( + ThriftBinaryBufferReader & reader, + User & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.id = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.username = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.email = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.name = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.timezone = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I32) { + PrivilegeLevel v; + readEnumPrivilegeLevel(reader, v); + s.privilege = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 21) { + if (fieldType == ThriftFieldType::T_I32) { + ServiceLevel v; + readEnumServiceLevel(reader, v); + s.serviceLevel = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.created = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.updated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.deleted = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.active = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 14) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.shardId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 15) { + if (fieldType == ThriftFieldType::T_STRUCT) { + UserAttributes v; + readUserAttributes(reader, v); + s.attributes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 16) { + if (fieldType == ThriftFieldType::T_STRUCT) { + Accounting v; + readAccounting(reader, v); + s.accounting = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 18) { + if (fieldType == ThriftFieldType::T_STRUCT) { + BusinessUserInfo v; + readBusinessUserInfo(reader, v); + s.businessUserInfo = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 19) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.photoUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 20) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.photoLastUpdated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 22) { + if (fieldType == ThriftFieldType::T_STRUCT) { + AccountLimits v; + readAccountLimits(reader, v); + s.accountLimits = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void User::print(QTextStream & strm) const +{ + strm << "User: {\n"; + localData.print(strm); + + if (id.isSet()) { + strm << " id = " + << id.ref() << "\n"; + } + else { + strm << " id is not set\n"; + } + + if (username.isSet()) { + strm << " username = " + << username.ref() << "\n"; + } + else { + strm << " username is not set\n"; + } + + if (email.isSet()) { + strm << " email = " + << email.ref() << "\n"; + } + else { + strm << " email is not set\n"; + } + + if (name.isSet()) { + strm << " name = " + << name.ref() << "\n"; + } + else { + strm << " name is not set\n"; + } + + if (timezone.isSet()) { + strm << " timezone = " + << timezone.ref() << "\n"; + } + else { + strm << " timezone is not set\n"; + } + + if (privilege.isSet()) { + strm << " privilege = " + << privilege.ref() << "\n"; + } + else { + strm << " privilege is not set\n"; + } + + if (serviceLevel.isSet()) { + strm << " serviceLevel = " + << serviceLevel.ref() << "\n"; + } + else { + strm << " serviceLevel is not set\n"; + } + + if (created.isSet()) { + strm << " created = " + << created.ref() << "\n"; + } + else { + strm << " created is not set\n"; + } + + if (updated.isSet()) { + strm << " updated = " + << updated.ref() << "\n"; + } + else { + strm << " updated is not set\n"; + } + + if (deleted.isSet()) { + strm << " deleted = " + << deleted.ref() << "\n"; + } + else { + strm << " deleted is not set\n"; + } + + if (active.isSet()) { + strm << " active = " + << active.ref() << "\n"; + } + else { + strm << " active is not set\n"; + } + + if (shardId.isSet()) { + strm << " shardId = " + << shardId.ref() << "\n"; + } + else { + strm << " shardId is not set\n"; + } + + if (attributes.isSet()) { + strm << " attributes = " + << attributes.ref() << "\n"; + } + else { + strm << " attributes is not set\n"; + } + + if (accounting.isSet()) { + strm << " accounting = " + << accounting.ref() << "\n"; + } + else { + strm << " accounting is not set\n"; + } + + if (businessUserInfo.isSet()) { + strm << " businessUserInfo = " + << businessUserInfo.ref() << "\n"; + } + else { + strm << " businessUserInfo is not set\n"; + } + + if (photoUrl.isSet()) { + strm << " photoUrl = " + << photoUrl.ref() << "\n"; + } + else { + strm << " photoUrl is not set\n"; + } + + if (photoLastUpdated.isSet()) { + strm << " photoLastUpdated = " + << photoLastUpdated.ref() << "\n"; + } + else { + strm << " photoLastUpdated is not set\n"; + } + + if (accountLimits.isSet()) { + strm << " accountLimits = " + << accountLimits.ref() << "\n"; + } + else { + strm << " accountLimits is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeContact( + ThriftBinaryBufferWriter & writer, + const Contact & s) +{ + writer.writeStructBegin(QStringLiteral("Contact")); + if (s.name.isSet()) { + writer.writeFieldBegin( + QStringLiteral("name"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.name.ref()); + writer.writeFieldEnd(); + } + + if (s.id.isSet()) { + writer.writeFieldBegin( + QStringLiteral("id"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.id.ref()); + writer.writeFieldEnd(); + } + + if (s.type.isSet()) { + writer.writeFieldBegin( + QStringLiteral("type"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(static_cast(s.type.ref())); + writer.writeFieldEnd(); + } + + if (s.photoUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("photoUrl"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.photoUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.photoLastUpdated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("photoLastUpdated"), + ThriftFieldType::T_I64, + 5); + + writer.writeI64(s.photoLastUpdated.ref()); + writer.writeFieldEnd(); + } + + if (s.messagingPermit.isSet()) { + writer.writeFieldBegin( + QStringLiteral("messagingPermit"), + ThriftFieldType::T_STRING, + 6); + + writer.writeBinary(s.messagingPermit.ref()); + writer.writeFieldEnd(); + } + + if (s.messagingPermitExpires.isSet()) { + writer.writeFieldBegin( + QStringLiteral("messagingPermitExpires"), + ThriftFieldType::T_I64, + 7); + + writer.writeI64(s.messagingPermitExpires.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readContact( + ThriftBinaryBufferReader & reader, + Contact & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.name = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.id = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + ContactType v; + readEnumContactType(reader, v); + s.type = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.photoUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.photoLastUpdated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QByteArray v; + reader.readBinary(v); + s.messagingPermit = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.messagingPermitExpires = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void Contact::print(QTextStream & strm) const +{ + strm << "Contact: {\n"; + localData.print(strm); + + if (name.isSet()) { + strm << " name = " + << name.ref() << "\n"; + } + else { + strm << " name is not set\n"; + } + + if (id.isSet()) { + strm << " id = " + << id.ref() << "\n"; + } + else { + strm << " id is not set\n"; + } + + if (type.isSet()) { + strm << " type = " + << type.ref() << "\n"; + } + else { + strm << " type is not set\n"; + } + + if (photoUrl.isSet()) { + strm << " photoUrl = " + << photoUrl.ref() << "\n"; + } + else { + strm << " photoUrl is not set\n"; + } + + if (photoLastUpdated.isSet()) { + strm << " photoLastUpdated = " + << photoLastUpdated.ref() << "\n"; + } + else { + strm << " photoLastUpdated is not set\n"; + } + + if (messagingPermit.isSet()) { + strm << " messagingPermit = " + << messagingPermit.ref() << "\n"; + } + else { + strm << " messagingPermit is not set\n"; + } + + if (messagingPermitExpires.isSet()) { + strm << " messagingPermitExpires = " + << messagingPermitExpires.ref() << "\n"; + } + else { + strm << " messagingPermitExpires is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeIdentity( + ThriftBinaryBufferWriter & writer, + const Identity & s) +{ + writer.writeStructBegin(QStringLiteral("Identity")); + writer.writeFieldBegin( + QStringLiteral("id"), + ThriftFieldType::T_I64, + 1); + + writer.writeI64(s.id); + writer.writeFieldEnd(); + + if (s.contact.isSet()) { + writer.writeFieldBegin( + QStringLiteral("contact"), + ThriftFieldType::T_STRUCT, + 2); + + writeContact(writer, s.contact.ref()); + writer.writeFieldEnd(); + } + + if (s.userId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userId"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(s.userId.ref()); + writer.writeFieldEnd(); + } + + if (s.deactivated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("deactivated"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(s.deactivated.ref()); + writer.writeFieldEnd(); + } + + if (s.sameBusiness.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sameBusiness"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(s.sameBusiness.ref()); + writer.writeFieldEnd(); + } + + if (s.blocked.isSet()) { + writer.writeFieldBegin( + QStringLiteral("blocked"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(s.blocked.ref()); + writer.writeFieldEnd(); + } + + if (s.userConnected.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userConnected"), + ThriftFieldType::T_BOOL, + 7); + + writer.writeBool(s.userConnected.ref()); + writer.writeFieldEnd(); + } + + if (s.eventId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("eventId"), + ThriftFieldType::T_I64, + 8); + + writer.writeI64(s.eventId.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readIdentity( + ThriftBinaryBufferReader & reader, + Identity & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool id_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I64) { + id_isset = true; + IdentityID v; + reader.readI64(v); + s.id = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRUCT) { + Contact v; + readContact(reader, v); + s.contact = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.userId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.deactivated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.sameBusiness = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.blocked = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.userConnected = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_I64) { + MessageEventID v; + reader.readI64(v); + s.eventId = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!id_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Identity.id has no value")); +} + +void Identity::print(QTextStream & strm) const +{ + strm << "Identity: {\n"; + localData.print(strm); + strm << " id = " + << id << "\n"; + + if (contact.isSet()) { + strm << " contact = " + << contact.ref() << "\n"; + } + else { + strm << " contact is not set\n"; + } + + if (userId.isSet()) { + strm << " userId = " + << userId.ref() << "\n"; + } + else { + strm << " userId is not set\n"; + } + + if (deactivated.isSet()) { + strm << " deactivated = " + << deactivated.ref() << "\n"; + } + else { + strm << " deactivated is not set\n"; + } + + if (sameBusiness.isSet()) { + strm << " sameBusiness = " + << sameBusiness.ref() << "\n"; + } + else { + strm << " sameBusiness is not set\n"; + } + + if (blocked.isSet()) { + strm << " blocked = " + << blocked.ref() << "\n"; + } + else { + strm << " blocked is not set\n"; + } + + if (userConnected.isSet()) { + strm << " userConnected = " + << userConnected.ref() << "\n"; + } + else { + strm << " userConnected is not set\n"; + } + + if (eventId.isSet()) { + strm << " eventId = " + << eventId.ref() << "\n"; + } + else { + strm << " eventId is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeTag( + ThriftBinaryBufferWriter & writer, + const Tag & s) +{ + writer.writeStructBegin(QStringLiteral("Tag")); + if (s.guid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.guid.ref()); + writer.writeFieldEnd(); + } + + if (s.name.isSet()) { + writer.writeFieldBegin( + QStringLiteral("name"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.name.ref()); + writer.writeFieldEnd(); + } + + if (s.parentGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("parentGuid"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.parentGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.updateSequenceNum.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updateSequenceNum"), + ThriftFieldType::T_I32, + 4); + + writer.writeI32(s.updateSequenceNum.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readTag( + ThriftBinaryBufferReader & reader, + Tag & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.guid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.name = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.parentGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.updateSequenceNum = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void Tag::print(QTextStream & strm) const +{ + strm << "Tag: {\n"; + localData.print(strm); + + if (guid.isSet()) { + strm << " guid = " + << guid.ref() << "\n"; + } + else { + strm << " guid is not set\n"; + } + + if (name.isSet()) { + strm << " name = " + << name.ref() << "\n"; + } + else { + strm << " name is not set\n"; + } + + if (parentGuid.isSet()) { + strm << " parentGuid = " + << parentGuid.ref() << "\n"; + } + else { + strm << " parentGuid is not set\n"; + } + + if (updateSequenceNum.isSet()) { + strm << " updateSequenceNum = " + << updateSequenceNum.ref() << "\n"; + } + else { + strm << " updateSequenceNum is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeLazyMap( + ThriftBinaryBufferWriter & writer, + const LazyMap & s) +{ + writer.writeStructBegin(QStringLiteral("LazyMap")); + if (s.keysOnly.isSet()) { + writer.writeFieldBegin( + QStringLiteral("keysOnly"), + ThriftFieldType::T_SET, + 1); + + writer.writeSetBegin(ThriftFieldType::T_STRING, s.keysOnly.ref().count()); + for(const auto & value: qAsConst(s.keysOnly.ref())) { + writer.writeString(value); + } + writer.writeSetEnd(); + + writer.writeFieldEnd(); + } + + if (s.fullMap.isSet()) { + writer.writeFieldBegin( + QStringLiteral("fullMap"), + ThriftFieldType::T_MAP, + 2); + + writer.writeMapBegin(ThriftFieldType::T_STRING, ThriftFieldType::T_STRING, s.fullMap.ref().size()); + for(const auto & it: toRange(s.fullMap.ref())) { + writer.writeString(it.key()); + writer.writeString(it.value()); + } + writer.writeMapEnd(); + + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readLazyMap( + ThriftBinaryBufferReader & reader, + LazyMap & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_SET) { + QSet v; + qint32 size; + ThriftFieldType elemType; + reader.readSetBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect set type (LazyMap.keysOnly)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.insert(elem); + } + reader.readSetEnd(); + s.keysOnly = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_MAP) { + QMap v; + qint32 size; + ThriftFieldType keyType; + ThriftFieldType elemType; + reader.readMapBegin(keyType, elemType, size); + if (keyType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map key type (LazyMap.fullMap)")); + if (elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map value type (LazyMap.fullMap)")); + for(qint32 i = 0; i < size; i++) { + QString key; + reader.readString(key); + QString value; + reader.readString(value); + v[key] = value; + } + reader.readMapEnd(); + s.fullMap = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void LazyMap::print(QTextStream & strm) const +{ + strm << "LazyMap: {\n"; + localData.print(strm); + + if (keysOnly.isSet()) { + strm << " keysOnly = " + << "QSet {"; + for(const auto & v: keysOnly.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " keysOnly is not set\n"; + } + + if (fullMap.isSet()) { + strm << " fullMap = " + << "QMap {"; + for(const auto & it: toRange(fullMap.ref())) { + strm << " [" << it.key() << "] = " << it.value() << "\n"; + } + strm << " }\n"; + } + else { + strm << " fullMap is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeResourceAttributes( + ThriftBinaryBufferWriter & writer, + const ResourceAttributes & s) +{ + writer.writeStructBegin(QStringLiteral("ResourceAttributes")); + if (s.sourceURL.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sourceURL"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.sourceURL.ref()); + writer.writeFieldEnd(); + } + + if (s.timestamp.isSet()) { + writer.writeFieldBegin( + QStringLiteral("timestamp"), + ThriftFieldType::T_I64, + 2); + + writer.writeI64(s.timestamp.ref()); + writer.writeFieldEnd(); + } + + if (s.latitude.isSet()) { + writer.writeFieldBegin( + QStringLiteral("latitude"), + ThriftFieldType::T_DOUBLE, + 3); + + writer.writeDouble(s.latitude.ref()); + writer.writeFieldEnd(); + } + + if (s.longitude.isSet()) { + writer.writeFieldBegin( + QStringLiteral("longitude"), + ThriftFieldType::T_DOUBLE, + 4); + + writer.writeDouble(s.longitude.ref()); + writer.writeFieldEnd(); + } + + if (s.altitude.isSet()) { + writer.writeFieldBegin( + QStringLiteral("altitude"), + ThriftFieldType::T_DOUBLE, + 5); + + writer.writeDouble(s.altitude.ref()); + writer.writeFieldEnd(); + } + + if (s.cameraMake.isSet()) { + writer.writeFieldBegin( + QStringLiteral("cameraMake"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.cameraMake.ref()); + writer.writeFieldEnd(); + } + + if (s.cameraModel.isSet()) { + writer.writeFieldBegin( + QStringLiteral("cameraModel"), + ThriftFieldType::T_STRING, + 7); + + writer.writeString(s.cameraModel.ref()); + writer.writeFieldEnd(); + } + + if (s.clientWillIndex.isSet()) { + writer.writeFieldBegin( + QStringLiteral("clientWillIndex"), + ThriftFieldType::T_BOOL, + 8); + + writer.writeBool(s.clientWillIndex.ref()); + writer.writeFieldEnd(); + } + + if (s.recoType.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recoType"), + ThriftFieldType::T_STRING, + 9); + + writer.writeString(s.recoType.ref()); + writer.writeFieldEnd(); + } + + if (s.fileName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("fileName"), + ThriftFieldType::T_STRING, + 10); + + writer.writeString(s.fileName.ref()); + writer.writeFieldEnd(); + } + + if (s.attachment.isSet()) { + writer.writeFieldBegin( + QStringLiteral("attachment"), + ThriftFieldType::T_BOOL, + 11); + + writer.writeBool(s.attachment.ref()); + writer.writeFieldEnd(); + } + + if (s.applicationData.isSet()) { + writer.writeFieldBegin( + QStringLiteral("applicationData"), + ThriftFieldType::T_STRUCT, + 12); + + writeLazyMap(writer, s.applicationData.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readResourceAttributes( + ThriftBinaryBufferReader & reader, + ResourceAttributes & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.sourceURL = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.timestamp = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_DOUBLE) { + double v; + reader.readDouble(v); + s.latitude = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_DOUBLE) { + double v; + reader.readDouble(v); + s.longitude = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_DOUBLE) { + double v; + reader.readDouble(v); + s.altitude = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.cameraMake = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.cameraModel = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.clientWillIndex = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.recoType = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.fileName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.attachment = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_STRUCT) { + LazyMap v; + readLazyMap(reader, v); + s.applicationData = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void ResourceAttributes::print(QTextStream & strm) const +{ + strm << "ResourceAttributes: {\n"; + localData.print(strm); + + if (sourceURL.isSet()) { + strm << " sourceURL = " + << sourceURL.ref() << "\n"; + } + else { + strm << " sourceURL is not set\n"; + } + + if (timestamp.isSet()) { + strm << " timestamp = " + << timestamp.ref() << "\n"; + } + else { + strm << " timestamp is not set\n"; + } + + if (latitude.isSet()) { + strm << " latitude = " + << latitude.ref() << "\n"; + } + else { + strm << " latitude is not set\n"; + } + + if (longitude.isSet()) { + strm << " longitude = " + << longitude.ref() << "\n"; + } + else { + strm << " longitude is not set\n"; + } + + if (altitude.isSet()) { + strm << " altitude = " + << altitude.ref() << "\n"; + } + else { + strm << " altitude is not set\n"; + } + + if (cameraMake.isSet()) { + strm << " cameraMake = " + << cameraMake.ref() << "\n"; + } + else { + strm << " cameraMake is not set\n"; + } + + if (cameraModel.isSet()) { + strm << " cameraModel = " + << cameraModel.ref() << "\n"; + } + else { + strm << " cameraModel is not set\n"; + } + + if (clientWillIndex.isSet()) { + strm << " clientWillIndex = " + << clientWillIndex.ref() << "\n"; + } + else { + strm << " clientWillIndex is not set\n"; + } + + if (recoType.isSet()) { + strm << " recoType = " + << recoType.ref() << "\n"; + } + else { + strm << " recoType is not set\n"; + } + + if (fileName.isSet()) { + strm << " fileName = " + << fileName.ref() << "\n"; + } + else { + strm << " fileName is not set\n"; + } + + if (attachment.isSet()) { + strm << " attachment = " + << attachment.ref() << "\n"; + } + else { + strm << " attachment is not set\n"; + } + + if (applicationData.isSet()) { + strm << " applicationData = " + << applicationData.ref() << "\n"; + } + else { + strm << " applicationData is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeResource( + ThriftBinaryBufferWriter & writer, + const Resource & s) +{ + writer.writeStructBegin(QStringLiteral("Resource")); + if (s.guid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.guid.ref()); + writer.writeFieldEnd(); + } + + if (s.noteGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteGuid"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.noteGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.data.isSet()) { + writer.writeFieldBegin( + QStringLiteral("data"), + ThriftFieldType::T_STRUCT, + 3); + + writeData(writer, s.data.ref()); + writer.writeFieldEnd(); + } + + if (s.mime.isSet()) { + writer.writeFieldBegin( + QStringLiteral("mime"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.mime.ref()); + writer.writeFieldEnd(); + } + + if (s.width.isSet()) { + writer.writeFieldBegin( + QStringLiteral("width"), + ThriftFieldType::T_I16, + 5); + + writer.writeI16(s.width.ref()); + writer.writeFieldEnd(); + } + + if (s.height.isSet()) { + writer.writeFieldBegin( + QStringLiteral("height"), + ThriftFieldType::T_I16, + 6); + + writer.writeI16(s.height.ref()); + writer.writeFieldEnd(); + } + + if (s.duration.isSet()) { + writer.writeFieldBegin( + QStringLiteral("duration"), + ThriftFieldType::T_I16, + 7); + + writer.writeI16(s.duration.ref()); + writer.writeFieldEnd(); + } + + if (s.active.isSet()) { + writer.writeFieldBegin( + QStringLiteral("active"), + ThriftFieldType::T_BOOL, + 8); + + writer.writeBool(s.active.ref()); + writer.writeFieldEnd(); + } + + if (s.recognition.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recognition"), + ThriftFieldType::T_STRUCT, + 9); + + writeData(writer, s.recognition.ref()); + writer.writeFieldEnd(); + } + + if (s.attributes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("attributes"), + ThriftFieldType::T_STRUCT, + 11); + + writeResourceAttributes(writer, s.attributes.ref()); + writer.writeFieldEnd(); + } + + if (s.updateSequenceNum.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updateSequenceNum"), + ThriftFieldType::T_I32, + 12); + + writer.writeI32(s.updateSequenceNum.ref()); + writer.writeFieldEnd(); + } + + if (s.alternateData.isSet()) { + writer.writeFieldBegin( + QStringLiteral("alternateData"), + ThriftFieldType::T_STRUCT, + 13); + + writeData(writer, s.alternateData.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readResource( + ThriftBinaryBufferReader & reader, + Resource & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.guid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.noteGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRUCT) { + Data v; + readData(reader, v); + s.data = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.mime = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I16) { + qint16 v; + reader.readI16(v); + s.width = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_I16) { + qint16 v; + reader.readI16(v); + s.height = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I16) { + qint16 v; + reader.readI16(v); + s.duration = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.active = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_STRUCT) { + Data v; + readData(reader, v); + s.recognition = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_STRUCT) { + ResourceAttributes v; + readResourceAttributes(reader, v); + s.attributes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.updateSequenceNum = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_STRUCT) { + Data v; + readData(reader, v); + s.alternateData = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void Resource::print(QTextStream & strm) const +{ + strm << "Resource: {\n"; + localData.print(strm); + + if (guid.isSet()) { + strm << " guid = " + << guid.ref() << "\n"; + } + else { + strm << " guid is not set\n"; + } + + if (noteGuid.isSet()) { + strm << " noteGuid = " + << noteGuid.ref() << "\n"; + } + else { + strm << " noteGuid is not set\n"; + } + + if (data.isSet()) { + strm << " data = " + << data.ref() << "\n"; + } + else { + strm << " data is not set\n"; + } + + if (mime.isSet()) { + strm << " mime = " + << mime.ref() << "\n"; + } + else { + strm << " mime is not set\n"; + } + + if (width.isSet()) { + strm << " width = " + << width.ref() << "\n"; + } + else { + strm << " width is not set\n"; + } + + if (height.isSet()) { + strm << " height = " + << height.ref() << "\n"; + } + else { + strm << " height is not set\n"; + } + + if (duration.isSet()) { + strm << " duration = " + << duration.ref() << "\n"; + } + else { + strm << " duration is not set\n"; + } + + if (active.isSet()) { + strm << " active = " + << active.ref() << "\n"; + } + else { + strm << " active is not set\n"; + } + + if (recognition.isSet()) { + strm << " recognition = " + << recognition.ref() << "\n"; + } + else { + strm << " recognition is not set\n"; + } + + if (attributes.isSet()) { + strm << " attributes = " + << attributes.ref() << "\n"; + } + else { + strm << " attributes is not set\n"; + } + + if (updateSequenceNum.isSet()) { + strm << " updateSequenceNum = " + << updateSequenceNum.ref() << "\n"; + } + else { + strm << " updateSequenceNum is not set\n"; + } + + if (alternateData.isSet()) { + strm << " alternateData = " + << alternateData.ref() << "\n"; + } + else { + strm << " alternateData is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteAttributes( + ThriftBinaryBufferWriter & writer, + const NoteAttributes & s) +{ + writer.writeStructBegin(QStringLiteral("NoteAttributes")); + if (s.subjectDate.isSet()) { + writer.writeFieldBegin( + QStringLiteral("subjectDate"), + ThriftFieldType::T_I64, + 1); + + writer.writeI64(s.subjectDate.ref()); + writer.writeFieldEnd(); + } + + if (s.latitude.isSet()) { + writer.writeFieldBegin( + QStringLiteral("latitude"), + ThriftFieldType::T_DOUBLE, + 10); + + writer.writeDouble(s.latitude.ref()); + writer.writeFieldEnd(); + } + + if (s.longitude.isSet()) { + writer.writeFieldBegin( + QStringLiteral("longitude"), + ThriftFieldType::T_DOUBLE, + 11); + + writer.writeDouble(s.longitude.ref()); + writer.writeFieldEnd(); + } + + if (s.altitude.isSet()) { + writer.writeFieldBegin( + QStringLiteral("altitude"), + ThriftFieldType::T_DOUBLE, + 12); + + writer.writeDouble(s.altitude.ref()); + writer.writeFieldEnd(); + } + + if (s.author.isSet()) { + writer.writeFieldBegin( + QStringLiteral("author"), + ThriftFieldType::T_STRING, + 13); + + writer.writeString(s.author.ref()); + writer.writeFieldEnd(); + } + + if (s.source.isSet()) { + writer.writeFieldBegin( + QStringLiteral("source"), + ThriftFieldType::T_STRING, + 14); + + writer.writeString(s.source.ref()); + writer.writeFieldEnd(); + } + + if (s.sourceURL.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sourceURL"), + ThriftFieldType::T_STRING, + 15); + + writer.writeString(s.sourceURL.ref()); + writer.writeFieldEnd(); + } + + if (s.sourceApplication.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sourceApplication"), + ThriftFieldType::T_STRING, + 16); + + writer.writeString(s.sourceApplication.ref()); + writer.writeFieldEnd(); + } + + if (s.shareDate.isSet()) { + writer.writeFieldBegin( + QStringLiteral("shareDate"), + ThriftFieldType::T_I64, + 17); + + writer.writeI64(s.shareDate.ref()); + writer.writeFieldEnd(); + } + + if (s.reminderOrder.isSet()) { + writer.writeFieldBegin( + QStringLiteral("reminderOrder"), + ThriftFieldType::T_I64, + 18); + + writer.writeI64(s.reminderOrder.ref()); + writer.writeFieldEnd(); + } + + if (s.reminderDoneTime.isSet()) { + writer.writeFieldBegin( + QStringLiteral("reminderDoneTime"), + ThriftFieldType::T_I64, + 19); + + writer.writeI64(s.reminderDoneTime.ref()); + writer.writeFieldEnd(); + } + + if (s.reminderTime.isSet()) { + writer.writeFieldBegin( + QStringLiteral("reminderTime"), + ThriftFieldType::T_I64, + 20); + + writer.writeI64(s.reminderTime.ref()); + writer.writeFieldEnd(); + } + + if (s.placeName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("placeName"), + ThriftFieldType::T_STRING, + 21); + + writer.writeString(s.placeName.ref()); + writer.writeFieldEnd(); + } + + if (s.contentClass.isSet()) { + writer.writeFieldBegin( + QStringLiteral("contentClass"), + ThriftFieldType::T_STRING, + 22); + + writer.writeString(s.contentClass.ref()); + writer.writeFieldEnd(); + } + + if (s.applicationData.isSet()) { + writer.writeFieldBegin( + QStringLiteral("applicationData"), + ThriftFieldType::T_STRUCT, + 23); + + writeLazyMap(writer, s.applicationData.ref()); + writer.writeFieldEnd(); + } + + if (s.lastEditedBy.isSet()) { + writer.writeFieldBegin( + QStringLiteral("lastEditedBy"), + ThriftFieldType::T_STRING, + 24); + + writer.writeString(s.lastEditedBy.ref()); + writer.writeFieldEnd(); + } + + if (s.classifications.isSet()) { + writer.writeFieldBegin( + QStringLiteral("classifications"), + ThriftFieldType::T_MAP, + 26); + + writer.writeMapBegin(ThriftFieldType::T_STRING, ThriftFieldType::T_STRING, s.classifications.ref().size()); + for(const auto & it: toRange(s.classifications.ref())) { + writer.writeString(it.key()); + writer.writeString(it.value()); + } + writer.writeMapEnd(); + + writer.writeFieldEnd(); + } + + if (s.creatorId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("creatorId"), + ThriftFieldType::T_I32, + 27); + + writer.writeI32(s.creatorId.ref()); + writer.writeFieldEnd(); + } + + if (s.lastEditorId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("lastEditorId"), + ThriftFieldType::T_I32, + 28); + + writer.writeI32(s.lastEditorId.ref()); + writer.writeFieldEnd(); + } + + if (s.sharedWithBusiness.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sharedWithBusiness"), + ThriftFieldType::T_BOOL, + 29); + + writer.writeBool(s.sharedWithBusiness.ref()); + writer.writeFieldEnd(); + } + + if (s.conflictSourceNoteGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("conflictSourceNoteGuid"), + ThriftFieldType::T_STRING, + 30); + + writer.writeString(s.conflictSourceNoteGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.noteTitleQuality.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteTitleQuality"), + ThriftFieldType::T_I32, + 31); + + writer.writeI32(s.noteTitleQuality.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteAttributes( + ThriftBinaryBufferReader & reader, + NoteAttributes & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.subjectDate = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_DOUBLE) { + double v; + reader.readDouble(v); + s.latitude = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_DOUBLE) { + double v; + reader.readDouble(v); + s.longitude = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_DOUBLE) { + double v; + reader.readDouble(v); + s.altitude = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.author = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 14) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.source = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 15) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.sourceURL = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 16) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.sourceApplication = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 17) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.shareDate = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 18) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.reminderOrder = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 19) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.reminderDoneTime = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 20) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.reminderTime = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 21) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.placeName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 22) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.contentClass = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 23) { + if (fieldType == ThriftFieldType::T_STRUCT) { + LazyMap v; + readLazyMap(reader, v); + s.applicationData = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 24) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.lastEditedBy = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 26) { + if (fieldType == ThriftFieldType::T_MAP) { + QMap v; + qint32 size; + ThriftFieldType keyType; + ThriftFieldType elemType; + reader.readMapBegin(keyType, elemType, size); + if (keyType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map key type (NoteAttributes.classifications)")); + if (elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map value type (NoteAttributes.classifications)")); + for(qint32 i = 0; i < size; i++) { + QString key; + reader.readString(key); + QString value; + reader.readString(value); + v[key] = value; + } + reader.readMapEnd(); + s.classifications = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 27) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.creatorId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 28) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.lastEditorId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 29) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.sharedWithBusiness = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 30) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.conflictSourceNoteGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 31) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.noteTitleQuality = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NoteAttributes::print(QTextStream & strm) const +{ + strm << "NoteAttributes: {\n"; + localData.print(strm); + + if (subjectDate.isSet()) { + strm << " subjectDate = " + << subjectDate.ref() << "\n"; + } + else { + strm << " subjectDate is not set\n"; + } + + if (latitude.isSet()) { + strm << " latitude = " + << latitude.ref() << "\n"; + } + else { + strm << " latitude is not set\n"; + } + + if (longitude.isSet()) { + strm << " longitude = " + << longitude.ref() << "\n"; + } + else { + strm << " longitude is not set\n"; + } + + if (altitude.isSet()) { + strm << " altitude = " + << altitude.ref() << "\n"; + } + else { + strm << " altitude is not set\n"; + } + + if (author.isSet()) { + strm << " author = " + << author.ref() << "\n"; + } + else { + strm << " author is not set\n"; + } + + if (source.isSet()) { + strm << " source = " + << source.ref() << "\n"; + } + else { + strm << " source is not set\n"; + } + + if (sourceURL.isSet()) { + strm << " sourceURL = " + << sourceURL.ref() << "\n"; + } + else { + strm << " sourceURL is not set\n"; + } + + if (sourceApplication.isSet()) { + strm << " sourceApplication = " + << sourceApplication.ref() << "\n"; + } + else { + strm << " sourceApplication is not set\n"; + } + + if (shareDate.isSet()) { + strm << " shareDate = " + << shareDate.ref() << "\n"; + } + else { + strm << " shareDate is not set\n"; + } + + if (reminderOrder.isSet()) { + strm << " reminderOrder = " + << reminderOrder.ref() << "\n"; + } + else { + strm << " reminderOrder is not set\n"; + } + + if (reminderDoneTime.isSet()) { + strm << " reminderDoneTime = " + << reminderDoneTime.ref() << "\n"; + } + else { + strm << " reminderDoneTime is not set\n"; + } + + if (reminderTime.isSet()) { + strm << " reminderTime = " + << reminderTime.ref() << "\n"; + } + else { + strm << " reminderTime is not set\n"; + } + + if (placeName.isSet()) { + strm << " placeName = " + << placeName.ref() << "\n"; + } + else { + strm << " placeName is not set\n"; + } + + if (contentClass.isSet()) { + strm << " contentClass = " + << contentClass.ref() << "\n"; + } + else { + strm << " contentClass is not set\n"; + } + + if (applicationData.isSet()) { + strm << " applicationData = " + << applicationData.ref() << "\n"; + } + else { + strm << " applicationData is not set\n"; + } + + if (lastEditedBy.isSet()) { + strm << " lastEditedBy = " + << lastEditedBy.ref() << "\n"; + } + else { + strm << " lastEditedBy is not set\n"; + } + + if (classifications.isSet()) { + strm << " classifications = " + << "QMap {"; + for(const auto & it: toRange(classifications.ref())) { + strm << " [" << it.key() << "] = " << it.value() << "\n"; + } + strm << " }\n"; + } + else { + strm << " classifications is not set\n"; + } + + if (creatorId.isSet()) { + strm << " creatorId = " + << creatorId.ref() << "\n"; + } + else { + strm << " creatorId is not set\n"; + } + + if (lastEditorId.isSet()) { + strm << " lastEditorId = " + << lastEditorId.ref() << "\n"; + } + else { + strm << " lastEditorId is not set\n"; + } + + if (sharedWithBusiness.isSet()) { + strm << " sharedWithBusiness = " + << sharedWithBusiness.ref() << "\n"; + } + else { + strm << " sharedWithBusiness is not set\n"; + } + + if (conflictSourceNoteGuid.isSet()) { + strm << " conflictSourceNoteGuid = " + << conflictSourceNoteGuid.ref() << "\n"; + } + else { + strm << " conflictSourceNoteGuid is not set\n"; + } + + if (noteTitleQuality.isSet()) { + strm << " noteTitleQuality = " + << noteTitleQuality.ref() << "\n"; + } + else { + strm << " noteTitleQuality is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeSharedNote( + ThriftBinaryBufferWriter & writer, + const SharedNote & s) +{ + writer.writeStructBegin(QStringLiteral("SharedNote")); + if (s.sharerUserID.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sharerUserID"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.sharerUserID.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientIdentity.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientIdentity"), + ThriftFieldType::T_STRUCT, + 2); + + writeIdentity(writer, s.recipientIdentity.ref()); + writer.writeFieldEnd(); + } + + if (s.privilege.isSet()) { + writer.writeFieldBegin( + QStringLiteral("privilege"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(static_cast(s.privilege.ref())); + writer.writeFieldEnd(); + } + + if (s.serviceCreated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("serviceCreated"), + ThriftFieldType::T_I64, + 4); + + writer.writeI64(s.serviceCreated.ref()); + writer.writeFieldEnd(); + } + + if (s.serviceUpdated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("serviceUpdated"), + ThriftFieldType::T_I64, + 5); + + writer.writeI64(s.serviceUpdated.ref()); + writer.writeFieldEnd(); + } + + if (s.serviceAssigned.isSet()) { + writer.writeFieldBegin( + QStringLiteral("serviceAssigned"), + ThriftFieldType::T_I64, + 6); + + writer.writeI64(s.serviceAssigned.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readSharedNote( + ThriftBinaryBufferReader & reader, + SharedNote & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.sharerUserID = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRUCT) { + Identity v; + readIdentity(reader, v); + s.recipientIdentity = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + SharedNotePrivilegeLevel v; + readEnumSharedNotePrivilegeLevel(reader, v); + s.privilege = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.serviceCreated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.serviceUpdated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.serviceAssigned = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void SharedNote::print(QTextStream & strm) const +{ + strm << "SharedNote: {\n"; + localData.print(strm); + + if (sharerUserID.isSet()) { + strm << " sharerUserID = " + << sharerUserID.ref() << "\n"; + } + else { + strm << " sharerUserID is not set\n"; + } + + if (recipientIdentity.isSet()) { + strm << " recipientIdentity = " + << recipientIdentity.ref() << "\n"; + } + else { + strm << " recipientIdentity is not set\n"; + } + + if (privilege.isSet()) { + strm << " privilege = " + << privilege.ref() << "\n"; + } + else { + strm << " privilege is not set\n"; + } + + if (serviceCreated.isSet()) { + strm << " serviceCreated = " + << serviceCreated.ref() << "\n"; + } + else { + strm << " serviceCreated is not set\n"; + } + + if (serviceUpdated.isSet()) { + strm << " serviceUpdated = " + << serviceUpdated.ref() << "\n"; + } + else { + strm << " serviceUpdated is not set\n"; + } + + if (serviceAssigned.isSet()) { + strm << " serviceAssigned = " + << serviceAssigned.ref() << "\n"; + } + else { + strm << " serviceAssigned is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteRestrictions( + ThriftBinaryBufferWriter & writer, + const NoteRestrictions & s) +{ + writer.writeStructBegin(QStringLiteral("NoteRestrictions")); + if (s.noUpdateTitle.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noUpdateTitle"), + ThriftFieldType::T_BOOL, + 1); + + writer.writeBool(s.noUpdateTitle.ref()); + writer.writeFieldEnd(); + } + + if (s.noUpdateContent.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noUpdateContent"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(s.noUpdateContent.ref()); + writer.writeFieldEnd(); + } + + if (s.noEmail.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noEmail"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(s.noEmail.ref()); + writer.writeFieldEnd(); + } + + if (s.noShare.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noShare"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(s.noShare.ref()); + writer.writeFieldEnd(); + } + + if (s.noSharePublicly.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSharePublicly"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(s.noSharePublicly.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteRestrictions( + ThriftBinaryBufferReader & reader, + NoteRestrictions & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noUpdateTitle = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noUpdateContent = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noEmail = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noShare = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSharePublicly = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NoteRestrictions::print(QTextStream & strm) const +{ + strm << "NoteRestrictions: {\n"; + localData.print(strm); + + if (noUpdateTitle.isSet()) { + strm << " noUpdateTitle = " + << noUpdateTitle.ref() << "\n"; + } + else { + strm << " noUpdateTitle is not set\n"; + } + + if (noUpdateContent.isSet()) { + strm << " noUpdateContent = " + << noUpdateContent.ref() << "\n"; + } + else { + strm << " noUpdateContent is not set\n"; + } + + if (noEmail.isSet()) { + strm << " noEmail = " + << noEmail.ref() << "\n"; + } + else { + strm << " noEmail is not set\n"; + } + + if (noShare.isSet()) { + strm << " noShare = " + << noShare.ref() << "\n"; + } + else { + strm << " noShare is not set\n"; + } + + if (noSharePublicly.isSet()) { + strm << " noSharePublicly = " + << noSharePublicly.ref() << "\n"; + } + else { + strm << " noSharePublicly is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNoteLimits( + ThriftBinaryBufferWriter & writer, + const NoteLimits & s) +{ + writer.writeStructBegin(QStringLiteral("NoteLimits")); + if (s.noteResourceCountMax.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteResourceCountMax"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.noteResourceCountMax.ref()); + writer.writeFieldEnd(); + } + + if (s.uploadLimit.isSet()) { + writer.writeFieldBegin( + QStringLiteral("uploadLimit"), + ThriftFieldType::T_I64, + 2); + + writer.writeI64(s.uploadLimit.ref()); + writer.writeFieldEnd(); + } + + if (s.resourceSizeMax.isSet()) { + writer.writeFieldBegin( + QStringLiteral("resourceSizeMax"), + ThriftFieldType::T_I64, + 3); + + writer.writeI64(s.resourceSizeMax.ref()); + writer.writeFieldEnd(); + } + + if (s.noteSizeMax.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteSizeMax"), + ThriftFieldType::T_I64, + 4); + + writer.writeI64(s.noteSizeMax.ref()); + writer.writeFieldEnd(); + } + + if (s.uploaded.isSet()) { + writer.writeFieldBegin( + QStringLiteral("uploaded"), + ThriftFieldType::T_I64, + 5); + + writer.writeI64(s.uploaded.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNoteLimits( + ThriftBinaryBufferReader & reader, + NoteLimits & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.noteResourceCountMax = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.uploadLimit = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.resourceSizeMax = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.noteSizeMax = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.uploaded = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NoteLimits::print(QTextStream & strm) const +{ + strm << "NoteLimits: {\n"; + localData.print(strm); + + if (noteResourceCountMax.isSet()) { + strm << " noteResourceCountMax = " + << noteResourceCountMax.ref() << "\n"; + } + else { + strm << " noteResourceCountMax is not set\n"; + } + + if (uploadLimit.isSet()) { + strm << " uploadLimit = " + << uploadLimit.ref() << "\n"; + } + else { + strm << " uploadLimit is not set\n"; + } + + if (resourceSizeMax.isSet()) { + strm << " resourceSizeMax = " + << resourceSizeMax.ref() << "\n"; + } + else { + strm << " resourceSizeMax is not set\n"; + } + + if (noteSizeMax.isSet()) { + strm << " noteSizeMax = " + << noteSizeMax.ref() << "\n"; + } + else { + strm << " noteSizeMax is not set\n"; + } + + if (uploaded.isSet()) { + strm << " uploaded = " + << uploaded.ref() << "\n"; + } + else { + strm << " uploaded is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNote( + ThriftBinaryBufferWriter & writer, + const Note & s) +{ + writer.writeStructBegin(QStringLiteral("Note")); + if (s.guid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.guid.ref()); + writer.writeFieldEnd(); + } + + if (s.title.isSet()) { + writer.writeFieldBegin( + QStringLiteral("title"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.title.ref()); + writer.writeFieldEnd(); + } + + if (s.content.isSet()) { + writer.writeFieldBegin( + QStringLiteral("content"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.content.ref()); + writer.writeFieldEnd(); + } + + if (s.contentHash.isSet()) { + writer.writeFieldBegin( + QStringLiteral("contentHash"), + ThriftFieldType::T_STRING, + 4); + + writer.writeBinary(s.contentHash.ref()); + writer.writeFieldEnd(); + } + + if (s.contentLength.isSet()) { + writer.writeFieldBegin( + QStringLiteral("contentLength"), + ThriftFieldType::T_I32, + 5); + + writer.writeI32(s.contentLength.ref()); + writer.writeFieldEnd(); + } + + if (s.created.isSet()) { + writer.writeFieldBegin( + QStringLiteral("created"), + ThriftFieldType::T_I64, + 6); + + writer.writeI64(s.created.ref()); + writer.writeFieldEnd(); + } + + if (s.updated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updated"), + ThriftFieldType::T_I64, + 7); + + writer.writeI64(s.updated.ref()); + writer.writeFieldEnd(); + } + + if (s.deleted.isSet()) { + writer.writeFieldBegin( + QStringLiteral("deleted"), + ThriftFieldType::T_I64, + 8); + + writer.writeI64(s.deleted.ref()); + writer.writeFieldEnd(); + } + + if (s.active.isSet()) { + writer.writeFieldBegin( + QStringLiteral("active"), + ThriftFieldType::T_BOOL, + 9); + + writer.writeBool(s.active.ref()); + writer.writeFieldEnd(); + } + + if (s.updateSequenceNum.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updateSequenceNum"), + ThriftFieldType::T_I32, + 10); + + writer.writeI32(s.updateSequenceNum.ref()); + writer.writeFieldEnd(); + } + + if (s.notebookGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebookGuid"), + ThriftFieldType::T_STRING, + 11); + + writer.writeString(s.notebookGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.tagGuids.isSet()) { + writer.writeFieldBegin( + QStringLiteral("tagGuids"), + ThriftFieldType::T_LIST, + 12); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.tagGuids.ref().length()); + for(const auto & value: qAsConst(s.tagGuids.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.resources.isSet()) { + writer.writeFieldBegin( + QStringLiteral("resources"), + ThriftFieldType::T_LIST, + 13); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.resources.ref().length()); + for(const auto & value: qAsConst(s.resources.ref())) { + writeResource(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.attributes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("attributes"), + ThriftFieldType::T_STRUCT, + 14); + + writeNoteAttributes(writer, s.attributes.ref()); + writer.writeFieldEnd(); + } + + if (s.tagNames.isSet()) { + writer.writeFieldBegin( + QStringLiteral("tagNames"), + ThriftFieldType::T_LIST, + 15); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.tagNames.ref().length()); + for(const auto & value: qAsConst(s.tagNames.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.sharedNotes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sharedNotes"), + ThriftFieldType::T_LIST, + 16); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.sharedNotes.ref().length()); + for(const auto & value: qAsConst(s.sharedNotes.ref())) { + writeSharedNote(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.restrictions.isSet()) { + writer.writeFieldBegin( + QStringLiteral("restrictions"), + ThriftFieldType::T_STRUCT, + 17); + + writeNoteRestrictions(writer, s.restrictions.ref()); + writer.writeFieldEnd(); + } + + if (s.limits.isSet()) { + writer.writeFieldBegin( + QStringLiteral("limits"), + ThriftFieldType::T_STRUCT, + 18); + + writeNoteLimits(writer, s.limits.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNote( + ThriftBinaryBufferReader & reader, + Note & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.guid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.title = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.content = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QByteArray v; + reader.readBinary(v); + s.contentHash = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.contentLength = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.created = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.updated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.deleted = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.active = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.updateSequenceNum = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.notebookGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (Note.tagGuids)")); + } + for(qint32 i = 0; i < size; i++) { + Guid elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.tagGuids = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (Note.resources)")); + } + for(qint32 i = 0; i < size; i++) { + Resource elem; + readResource(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.resources = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 14) { + if (fieldType == ThriftFieldType::T_STRUCT) { + NoteAttributes v; + readNoteAttributes(reader, v); + s.attributes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 15) { + if (fieldType == ThriftFieldType::T_LIST) { + QStringList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (Note.tagNames)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.tagNames = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 16) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (Note.sharedNotes)")); + } + for(qint32 i = 0; i < size; i++) { + SharedNote elem; + readSharedNote(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.sharedNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 17) { + if (fieldType == ThriftFieldType::T_STRUCT) { + NoteRestrictions v; + readNoteRestrictions(reader, v); + s.restrictions = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 18) { + if (fieldType == ThriftFieldType::T_STRUCT) { + NoteLimits v; + readNoteLimits(reader, v); + s.limits = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void Note::print(QTextStream & strm) const +{ + strm << "Note: {\n"; + localData.print(strm); + + if (guid.isSet()) { + strm << " guid = " + << guid.ref() << "\n"; + } + else { + strm << " guid is not set\n"; + } + + if (title.isSet()) { + strm << " title = " + << title.ref() << "\n"; + } + else { + strm << " title is not set\n"; + } + + if (content.isSet()) { + strm << " content = " + << content.ref() << "\n"; + } + else { + strm << " content is not set\n"; + } + + if (contentHash.isSet()) { + strm << " contentHash = " + << contentHash.ref() << "\n"; + } + else { + strm << " contentHash is not set\n"; + } + + if (contentLength.isSet()) { + strm << " contentLength = " + << contentLength.ref() << "\n"; + } + else { + strm << " contentLength is not set\n"; + } + + if (created.isSet()) { + strm << " created = " + << created.ref() << "\n"; + } + else { + strm << " created is not set\n"; + } + + if (updated.isSet()) { + strm << " updated = " + << updated.ref() << "\n"; + } + else { + strm << " updated is not set\n"; + } + + if (deleted.isSet()) { + strm << " deleted = " + << deleted.ref() << "\n"; + } + else { + strm << " deleted is not set\n"; + } + + if (active.isSet()) { + strm << " active = " + << active.ref() << "\n"; + } + else { + strm << " active is not set\n"; + } + + if (updateSequenceNum.isSet()) { + strm << " updateSequenceNum = " + << updateSequenceNum.ref() << "\n"; + } + else { + strm << " updateSequenceNum is not set\n"; + } + + if (notebookGuid.isSet()) { + strm << " notebookGuid = " + << notebookGuid.ref() << "\n"; + } + else { + strm << " notebookGuid is not set\n"; + } + + if (tagGuids.isSet()) { + strm << " tagGuids = " + << "QList {"; + for(const auto & v: tagGuids.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " tagGuids is not set\n"; + } + + if (resources.isSet()) { + strm << " resources = " + << "QList {"; + for(const auto & v: resources.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " resources is not set\n"; + } + + if (attributes.isSet()) { + strm << " attributes = " + << attributes.ref() << "\n"; + } + else { + strm << " attributes is not set\n"; + } + + if (tagNames.isSet()) { + strm << " tagNames = " + << "QList {"; + for(const auto & v: tagNames.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " tagNames is not set\n"; + } + + if (sharedNotes.isSet()) { + strm << " sharedNotes = " + << "QList {"; + for(const auto & v: sharedNotes.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " sharedNotes is not set\n"; + } + + if (restrictions.isSet()) { + strm << " restrictions = " + << restrictions.ref() << "\n"; + } + else { + strm << " restrictions is not set\n"; + } + + if (limits.isSet()) { + strm << " limits = " + << limits.ref() << "\n"; + } + else { + strm << " limits is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writePublishing( + ThriftBinaryBufferWriter & writer, + const Publishing & s) +{ + writer.writeStructBegin(QStringLiteral("Publishing")); + if (s.uri.isSet()) { + writer.writeFieldBegin( + QStringLiteral("uri"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.uri.ref()); + writer.writeFieldEnd(); + } + + if (s.order.isSet()) { + writer.writeFieldBegin( + QStringLiteral("order"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(static_cast(s.order.ref())); + writer.writeFieldEnd(); + } + + if (s.ascending.isSet()) { + writer.writeFieldBegin( + QStringLiteral("ascending"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(s.ascending.ref()); + writer.writeFieldEnd(); + } + + if (s.publicDescription.isSet()) { + writer.writeFieldBegin( + QStringLiteral("publicDescription"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.publicDescription.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readPublishing( + ThriftBinaryBufferReader & reader, + Publishing & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.uri = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I32) { + NoteSortOrder v; + readEnumNoteSortOrder(reader, v); + s.order = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.ascending = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.publicDescription = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void Publishing::print(QTextStream & strm) const +{ + strm << "Publishing: {\n"; + localData.print(strm); + + if (uri.isSet()) { + strm << " uri = " + << uri.ref() << "\n"; + } + else { + strm << " uri is not set\n"; + } + + if (order.isSet()) { + strm << " order = " + << order.ref() << "\n"; + } + else { + strm << " order is not set\n"; + } + + if (ascending.isSet()) { + strm << " ascending = " + << ascending.ref() << "\n"; + } + else { + strm << " ascending is not set\n"; + } + + if (publicDescription.isSet()) { + strm << " publicDescription = " + << publicDescription.ref() << "\n"; + } + else { + strm << " publicDescription is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeBusinessNotebook( + ThriftBinaryBufferWriter & writer, + const BusinessNotebook & s) +{ + writer.writeStructBegin(QStringLiteral("BusinessNotebook")); + if (s.notebookDescription.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebookDescription"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.notebookDescription.ref()); + writer.writeFieldEnd(); + } + + if (s.privilege.isSet()) { + writer.writeFieldBegin( + QStringLiteral("privilege"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(static_cast(s.privilege.ref())); + writer.writeFieldEnd(); + } + + if (s.recommended.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recommended"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(s.recommended.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readBusinessNotebook( + ThriftBinaryBufferReader & reader, + BusinessNotebook & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.notebookDescription = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I32) { + SharedNotebookPrivilegeLevel v; + readEnumSharedNotebookPrivilegeLevel(reader, v); + s.privilege = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.recommended = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void BusinessNotebook::print(QTextStream & strm) const +{ + strm << "BusinessNotebook: {\n"; + localData.print(strm); + + if (notebookDescription.isSet()) { + strm << " notebookDescription = " + << notebookDescription.ref() << "\n"; + } + else { + strm << " notebookDescription is not set\n"; + } + + if (privilege.isSet()) { + strm << " privilege = " + << privilege.ref() << "\n"; + } + else { + strm << " privilege is not set\n"; + } + + if (recommended.isSet()) { + strm << " recommended = " + << recommended.ref() << "\n"; + } + else { + strm << " recommended is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeSavedSearchScope( + ThriftBinaryBufferWriter & writer, + const SavedSearchScope & s) +{ + writer.writeStructBegin(QStringLiteral("SavedSearchScope")); + if (s.includeAccount.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeAccount"), + ThriftFieldType::T_BOOL, + 1); + + writer.writeBool(s.includeAccount.ref()); + writer.writeFieldEnd(); + } + + if (s.includePersonalLinkedNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includePersonalLinkedNotebooks"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(s.includePersonalLinkedNotebooks.ref()); + writer.writeFieldEnd(); + } + + if (s.includeBusinessLinkedNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("includeBusinessLinkedNotebooks"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(s.includeBusinessLinkedNotebooks.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readSavedSearchScope( + ThriftBinaryBufferReader & reader, + SavedSearchScope & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeAccount = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includePersonalLinkedNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.includeBusinessLinkedNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void SavedSearchScope::print(QTextStream & strm) const +{ + strm << "SavedSearchScope: {\n"; + localData.print(strm); + + if (includeAccount.isSet()) { + strm << " includeAccount = " + << includeAccount.ref() << "\n"; + } + else { + strm << " includeAccount is not set\n"; + } + + if (includePersonalLinkedNotebooks.isSet()) { + strm << " includePersonalLinkedNotebooks = " + << includePersonalLinkedNotebooks.ref() << "\n"; + } + else { + strm << " includePersonalLinkedNotebooks is not set\n"; + } + + if (includeBusinessLinkedNotebooks.isSet()) { + strm << " includeBusinessLinkedNotebooks = " + << includeBusinessLinkedNotebooks.ref() << "\n"; + } + else { + strm << " includeBusinessLinkedNotebooks is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeSavedSearch( + ThriftBinaryBufferWriter & writer, + const SavedSearch & s) +{ + writer.writeStructBegin(QStringLiteral("SavedSearch")); + if (s.guid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.guid.ref()); + writer.writeFieldEnd(); + } + + if (s.name.isSet()) { + writer.writeFieldBegin( + QStringLiteral("name"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.name.ref()); + writer.writeFieldEnd(); + } + + if (s.query.isSet()) { + writer.writeFieldBegin( + QStringLiteral("query"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.query.ref()); + writer.writeFieldEnd(); + } + + if (s.format.isSet()) { + writer.writeFieldBegin( + QStringLiteral("format"), + ThriftFieldType::T_I32, + 4); + + writer.writeI32(static_cast(s.format.ref())); + writer.writeFieldEnd(); + } + + if (s.updateSequenceNum.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updateSequenceNum"), + ThriftFieldType::T_I32, + 5); + + writer.writeI32(s.updateSequenceNum.ref()); + writer.writeFieldEnd(); + } + + if (s.scope.isSet()) { + writer.writeFieldBegin( + QStringLiteral("scope"), + ThriftFieldType::T_STRUCT, + 6); + + writeSavedSearchScope(writer, s.scope.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readSavedSearch( + ThriftBinaryBufferReader & reader, + SavedSearch & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.guid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.name = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.query = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_I32) { + QueryFormat v; + readEnumQueryFormat(reader, v); + s.format = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.updateSequenceNum = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRUCT) { + SavedSearchScope v; + readSavedSearchScope(reader, v); + s.scope = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void SavedSearch::print(QTextStream & strm) const +{ + strm << "SavedSearch: {\n"; + localData.print(strm); + + if (guid.isSet()) { + strm << " guid = " + << guid.ref() << "\n"; + } + else { + strm << " guid is not set\n"; + } + + if (name.isSet()) { + strm << " name = " + << name.ref() << "\n"; + } + else { + strm << " name is not set\n"; + } + + if (query.isSet()) { + strm << " query = " + << query.ref() << "\n"; + } + else { + strm << " query is not set\n"; + } + + if (format.isSet()) { + strm << " format = " + << format.ref() << "\n"; + } + else { + strm << " format is not set\n"; + } + + if (updateSequenceNum.isSet()) { + strm << " updateSequenceNum = " + << updateSequenceNum.ref() << "\n"; + } + else { + strm << " updateSequenceNum is not set\n"; + } + + if (scope.isSet()) { + strm << " scope = " + << scope.ref() << "\n"; + } + else { + strm << " scope is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeSharedNotebookRecipientSettings( + ThriftBinaryBufferWriter & writer, + const SharedNotebookRecipientSettings & s) +{ + writer.writeStructBegin(QStringLiteral("SharedNotebookRecipientSettings")); + if (s.reminderNotifyEmail.isSet()) { + writer.writeFieldBegin( + QStringLiteral("reminderNotifyEmail"), + ThriftFieldType::T_BOOL, + 1); + + writer.writeBool(s.reminderNotifyEmail.ref()); + writer.writeFieldEnd(); + } + + if (s.reminderNotifyInApp.isSet()) { + writer.writeFieldBegin( + QStringLiteral("reminderNotifyInApp"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(s.reminderNotifyInApp.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readSharedNotebookRecipientSettings( + ThriftBinaryBufferReader & reader, + SharedNotebookRecipientSettings & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.reminderNotifyEmail = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.reminderNotifyInApp = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void SharedNotebookRecipientSettings::print(QTextStream & strm) const +{ + strm << "SharedNotebookRecipientSettings: {\n"; + localData.print(strm); + + if (reminderNotifyEmail.isSet()) { + strm << " reminderNotifyEmail = " + << reminderNotifyEmail.ref() << "\n"; + } + else { + strm << " reminderNotifyEmail is not set\n"; + } + + if (reminderNotifyInApp.isSet()) { + strm << " reminderNotifyInApp = " + << reminderNotifyInApp.ref() << "\n"; + } + else { + strm << " reminderNotifyInApp is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNotebookRecipientSettings( + ThriftBinaryBufferWriter & writer, + const NotebookRecipientSettings & s) +{ + writer.writeStructBegin(QStringLiteral("NotebookRecipientSettings")); + if (s.reminderNotifyEmail.isSet()) { + writer.writeFieldBegin( + QStringLiteral("reminderNotifyEmail"), + ThriftFieldType::T_BOOL, + 1); + + writer.writeBool(s.reminderNotifyEmail.ref()); + writer.writeFieldEnd(); + } + + if (s.reminderNotifyInApp.isSet()) { + writer.writeFieldBegin( + QStringLiteral("reminderNotifyInApp"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(s.reminderNotifyInApp.ref()); + writer.writeFieldEnd(); + } + + if (s.inMyList.isSet()) { + writer.writeFieldBegin( + QStringLiteral("inMyList"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(s.inMyList.ref()); + writer.writeFieldEnd(); + } + + if (s.stack.isSet()) { + writer.writeFieldBegin( + QStringLiteral("stack"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.stack.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientStatus.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientStatus"), + ThriftFieldType::T_I32, + 5); + + writer.writeI32(static_cast(s.recipientStatus.ref())); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNotebookRecipientSettings( + ThriftBinaryBufferReader & reader, + NotebookRecipientSettings & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.reminderNotifyEmail = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.reminderNotifyInApp = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.inMyList = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.stack = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I32) { + RecipientStatus v; + readEnumRecipientStatus(reader, v); + s.recipientStatus = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NotebookRecipientSettings::print(QTextStream & strm) const +{ + strm << "NotebookRecipientSettings: {\n"; + localData.print(strm); + + if (reminderNotifyEmail.isSet()) { + strm << " reminderNotifyEmail = " + << reminderNotifyEmail.ref() << "\n"; + } + else { + strm << " reminderNotifyEmail is not set\n"; + } + + if (reminderNotifyInApp.isSet()) { + strm << " reminderNotifyInApp = " + << reminderNotifyInApp.ref() << "\n"; + } + else { + strm << " reminderNotifyInApp is not set\n"; + } + + if (inMyList.isSet()) { + strm << " inMyList = " + << inMyList.ref() << "\n"; + } + else { + strm << " inMyList is not set\n"; + } + + if (stack.isSet()) { + strm << " stack = " + << stack.ref() << "\n"; + } + else { + strm << " stack is not set\n"; + } + + if (recipientStatus.isSet()) { + strm << " recipientStatus = " + << recipientStatus.ref() << "\n"; + } + else { + strm << " recipientStatus is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeSharedNotebook( + ThriftBinaryBufferWriter & writer, + const SharedNotebook & s) +{ + writer.writeStructBegin(QStringLiteral("SharedNotebook")); + if (s.id.isSet()) { + writer.writeFieldBegin( + QStringLiteral("id"), + ThriftFieldType::T_I64, + 1); + + writer.writeI64(s.id.ref()); + writer.writeFieldEnd(); + } + + if (s.userId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userId"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(s.userId.ref()); + writer.writeFieldEnd(); + } + + if (s.notebookGuid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebookGuid"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.notebookGuid.ref()); + writer.writeFieldEnd(); + } + + if (s.email.isSet()) { + writer.writeFieldBegin( + QStringLiteral("email"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.email.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientIdentityId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientIdentityId"), + ThriftFieldType::T_I64, + 18); + + writer.writeI64(s.recipientIdentityId.ref()); + writer.writeFieldEnd(); + } + + if (s.notebookModifiable.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebookModifiable"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(s.notebookModifiable.ref()); + writer.writeFieldEnd(); + } + + if (s.serviceCreated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("serviceCreated"), + ThriftFieldType::T_I64, + 7); + + writer.writeI64(s.serviceCreated.ref()); + writer.writeFieldEnd(); + } + + if (s.serviceUpdated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("serviceUpdated"), + ThriftFieldType::T_I64, + 10); + + writer.writeI64(s.serviceUpdated.ref()); + writer.writeFieldEnd(); + } + + if (s.globalId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("globalId"), + ThriftFieldType::T_STRING, + 8); + + writer.writeString(s.globalId.ref()); + writer.writeFieldEnd(); + } + + if (s.username.isSet()) { + writer.writeFieldBegin( + QStringLiteral("username"), + ThriftFieldType::T_STRING, + 9); + + writer.writeString(s.username.ref()); + writer.writeFieldEnd(); + } + + if (s.privilege.isSet()) { + writer.writeFieldBegin( + QStringLiteral("privilege"), + ThriftFieldType::T_I32, + 11); + + writer.writeI32(static_cast(s.privilege.ref())); + writer.writeFieldEnd(); + } + + if (s.recipientSettings.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientSettings"), + ThriftFieldType::T_STRUCT, + 13); + + writeSharedNotebookRecipientSettings(writer, s.recipientSettings.ref()); + writer.writeFieldEnd(); + } + + if (s.sharerUserId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sharerUserId"), + ThriftFieldType::T_I32, + 14); + + writer.writeI32(s.sharerUserId.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientUsername.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientUsername"), + ThriftFieldType::T_STRING, + 15); + + writer.writeString(s.recipientUsername.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientUserId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientUserId"), + ThriftFieldType::T_I32, + 17); + + writer.writeI32(s.recipientUserId.ref()); + writer.writeFieldEnd(); + } + + if (s.serviceAssigned.isSet()) { + writer.writeFieldBegin( + QStringLiteral("serviceAssigned"), + ThriftFieldType::T_I64, + 16); + + writer.writeI64(s.serviceAssigned.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readSharedNotebook( + ThriftBinaryBufferReader & reader, + SharedNotebook & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.id = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.userId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.notebookGuid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.email = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 18) { + if (fieldType == ThriftFieldType::T_I64) { + IdentityID v; + reader.readI64(v); + s.recipientIdentityId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.notebookModifiable = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.serviceCreated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.serviceUpdated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.globalId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.username = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_I32) { + SharedNotebookPrivilegeLevel v; + readEnumSharedNotebookPrivilegeLevel(reader, v); + s.privilege = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_STRUCT) { + SharedNotebookRecipientSettings v; + readSharedNotebookRecipientSettings(reader, v); + s.recipientSettings = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 14) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.sharerUserId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 15) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.recipientUsername = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 17) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.recipientUserId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 16) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.serviceAssigned = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void SharedNotebook::print(QTextStream & strm) const +{ + strm << "SharedNotebook: {\n"; + localData.print(strm); + + if (id.isSet()) { + strm << " id = " + << id.ref() << "\n"; + } + else { + strm << " id is not set\n"; + } + + if (userId.isSet()) { + strm << " userId = " + << userId.ref() << "\n"; + } + else { + strm << " userId is not set\n"; + } + + if (notebookGuid.isSet()) { + strm << " notebookGuid = " + << notebookGuid.ref() << "\n"; + } + else { + strm << " notebookGuid is not set\n"; + } + + if (email.isSet()) { + strm << " email = " + << email.ref() << "\n"; + } + else { + strm << " email is not set\n"; + } + + if (recipientIdentityId.isSet()) { + strm << " recipientIdentityId = " + << recipientIdentityId.ref() << "\n"; + } + else { + strm << " recipientIdentityId is not set\n"; + } + + if (notebookModifiable.isSet()) { + strm << " notebookModifiable = " + << notebookModifiable.ref() << "\n"; + } + else { + strm << " notebookModifiable is not set\n"; + } + + if (serviceCreated.isSet()) { + strm << " serviceCreated = " + << serviceCreated.ref() << "\n"; + } + else { + strm << " serviceCreated is not set\n"; + } + + if (serviceUpdated.isSet()) { + strm << " serviceUpdated = " + << serviceUpdated.ref() << "\n"; + } + else { + strm << " serviceUpdated is not set\n"; + } + + if (globalId.isSet()) { + strm << " globalId = " + << globalId.ref() << "\n"; + } + else { + strm << " globalId is not set\n"; + } + + if (username.isSet()) { + strm << " username = " + << username.ref() << "\n"; + } + else { + strm << " username is not set\n"; + } + + if (privilege.isSet()) { + strm << " privilege = " + << privilege.ref() << "\n"; + } + else { + strm << " privilege is not set\n"; + } + + if (recipientSettings.isSet()) { + strm << " recipientSettings = " + << recipientSettings.ref() << "\n"; + } + else { + strm << " recipientSettings is not set\n"; + } + + if (sharerUserId.isSet()) { + strm << " sharerUserId = " + << sharerUserId.ref() << "\n"; + } + else { + strm << " sharerUserId is not set\n"; + } + + if (recipientUsername.isSet()) { + strm << " recipientUsername = " + << recipientUsername.ref() << "\n"; + } + else { + strm << " recipientUsername is not set\n"; + } + + if (recipientUserId.isSet()) { + strm << " recipientUserId = " + << recipientUserId.ref() << "\n"; + } + else { + strm << " recipientUserId is not set\n"; + } + + if (serviceAssigned.isSet()) { + strm << " serviceAssigned = " + << serviceAssigned.ref() << "\n"; + } + else { + strm << " serviceAssigned is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeCanMoveToContainerRestrictions( + ThriftBinaryBufferWriter & writer, + const CanMoveToContainerRestrictions & s) +{ + writer.writeStructBegin(QStringLiteral("CanMoveToContainerRestrictions")); + if (s.canMoveToContainer.isSet()) { + writer.writeFieldBegin( + QStringLiteral("canMoveToContainer"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(static_cast(s.canMoveToContainer.ref())); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readCanMoveToContainerRestrictions( + ThriftBinaryBufferReader & reader, + CanMoveToContainerRestrictions & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + CanMoveToContainerStatus v; + readEnumCanMoveToContainerStatus(reader, v); + s.canMoveToContainer = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void CanMoveToContainerRestrictions::print(QTextStream & strm) const +{ + strm << "CanMoveToContainerRestrictions: {\n"; + localData.print(strm); + + if (canMoveToContainer.isSet()) { + strm << " canMoveToContainer = " + << canMoveToContainer.ref() << "\n"; + } + else { + strm << " canMoveToContainer is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNotebookRestrictions( + ThriftBinaryBufferWriter & writer, + const NotebookRestrictions & s) +{ + writer.writeStructBegin(QStringLiteral("NotebookRestrictions")); + if (s.noReadNotes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noReadNotes"), + ThriftFieldType::T_BOOL, + 1); + + writer.writeBool(s.noReadNotes.ref()); + writer.writeFieldEnd(); + } + + if (s.noCreateNotes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noCreateNotes"), + ThriftFieldType::T_BOOL, + 2); + + writer.writeBool(s.noCreateNotes.ref()); + writer.writeFieldEnd(); + } + + if (s.noUpdateNotes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noUpdateNotes"), + ThriftFieldType::T_BOOL, + 3); + + writer.writeBool(s.noUpdateNotes.ref()); + writer.writeFieldEnd(); + } + + if (s.noExpungeNotes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noExpungeNotes"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(s.noExpungeNotes.ref()); + writer.writeFieldEnd(); + } + + if (s.noShareNotes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noShareNotes"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(s.noShareNotes.ref()); + writer.writeFieldEnd(); + } + + if (s.noEmailNotes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noEmailNotes"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(s.noEmailNotes.ref()); + writer.writeFieldEnd(); + } + + if (s.noSendMessageToRecipients.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSendMessageToRecipients"), + ThriftFieldType::T_BOOL, + 7); + + writer.writeBool(s.noSendMessageToRecipients.ref()); + writer.writeFieldEnd(); + } + + if (s.noUpdateNotebook.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noUpdateNotebook"), + ThriftFieldType::T_BOOL, + 8); + + writer.writeBool(s.noUpdateNotebook.ref()); + writer.writeFieldEnd(); + } + + if (s.noExpungeNotebook.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noExpungeNotebook"), + ThriftFieldType::T_BOOL, + 9); + + writer.writeBool(s.noExpungeNotebook.ref()); + writer.writeFieldEnd(); + } + + if (s.noSetDefaultNotebook.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetDefaultNotebook"), + ThriftFieldType::T_BOOL, + 10); + + writer.writeBool(s.noSetDefaultNotebook.ref()); + writer.writeFieldEnd(); + } + + if (s.noSetNotebookStack.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetNotebookStack"), + ThriftFieldType::T_BOOL, + 11); + + writer.writeBool(s.noSetNotebookStack.ref()); + writer.writeFieldEnd(); + } + + if (s.noPublishToPublic.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noPublishToPublic"), + ThriftFieldType::T_BOOL, + 12); + + writer.writeBool(s.noPublishToPublic.ref()); + writer.writeFieldEnd(); + } + + if (s.noPublishToBusinessLibrary.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noPublishToBusinessLibrary"), + ThriftFieldType::T_BOOL, + 13); + + writer.writeBool(s.noPublishToBusinessLibrary.ref()); + writer.writeFieldEnd(); + } + + if (s.noCreateTags.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noCreateTags"), + ThriftFieldType::T_BOOL, + 14); + + writer.writeBool(s.noCreateTags.ref()); + writer.writeFieldEnd(); + } + + if (s.noUpdateTags.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noUpdateTags"), + ThriftFieldType::T_BOOL, + 15); + + writer.writeBool(s.noUpdateTags.ref()); + writer.writeFieldEnd(); + } + + if (s.noExpungeTags.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noExpungeTags"), + ThriftFieldType::T_BOOL, + 16); + + writer.writeBool(s.noExpungeTags.ref()); + writer.writeFieldEnd(); + } + + if (s.noSetParentTag.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetParentTag"), + ThriftFieldType::T_BOOL, + 17); + + writer.writeBool(s.noSetParentTag.ref()); + writer.writeFieldEnd(); + } + + if (s.noCreateSharedNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noCreateSharedNotebooks"), + ThriftFieldType::T_BOOL, + 18); + + writer.writeBool(s.noCreateSharedNotebooks.ref()); + writer.writeFieldEnd(); + } + + if (s.updateWhichSharedNotebookRestrictions.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updateWhichSharedNotebookRestrictions"), + ThriftFieldType::T_I32, + 19); + + writer.writeI32(static_cast(s.updateWhichSharedNotebookRestrictions.ref())); + writer.writeFieldEnd(); + } + + if (s.expungeWhichSharedNotebookRestrictions.isSet()) { + writer.writeFieldBegin( + QStringLiteral("expungeWhichSharedNotebookRestrictions"), + ThriftFieldType::T_I32, + 20); + + writer.writeI32(static_cast(s.expungeWhichSharedNotebookRestrictions.ref())); + writer.writeFieldEnd(); + } + + if (s.noShareNotesWithBusiness.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noShareNotesWithBusiness"), + ThriftFieldType::T_BOOL, + 21); + + writer.writeBool(s.noShareNotesWithBusiness.ref()); + writer.writeFieldEnd(); + } + + if (s.noRenameNotebook.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noRenameNotebook"), + ThriftFieldType::T_BOOL, + 22); + + writer.writeBool(s.noRenameNotebook.ref()); + writer.writeFieldEnd(); + } + + if (s.noSetInMyList.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetInMyList"), + ThriftFieldType::T_BOOL, + 23); + + writer.writeBool(s.noSetInMyList.ref()); + writer.writeFieldEnd(); + } + + if (s.noChangeContact.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noChangeContact"), + ThriftFieldType::T_BOOL, + 24); + + writer.writeBool(s.noChangeContact.ref()); + writer.writeFieldEnd(); + } + + if (s.canMoveToContainerRestrictions.isSet()) { + writer.writeFieldBegin( + QStringLiteral("canMoveToContainerRestrictions"), + ThriftFieldType::T_STRUCT, + 26); + + writeCanMoveToContainerRestrictions(writer, s.canMoveToContainerRestrictions.ref()); + writer.writeFieldEnd(); + } + + if (s.noSetReminderNotifyEmail.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetReminderNotifyEmail"), + ThriftFieldType::T_BOOL, + 27); + + writer.writeBool(s.noSetReminderNotifyEmail.ref()); + writer.writeFieldEnd(); + } + + if (s.noSetReminderNotifyInApp.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetReminderNotifyInApp"), + ThriftFieldType::T_BOOL, + 28); + + writer.writeBool(s.noSetReminderNotifyInApp.ref()); + writer.writeFieldEnd(); + } + + if (s.noSetRecipientSettingsStack.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noSetRecipientSettingsStack"), + ThriftFieldType::T_BOOL, + 29); + + writer.writeBool(s.noSetRecipientSettingsStack.ref()); + writer.writeFieldEnd(); + } + + if (s.noCanMoveNote.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noCanMoveNote"), + ThriftFieldType::T_BOOL, + 30); + + writer.writeBool(s.noCanMoveNote.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNotebookRestrictions( + ThriftBinaryBufferReader & reader, + NotebookRestrictions & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noReadNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noCreateNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noUpdateNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noExpungeNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noShareNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noEmailNotes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSendMessageToRecipients = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noUpdateNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noExpungeNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetDefaultNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetNotebookStack = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noPublishToPublic = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noPublishToBusinessLibrary = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 14) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noCreateTags = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 15) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noUpdateTags = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 16) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noExpungeTags = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 17) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetParentTag = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 18) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noCreateSharedNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 19) { + if (fieldType == ThriftFieldType::T_I32) { + SharedNotebookInstanceRestrictions v; + readEnumSharedNotebookInstanceRestrictions(reader, v); + s.updateWhichSharedNotebookRestrictions = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 20) { + if (fieldType == ThriftFieldType::T_I32) { + SharedNotebookInstanceRestrictions v; + readEnumSharedNotebookInstanceRestrictions(reader, v); + s.expungeWhichSharedNotebookRestrictions = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 21) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noShareNotesWithBusiness = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 22) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noRenameNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 23) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetInMyList = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 24) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noChangeContact = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 26) { + if (fieldType == ThriftFieldType::T_STRUCT) { + CanMoveToContainerRestrictions v; + readCanMoveToContainerRestrictions(reader, v); + s.canMoveToContainerRestrictions = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 27) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetReminderNotifyEmail = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 28) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetReminderNotifyInApp = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 29) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noSetRecipientSettingsStack = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 30) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.noCanMoveNote = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NotebookRestrictions::print(QTextStream & strm) const +{ + strm << "NotebookRestrictions: {\n"; + localData.print(strm); + + if (noReadNotes.isSet()) { + strm << " noReadNotes = " + << noReadNotes.ref() << "\n"; + } + else { + strm << " noReadNotes is not set\n"; + } + + if (noCreateNotes.isSet()) { + strm << " noCreateNotes = " + << noCreateNotes.ref() << "\n"; + } + else { + strm << " noCreateNotes is not set\n"; + } + + if (noUpdateNotes.isSet()) { + strm << " noUpdateNotes = " + << noUpdateNotes.ref() << "\n"; + } + else { + strm << " noUpdateNotes is not set\n"; + } + + if (noExpungeNotes.isSet()) { + strm << " noExpungeNotes = " + << noExpungeNotes.ref() << "\n"; + } + else { + strm << " noExpungeNotes is not set\n"; + } + + if (noShareNotes.isSet()) { + strm << " noShareNotes = " + << noShareNotes.ref() << "\n"; + } + else { + strm << " noShareNotes is not set\n"; + } + + if (noEmailNotes.isSet()) { + strm << " noEmailNotes = " + << noEmailNotes.ref() << "\n"; + } + else { + strm << " noEmailNotes is not set\n"; + } + + if (noSendMessageToRecipients.isSet()) { + strm << " noSendMessageToRecipients = " + << noSendMessageToRecipients.ref() << "\n"; + } + else { + strm << " noSendMessageToRecipients is not set\n"; + } + + if (noUpdateNotebook.isSet()) { + strm << " noUpdateNotebook = " + << noUpdateNotebook.ref() << "\n"; + } + else { + strm << " noUpdateNotebook is not set\n"; + } + + if (noExpungeNotebook.isSet()) { + strm << " noExpungeNotebook = " + << noExpungeNotebook.ref() << "\n"; + } + else { + strm << " noExpungeNotebook is not set\n"; + } + + if (noSetDefaultNotebook.isSet()) { + strm << " noSetDefaultNotebook = " + << noSetDefaultNotebook.ref() << "\n"; + } + else { + strm << " noSetDefaultNotebook is not set\n"; + } + + if (noSetNotebookStack.isSet()) { + strm << " noSetNotebookStack = " + << noSetNotebookStack.ref() << "\n"; + } + else { + strm << " noSetNotebookStack is not set\n"; + } + + if (noPublishToPublic.isSet()) { + strm << " noPublishToPublic = " + << noPublishToPublic.ref() << "\n"; + } + else { + strm << " noPublishToPublic is not set\n"; + } + + if (noPublishToBusinessLibrary.isSet()) { + strm << " noPublishToBusinessLibrary = " + << noPublishToBusinessLibrary.ref() << "\n"; + } + else { + strm << " noPublishToBusinessLibrary is not set\n"; + } + + if (noCreateTags.isSet()) { + strm << " noCreateTags = " + << noCreateTags.ref() << "\n"; + } + else { + strm << " noCreateTags is not set\n"; + } + + if (noUpdateTags.isSet()) { + strm << " noUpdateTags = " + << noUpdateTags.ref() << "\n"; + } + else { + strm << " noUpdateTags is not set\n"; + } + + if (noExpungeTags.isSet()) { + strm << " noExpungeTags = " + << noExpungeTags.ref() << "\n"; + } + else { + strm << " noExpungeTags is not set\n"; + } + + if (noSetParentTag.isSet()) { + strm << " noSetParentTag = " + << noSetParentTag.ref() << "\n"; + } + else { + strm << " noSetParentTag is not set\n"; + } + + if (noCreateSharedNotebooks.isSet()) { + strm << " noCreateSharedNotebooks = " + << noCreateSharedNotebooks.ref() << "\n"; + } + else { + strm << " noCreateSharedNotebooks is not set\n"; + } + + if (updateWhichSharedNotebookRestrictions.isSet()) { + strm << " updateWhichSharedNotebookRestrictions = " + << updateWhichSharedNotebookRestrictions.ref() << "\n"; + } + else { + strm << " updateWhichSharedNotebookRestrictions is not set\n"; + } + + if (expungeWhichSharedNotebookRestrictions.isSet()) { + strm << " expungeWhichSharedNotebookRestrictions = " + << expungeWhichSharedNotebookRestrictions.ref() << "\n"; + } + else { + strm << " expungeWhichSharedNotebookRestrictions is not set\n"; + } + + if (noShareNotesWithBusiness.isSet()) { + strm << " noShareNotesWithBusiness = " + << noShareNotesWithBusiness.ref() << "\n"; + } + else { + strm << " noShareNotesWithBusiness is not set\n"; + } + + if (noRenameNotebook.isSet()) { + strm << " noRenameNotebook = " + << noRenameNotebook.ref() << "\n"; + } + else { + strm << " noRenameNotebook is not set\n"; + } + + if (noSetInMyList.isSet()) { + strm << " noSetInMyList = " + << noSetInMyList.ref() << "\n"; + } + else { + strm << " noSetInMyList is not set\n"; + } + + if (noChangeContact.isSet()) { + strm << " noChangeContact = " + << noChangeContact.ref() << "\n"; + } + else { + strm << " noChangeContact is not set\n"; + } + + if (canMoveToContainerRestrictions.isSet()) { + strm << " canMoveToContainerRestrictions = " + << canMoveToContainerRestrictions.ref() << "\n"; + } + else { + strm << " canMoveToContainerRestrictions is not set\n"; + } + + if (noSetReminderNotifyEmail.isSet()) { + strm << " noSetReminderNotifyEmail = " + << noSetReminderNotifyEmail.ref() << "\n"; + } + else { + strm << " noSetReminderNotifyEmail is not set\n"; + } + + if (noSetReminderNotifyInApp.isSet()) { + strm << " noSetReminderNotifyInApp = " + << noSetReminderNotifyInApp.ref() << "\n"; + } + else { + strm << " noSetReminderNotifyInApp is not set\n"; + } + + if (noSetRecipientSettingsStack.isSet()) { + strm << " noSetRecipientSettingsStack = " + << noSetRecipientSettingsStack.ref() << "\n"; + } + else { + strm << " noSetRecipientSettingsStack is not set\n"; + } + + if (noCanMoveNote.isSet()) { + strm << " noCanMoveNote = " + << noCanMoveNote.ref() << "\n"; + } + else { + strm << " noCanMoveNote is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNotebook( + ThriftBinaryBufferWriter & writer, + const Notebook & s) +{ + writer.writeStructBegin(QStringLiteral("Notebook")); + if (s.guid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.guid.ref()); + writer.writeFieldEnd(); + } + + if (s.name.isSet()) { + writer.writeFieldBegin( + QStringLiteral("name"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.name.ref()); + writer.writeFieldEnd(); + } + + if (s.updateSequenceNum.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updateSequenceNum"), + ThriftFieldType::T_I32, + 5); + + writer.writeI32(s.updateSequenceNum.ref()); + writer.writeFieldEnd(); + } + + if (s.defaultNotebook.isSet()) { + writer.writeFieldBegin( + QStringLiteral("defaultNotebook"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(s.defaultNotebook.ref()); + writer.writeFieldEnd(); + } + + if (s.serviceCreated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("serviceCreated"), + ThriftFieldType::T_I64, + 7); + + writer.writeI64(s.serviceCreated.ref()); + writer.writeFieldEnd(); + } + + if (s.serviceUpdated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("serviceUpdated"), + ThriftFieldType::T_I64, + 8); + + writer.writeI64(s.serviceUpdated.ref()); + writer.writeFieldEnd(); + } + + if (s.publishing.isSet()) { + writer.writeFieldBegin( + QStringLiteral("publishing"), + ThriftFieldType::T_STRUCT, + 10); + + writePublishing(writer, s.publishing.ref()); + writer.writeFieldEnd(); + } + + if (s.published.isSet()) { + writer.writeFieldBegin( + QStringLiteral("published"), + ThriftFieldType::T_BOOL, + 11); + + writer.writeBool(s.published.ref()); + writer.writeFieldEnd(); + } + + if (s.stack.isSet()) { + writer.writeFieldBegin( + QStringLiteral("stack"), + ThriftFieldType::T_STRING, + 12); + + writer.writeString(s.stack.ref()); + writer.writeFieldEnd(); + } + + if (s.sharedNotebookIds.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sharedNotebookIds"), + ThriftFieldType::T_LIST, + 13); + + writer.writeListBegin(ThriftFieldType::T_I64, s.sharedNotebookIds.ref().length()); + for(const auto & value: qAsConst(s.sharedNotebookIds.ref())) { + writer.writeI64(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.sharedNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sharedNotebooks"), + ThriftFieldType::T_LIST, + 14); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.sharedNotebooks.ref().length()); + for(const auto & value: qAsConst(s.sharedNotebooks.ref())) { + writeSharedNotebook(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.businessNotebook.isSet()) { + writer.writeFieldBegin( + QStringLiteral("businessNotebook"), + ThriftFieldType::T_STRUCT, + 15); + + writeBusinessNotebook(writer, s.businessNotebook.ref()); + writer.writeFieldEnd(); + } + + if (s.contact.isSet()) { + writer.writeFieldBegin( + QStringLiteral("contact"), + ThriftFieldType::T_STRUCT, + 16); + + writeUser(writer, s.contact.ref()); + writer.writeFieldEnd(); + } + + if (s.restrictions.isSet()) { + writer.writeFieldBegin( + QStringLiteral("restrictions"), + ThriftFieldType::T_STRUCT, + 17); + + writeNotebookRestrictions(writer, s.restrictions.ref()); + writer.writeFieldEnd(); + } + + if (s.recipientSettings.isSet()) { + writer.writeFieldBegin( + QStringLiteral("recipientSettings"), + ThriftFieldType::T_STRUCT, + 18); + + writeNotebookRecipientSettings(writer, s.recipientSettings.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNotebook( + ThriftBinaryBufferReader & reader, + Notebook & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.guid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.name = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.updateSequenceNum = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.defaultNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.serviceCreated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.serviceUpdated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_STRUCT) { + Publishing v; + readPublishing(reader, v); + s.publishing = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.published = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.stack = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_I64) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (Notebook.sharedNotebookIds)")); + } + for(qint32 i = 0; i < size; i++) { + qint64 elem; + reader.readI64(elem); + v.append(elem); + } + reader.readListEnd(); + s.sharedNotebookIds = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 14) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (Notebook.sharedNotebooks)")); + } + for(qint32 i = 0; i < size; i++) { + SharedNotebook elem; + readSharedNotebook(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.sharedNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 15) { + if (fieldType == ThriftFieldType::T_STRUCT) { + BusinessNotebook v; + readBusinessNotebook(reader, v); + s.businessNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 16) { + if (fieldType == ThriftFieldType::T_STRUCT) { + User v; + readUser(reader, v); + s.contact = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 17) { + if (fieldType == ThriftFieldType::T_STRUCT) { + NotebookRestrictions v; + readNotebookRestrictions(reader, v); + s.restrictions = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 18) { + if (fieldType == ThriftFieldType::T_STRUCT) { + NotebookRecipientSettings v; + readNotebookRecipientSettings(reader, v); + s.recipientSettings = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void Notebook::print(QTextStream & strm) const +{ + strm << "Notebook: {\n"; + localData.print(strm); + + if (guid.isSet()) { + strm << " guid = " + << guid.ref() << "\n"; + } + else { + strm << " guid is not set\n"; + } + + if (name.isSet()) { + strm << " name = " + << name.ref() << "\n"; + } + else { + strm << " name is not set\n"; + } + + if (updateSequenceNum.isSet()) { + strm << " updateSequenceNum = " + << updateSequenceNum.ref() << "\n"; + } + else { + strm << " updateSequenceNum is not set\n"; + } + + if (defaultNotebook.isSet()) { + strm << " defaultNotebook = " + << defaultNotebook.ref() << "\n"; + } + else { + strm << " defaultNotebook is not set\n"; + } + + if (serviceCreated.isSet()) { + strm << " serviceCreated = " + << serviceCreated.ref() << "\n"; + } + else { + strm << " serviceCreated is not set\n"; + } + + if (serviceUpdated.isSet()) { + strm << " serviceUpdated = " + << serviceUpdated.ref() << "\n"; + } + else { + strm << " serviceUpdated is not set\n"; + } + + if (publishing.isSet()) { + strm << " publishing = " + << publishing.ref() << "\n"; + } + else { + strm << " publishing is not set\n"; + } + + if (published.isSet()) { + strm << " published = " + << published.ref() << "\n"; + } + else { + strm << " published is not set\n"; + } + + if (stack.isSet()) { + strm << " stack = " + << stack.ref() << "\n"; + } + else { + strm << " stack is not set\n"; + } + + if (sharedNotebookIds.isSet()) { + strm << " sharedNotebookIds = " + << "QList {"; + for(const auto & v: sharedNotebookIds.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " sharedNotebookIds is not set\n"; + } + + if (sharedNotebooks.isSet()) { + strm << " sharedNotebooks = " + << "QList {"; + for(const auto & v: sharedNotebooks.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " sharedNotebooks is not set\n"; + } + + if (businessNotebook.isSet()) { + strm << " businessNotebook = " + << businessNotebook.ref() << "\n"; + } + else { + strm << " businessNotebook is not set\n"; + } + + if (contact.isSet()) { + strm << " contact = " + << contact.ref() << "\n"; + } + else { + strm << " contact is not set\n"; + } + + if (restrictions.isSet()) { + strm << " restrictions = " + << restrictions.ref() << "\n"; + } + else { + strm << " restrictions is not set\n"; + } + + if (recipientSettings.isSet()) { + strm << " recipientSettings = " + << recipientSettings.ref() << "\n"; + } + else { + strm << " recipientSettings is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeLinkedNotebook( + ThriftBinaryBufferWriter & writer, + const LinkedNotebook & s) +{ + writer.writeStructBegin(QStringLiteral("LinkedNotebook")); + if (s.shareName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("shareName"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.shareName.ref()); + writer.writeFieldEnd(); + } + + if (s.username.isSet()) { + writer.writeFieldBegin( + QStringLiteral("username"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.username.ref()); + writer.writeFieldEnd(); + } + + if (s.shardId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("shardId"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.shardId.ref()); + writer.writeFieldEnd(); + } + + if (s.sharedNotebookGlobalId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sharedNotebookGlobalId"), + ThriftFieldType::T_STRING, + 5); + + writer.writeString(s.sharedNotebookGlobalId.ref()); + writer.writeFieldEnd(); + } + + if (s.uri.isSet()) { + writer.writeFieldBegin( + QStringLiteral("uri"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.uri.ref()); + writer.writeFieldEnd(); + } + + if (s.guid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 7); + + writer.writeString(s.guid.ref()); + writer.writeFieldEnd(); + } + + if (s.updateSequenceNum.isSet()) { + writer.writeFieldBegin( + QStringLiteral("updateSequenceNum"), + ThriftFieldType::T_I32, + 8); + + writer.writeI32(s.updateSequenceNum.ref()); + writer.writeFieldEnd(); + } + + if (s.noteStoreUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteStoreUrl"), + ThriftFieldType::T_STRING, + 9); + + writer.writeString(s.noteStoreUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.webApiUrlPrefix.isSet()) { + writer.writeFieldBegin( + QStringLiteral("webApiUrlPrefix"), + ThriftFieldType::T_STRING, + 10); + + writer.writeString(s.webApiUrlPrefix.ref()); + writer.writeFieldEnd(); + } + + if (s.stack.isSet()) { + writer.writeFieldBegin( + QStringLiteral("stack"), + ThriftFieldType::T_STRING, + 11); + + writer.writeString(s.stack.ref()); + writer.writeFieldEnd(); + } + + if (s.businessId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("businessId"), + ThriftFieldType::T_I32, + 12); + + writer.writeI32(s.businessId.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readLinkedNotebook( + ThriftBinaryBufferReader & reader, + LinkedNotebook & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.shareName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.username = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.shardId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.sharedNotebookGlobalId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.uri = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.guid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.updateSequenceNum = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.noteStoreUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.webApiUrlPrefix = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.stack = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.businessId = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void LinkedNotebook::print(QTextStream & strm) const +{ + strm << "LinkedNotebook: {\n"; + localData.print(strm); + + if (shareName.isSet()) { + strm << " shareName = " + << shareName.ref() << "\n"; + } + else { + strm << " shareName is not set\n"; + } + + if (username.isSet()) { + strm << " username = " + << username.ref() << "\n"; + } + else { + strm << " username is not set\n"; + } + + if (shardId.isSet()) { + strm << " shardId = " + << shardId.ref() << "\n"; + } + else { + strm << " shardId is not set\n"; + } + + if (sharedNotebookGlobalId.isSet()) { + strm << " sharedNotebookGlobalId = " + << sharedNotebookGlobalId.ref() << "\n"; + } + else { + strm << " sharedNotebookGlobalId is not set\n"; + } + + if (uri.isSet()) { + strm << " uri = " + << uri.ref() << "\n"; + } + else { + strm << " uri is not set\n"; + } + + if (guid.isSet()) { + strm << " guid = " + << guid.ref() << "\n"; + } + else { + strm << " guid is not set\n"; + } + + if (updateSequenceNum.isSet()) { + strm << " updateSequenceNum = " + << updateSequenceNum.ref() << "\n"; + } + else { + strm << " updateSequenceNum is not set\n"; + } + + if (noteStoreUrl.isSet()) { + strm << " noteStoreUrl = " + << noteStoreUrl.ref() << "\n"; + } + else { + strm << " noteStoreUrl is not set\n"; + } + + if (webApiUrlPrefix.isSet()) { + strm << " webApiUrlPrefix = " + << webApiUrlPrefix.ref() << "\n"; + } + else { + strm << " webApiUrlPrefix is not set\n"; + } + + if (stack.isSet()) { + strm << " stack = " + << stack.ref() << "\n"; + } + else { + strm << " stack is not set\n"; + } + + if (businessId.isSet()) { + strm << " businessId = " + << businessId.ref() << "\n"; + } + else { + strm << " businessId is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeNotebookDescriptor( + ThriftBinaryBufferWriter & writer, + const NotebookDescriptor & s) +{ + writer.writeStructBegin(QStringLiteral("NotebookDescriptor")); + if (s.guid.isSet()) { + writer.writeFieldBegin( + QStringLiteral("guid"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.guid.ref()); + writer.writeFieldEnd(); + } + + if (s.notebookDisplayName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("notebookDisplayName"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.notebookDisplayName.ref()); + writer.writeFieldEnd(); + } + + if (s.contactName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("contactName"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.contactName.ref()); + writer.writeFieldEnd(); + } + + if (s.hasSharedNotebook.isSet()) { + writer.writeFieldBegin( + QStringLiteral("hasSharedNotebook"), + ThriftFieldType::T_BOOL, + 4); + + writer.writeBool(s.hasSharedNotebook.ref()); + writer.writeFieldEnd(); + } + + if (s.joinedUserCount.isSet()) { + writer.writeFieldBegin( + QStringLiteral("joinedUserCount"), + ThriftFieldType::T_I32, + 5); + + writer.writeI32(s.joinedUserCount.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readNotebookDescriptor( + ThriftBinaryBufferReader & reader, + NotebookDescriptor & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + Guid v; + reader.readString(v); + s.guid = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.notebookDisplayName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.contactName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.hasSharedNotebook = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.joinedUserCount = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void NotebookDescriptor::print(QTextStream & strm) const +{ + strm << "NotebookDescriptor: {\n"; + localData.print(strm); + + if (guid.isSet()) { + strm << " guid = " + << guid.ref() << "\n"; + } + else { + strm << " guid is not set\n"; + } + + if (notebookDisplayName.isSet()) { + strm << " notebookDisplayName = " + << notebookDisplayName.ref() << "\n"; + } + else { + strm << " notebookDisplayName is not set\n"; + } + + if (contactName.isSet()) { + strm << " contactName = " + << contactName.ref() << "\n"; + } + else { + strm << " contactName is not set\n"; + } + + if (hasSharedNotebook.isSet()) { + strm << " hasSharedNotebook = " + << hasSharedNotebook.ref() << "\n"; + } + else { + strm << " hasSharedNotebook is not set\n"; + } + + if (joinedUserCount.isSet()) { + strm << " joinedUserCount = " + << joinedUserCount.ref() << "\n"; + } + else { + strm << " joinedUserCount is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeUserProfile( + ThriftBinaryBufferWriter & writer, + const UserProfile & s) +{ + writer.writeStructBegin(QStringLiteral("UserProfile")); + if (s.id.isSet()) { + writer.writeFieldBegin( + QStringLiteral("id"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.id.ref()); + writer.writeFieldEnd(); + } + + if (s.name.isSet()) { + writer.writeFieldBegin( + QStringLiteral("name"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.name.ref()); + writer.writeFieldEnd(); + } + + if (s.email.isSet()) { + writer.writeFieldBegin( + QStringLiteral("email"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.email.ref()); + writer.writeFieldEnd(); + } + + if (s.username.isSet()) { + writer.writeFieldBegin( + QStringLiteral("username"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.username.ref()); + writer.writeFieldEnd(); + } + + if (s.attributes.isSet()) { + writer.writeFieldBegin( + QStringLiteral("attributes"), + ThriftFieldType::T_STRUCT, + 5); + + writeBusinessUserAttributes(writer, s.attributes.ref()); + writer.writeFieldEnd(); + } + + if (s.joined.isSet()) { + writer.writeFieldBegin( + QStringLiteral("joined"), + ThriftFieldType::T_I64, + 6); + + writer.writeI64(s.joined.ref()); + writer.writeFieldEnd(); + } + + if (s.photoLastUpdated.isSet()) { + writer.writeFieldBegin( + QStringLiteral("photoLastUpdated"), + ThriftFieldType::T_I64, + 7); + + writer.writeI64(s.photoLastUpdated.ref()); + writer.writeFieldEnd(); + } + + if (s.photoUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("photoUrl"), + ThriftFieldType::T_STRING, + 8); + + writer.writeString(s.photoUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.role.isSet()) { + writer.writeFieldBegin( + QStringLiteral("role"), + ThriftFieldType::T_I32, + 9); + + writer.writeI32(static_cast(s.role.ref())); + writer.writeFieldEnd(); + } + + if (s.status.isSet()) { + writer.writeFieldBegin( + QStringLiteral("status"), + ThriftFieldType::T_I32, + 10); + + writer.writeI32(static_cast(s.status.ref())); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readUserProfile( + ThriftBinaryBufferReader & reader, + UserProfile & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.id = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.name = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.email = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.username = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_STRUCT) { + BusinessUserAttributes v; + readBusinessUserAttributes(reader, v); + s.attributes = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.joined = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.photoLastUpdated = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.photoUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_I32) { + BusinessUserRole v; + readEnumBusinessUserRole(reader, v); + s.role = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_I32) { + BusinessUserStatus v; + readEnumBusinessUserStatus(reader, v); + s.status = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void UserProfile::print(QTextStream & strm) const +{ + strm << "UserProfile: {\n"; + localData.print(strm); + + if (id.isSet()) { + strm << " id = " + << id.ref() << "\n"; + } + else { + strm << " id is not set\n"; + } + + if (name.isSet()) { + strm << " name = " + << name.ref() << "\n"; + } + else { + strm << " name is not set\n"; + } + + if (email.isSet()) { + strm << " email = " + << email.ref() << "\n"; + } + else { + strm << " email is not set\n"; + } + + if (username.isSet()) { + strm << " username = " + << username.ref() << "\n"; + } + else { + strm << " username is not set\n"; + } + + if (attributes.isSet()) { + strm << " attributes = " + << attributes.ref() << "\n"; + } + else { + strm << " attributes is not set\n"; + } + + if (joined.isSet()) { + strm << " joined = " + << joined.ref() << "\n"; + } + else { + strm << " joined is not set\n"; + } + + if (photoLastUpdated.isSet()) { + strm << " photoLastUpdated = " + << photoLastUpdated.ref() << "\n"; + } + else { + strm << " photoLastUpdated is not set\n"; + } + + if (photoUrl.isSet()) { + strm << " photoUrl = " + << photoUrl.ref() << "\n"; + } + else { + strm << " photoUrl is not set\n"; + } + + if (role.isSet()) { + strm << " role = " + << role.ref() << "\n"; + } + else { + strm << " role is not set\n"; + } + + if (status.isSet()) { + strm << " status = " + << status.ref() << "\n"; + } + else { + strm << " status is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeRelatedContentImage( + ThriftBinaryBufferWriter & writer, + const RelatedContentImage & s) +{ + writer.writeStructBegin(QStringLiteral("RelatedContentImage")); + if (s.url.isSet()) { + writer.writeFieldBegin( + QStringLiteral("url"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.url.ref()); + writer.writeFieldEnd(); + } + + if (s.width.isSet()) { + writer.writeFieldBegin( + QStringLiteral("width"), + ThriftFieldType::T_I32, + 2); + + writer.writeI32(s.width.ref()); + writer.writeFieldEnd(); + } + + if (s.height.isSet()) { + writer.writeFieldBegin( + QStringLiteral("height"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(s.height.ref()); + writer.writeFieldEnd(); + } + + if (s.pixelRatio.isSet()) { + writer.writeFieldBegin( + QStringLiteral("pixelRatio"), + ThriftFieldType::T_DOUBLE, + 4); + + writer.writeDouble(s.pixelRatio.ref()); + writer.writeFieldEnd(); + } + + if (s.fileSize.isSet()) { + writer.writeFieldBegin( + QStringLiteral("fileSize"), + ThriftFieldType::T_I32, + 5); + + writer.writeI32(s.fileSize.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readRelatedContentImage( + ThriftBinaryBufferReader & reader, + RelatedContentImage & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.url = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.width = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.height = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_DOUBLE) { + double v; + reader.readDouble(v); + s.pixelRatio = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.fileSize = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void RelatedContentImage::print(QTextStream & strm) const +{ + strm << "RelatedContentImage: {\n"; + localData.print(strm); + + if (url.isSet()) { + strm << " url = " + << url.ref() << "\n"; + } + else { + strm << " url is not set\n"; + } + + if (width.isSet()) { + strm << " width = " + << width.ref() << "\n"; + } + else { + strm << " width is not set\n"; + } + + if (height.isSet()) { + strm << " height = " + << height.ref() << "\n"; + } + else { + strm << " height is not set\n"; + } + + if (pixelRatio.isSet()) { + strm << " pixelRatio = " + << pixelRatio.ref() << "\n"; + } + else { + strm << " pixelRatio is not set\n"; + } + + if (fileSize.isSet()) { + strm << " fileSize = " + << fileSize.ref() << "\n"; + } + else { + strm << " fileSize is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeRelatedContent( + ThriftBinaryBufferWriter & writer, + const RelatedContent & s) +{ + writer.writeStructBegin(QStringLiteral("RelatedContent")); + if (s.contentId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("contentId"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.contentId.ref()); + writer.writeFieldEnd(); + } + + if (s.title.isSet()) { + writer.writeFieldBegin( + QStringLiteral("title"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.title.ref()); + writer.writeFieldEnd(); + } + + if (s.url.isSet()) { + writer.writeFieldBegin( + QStringLiteral("url"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.url.ref()); + writer.writeFieldEnd(); + } + + if (s.sourceId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sourceId"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.sourceId.ref()); + writer.writeFieldEnd(); + } + + if (s.sourceUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sourceUrl"), + ThriftFieldType::T_STRING, + 5); + + writer.writeString(s.sourceUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.sourceFaviconUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sourceFaviconUrl"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.sourceFaviconUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.sourceName.isSet()) { + writer.writeFieldBegin( + QStringLiteral("sourceName"), + ThriftFieldType::T_STRING, + 7); + + writer.writeString(s.sourceName.ref()); + writer.writeFieldEnd(); + } + + if (s.date.isSet()) { + writer.writeFieldBegin( + QStringLiteral("date"), + ThriftFieldType::T_I64, + 8); + + writer.writeI64(s.date.ref()); + writer.writeFieldEnd(); + } + + if (s.teaser.isSet()) { + writer.writeFieldBegin( + QStringLiteral("teaser"), + ThriftFieldType::T_STRING, + 9); + + writer.writeString(s.teaser.ref()); + writer.writeFieldEnd(); + } + + if (s.thumbnails.isSet()) { + writer.writeFieldBegin( + QStringLiteral("thumbnails"), + ThriftFieldType::T_LIST, + 10); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.thumbnails.ref().length()); + for(const auto & value: qAsConst(s.thumbnails.ref())) { + writeRelatedContentImage(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + if (s.contentType.isSet()) { + writer.writeFieldBegin( + QStringLiteral("contentType"), + ThriftFieldType::T_I32, + 11); + + writer.writeI32(static_cast(s.contentType.ref())); + writer.writeFieldEnd(); + } + + if (s.accessType.isSet()) { + writer.writeFieldBegin( + QStringLiteral("accessType"), + ThriftFieldType::T_I32, + 12); + + writer.writeI32(static_cast(s.accessType.ref())); + writer.writeFieldEnd(); + } + + if (s.visibleUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("visibleUrl"), + ThriftFieldType::T_STRING, + 13); + + writer.writeString(s.visibleUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.clipUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("clipUrl"), + ThriftFieldType::T_STRING, + 14); + + writer.writeString(s.clipUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.contact.isSet()) { + writer.writeFieldBegin( + QStringLiteral("contact"), + ThriftFieldType::T_STRUCT, + 15); + + writeContact(writer, s.contact.ref()); + writer.writeFieldEnd(); + } + + if (s.authors.isSet()) { + writer.writeFieldBegin( + QStringLiteral("authors"), + ThriftFieldType::T_LIST, + 16); + + writer.writeListBegin(ThriftFieldType::T_STRING, s.authors.ref().length()); + for(const auto & value: qAsConst(s.authors.ref())) { + writer.writeString(value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readRelatedContent( + ThriftBinaryBufferReader & reader, + RelatedContent & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.contentId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.title = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.url = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.sourceId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.sourceUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.sourceFaviconUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.sourceName = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.date = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.teaser = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (RelatedContent.thumbnails)")); + } + for(qint32 i = 0; i < size; i++) { + RelatedContentImage elem; + readRelatedContentImage(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.thumbnails = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_I32) { + RelatedContentType v; + readEnumRelatedContentType(reader, v); + s.contentType = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_I32) { + RelatedContentAccess v; + readEnumRelatedContentAccess(reader, v); + s.accessType = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.visibleUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 14) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.clipUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 15) { + if (fieldType == ThriftFieldType::T_STRUCT) { + Contact v; + readContact(reader, v); + s.contact = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 16) { + if (fieldType == ThriftFieldType::T_LIST) { + QStringList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRING) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (RelatedContent.authors)")); + } + for(qint32 i = 0; i < size; i++) { + QString elem; + reader.readString(elem); + v.append(elem); + } + reader.readListEnd(); + s.authors = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void RelatedContent::print(QTextStream & strm) const +{ + strm << "RelatedContent: {\n"; + localData.print(strm); + + if (contentId.isSet()) { + strm << " contentId = " + << contentId.ref() << "\n"; + } + else { + strm << " contentId is not set\n"; + } + + if (title.isSet()) { + strm << " title = " + << title.ref() << "\n"; + } + else { + strm << " title is not set\n"; + } + + if (url.isSet()) { + strm << " url = " + << url.ref() << "\n"; + } + else { + strm << " url is not set\n"; + } + + if (sourceId.isSet()) { + strm << " sourceId = " + << sourceId.ref() << "\n"; + } + else { + strm << " sourceId is not set\n"; + } + + if (sourceUrl.isSet()) { + strm << " sourceUrl = " + << sourceUrl.ref() << "\n"; + } + else { + strm << " sourceUrl is not set\n"; + } + + if (sourceFaviconUrl.isSet()) { + strm << " sourceFaviconUrl = " + << sourceFaviconUrl.ref() << "\n"; + } + else { + strm << " sourceFaviconUrl is not set\n"; + } + + if (sourceName.isSet()) { + strm << " sourceName = " + << sourceName.ref() << "\n"; + } + else { + strm << " sourceName is not set\n"; + } + + if (date.isSet()) { + strm << " date = " + << date.ref() << "\n"; + } + else { + strm << " date is not set\n"; + } + + if (teaser.isSet()) { + strm << " teaser = " + << teaser.ref() << "\n"; + } + else { + strm << " teaser is not set\n"; + } + + if (thumbnails.isSet()) { + strm << " thumbnails = " + << "QList {"; + for(const auto & v: thumbnails.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " thumbnails is not set\n"; + } + + if (contentType.isSet()) { + strm << " contentType = " + << contentType.ref() << "\n"; + } + else { + strm << " contentType is not set\n"; + } + + if (accessType.isSet()) { + strm << " accessType = " + << accessType.ref() << "\n"; + } + else { + strm << " accessType is not set\n"; + } + + if (visibleUrl.isSet()) { + strm << " visibleUrl = " + << visibleUrl.ref() << "\n"; + } + else { + strm << " visibleUrl is not set\n"; + } + + if (clipUrl.isSet()) { + strm << " clipUrl = " + << clipUrl.ref() << "\n"; + } + else { + strm << " clipUrl is not set\n"; + } + + if (contact.isSet()) { + strm << " contact = " + << contact.ref() << "\n"; + } + else { + strm << " contact is not set\n"; + } + + if (authors.isSet()) { + strm << " authors = " + << "QList {"; + for(const auto & v: authors.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " authors is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeBusinessInvitation( + ThriftBinaryBufferWriter & writer, + const BusinessInvitation & s) +{ + writer.writeStructBegin(QStringLiteral("BusinessInvitation")); + if (s.businessId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("businessId"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.businessId.ref()); + writer.writeFieldEnd(); + } + + if (s.email.isSet()) { + writer.writeFieldBegin( + QStringLiteral("email"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.email.ref()); + writer.writeFieldEnd(); + } + + if (s.role.isSet()) { + writer.writeFieldBegin( + QStringLiteral("role"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(static_cast(s.role.ref())); + writer.writeFieldEnd(); + } + + if (s.status.isSet()) { + writer.writeFieldBegin( + QStringLiteral("status"), + ThriftFieldType::T_I32, + 4); + + writer.writeI32(static_cast(s.status.ref())); + writer.writeFieldEnd(); + } + + if (s.requesterId.isSet()) { + writer.writeFieldBegin( + QStringLiteral("requesterId"), + ThriftFieldType::T_I32, + 5); + + writer.writeI32(s.requesterId.ref()); + writer.writeFieldEnd(); + } + + if (s.fromWorkChat.isSet()) { + writer.writeFieldBegin( + QStringLiteral("fromWorkChat"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(s.fromWorkChat.ref()); + writer.writeFieldEnd(); + } + + if (s.created.isSet()) { + writer.writeFieldBegin( + QStringLiteral("created"), + ThriftFieldType::T_I64, + 7); + + writer.writeI64(s.created.ref()); + writer.writeFieldEnd(); + } + + if (s.mostRecentReminder.isSet()) { + writer.writeFieldBegin( + QStringLiteral("mostRecentReminder"), + ThriftFieldType::T_I64, + 8); + + writer.writeI64(s.mostRecentReminder.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readBusinessInvitation( + ThriftBinaryBufferReader & reader, + BusinessInvitation & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.businessId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.email = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + BusinessUserRole v; + readEnumBusinessUserRole(reader, v); + s.role = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_I32) { + BusinessInvitationStatus v; + readEnumBusinessInvitationStatus(reader, v); + s.status = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_I32) { + UserID v; + reader.readI32(v); + s.requesterId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.fromWorkChat = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.created = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.mostRecentReminder = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void BusinessInvitation::print(QTextStream & strm) const +{ + strm << "BusinessInvitation: {\n"; + localData.print(strm); + + if (businessId.isSet()) { + strm << " businessId = " + << businessId.ref() << "\n"; + } + else { + strm << " businessId is not set\n"; + } + + if (email.isSet()) { + strm << " email = " + << email.ref() << "\n"; + } + else { + strm << " email is not set\n"; + } + + if (role.isSet()) { + strm << " role = " + << role.ref() << "\n"; + } + else { + strm << " role is not set\n"; + } + + if (status.isSet()) { + strm << " status = " + << status.ref() << "\n"; + } + else { + strm << " status is not set\n"; + } + + if (requesterId.isSet()) { + strm << " requesterId = " + << requesterId.ref() << "\n"; + } + else { + strm << " requesterId is not set\n"; + } + + if (fromWorkChat.isSet()) { + strm << " fromWorkChat = " + << fromWorkChat.ref() << "\n"; + } + else { + strm << " fromWorkChat is not set\n"; + } + + if (created.isSet()) { + strm << " created = " + << created.ref() << "\n"; + } + else { + strm << " created is not set\n"; + } + + if (mostRecentReminder.isSet()) { + strm << " mostRecentReminder = " + << mostRecentReminder.ref() << "\n"; + } + else { + strm << " mostRecentReminder is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeUserIdentity( + ThriftBinaryBufferWriter & writer, + const UserIdentity & s) +{ + writer.writeStructBegin(QStringLiteral("UserIdentity")); + if (s.type.isSet()) { + writer.writeFieldBegin( + QStringLiteral("type"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(static_cast(s.type.ref())); + writer.writeFieldEnd(); + } + + if (s.stringIdentifier.isSet()) { + writer.writeFieldBegin( + QStringLiteral("stringIdentifier"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.stringIdentifier.ref()); + writer.writeFieldEnd(); + } + + if (s.longIdentifier.isSet()) { + writer.writeFieldBegin( + QStringLiteral("longIdentifier"), + ThriftFieldType::T_I64, + 3); + + writer.writeI64(s.longIdentifier.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readUserIdentity( + ThriftBinaryBufferReader & reader, + UserIdentity & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + UserIdentityType v; + readEnumUserIdentityType(reader, v); + s.type = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.stringIdentifier = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I64) { + qint64 v; + reader.readI64(v); + s.longIdentifier = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void UserIdentity::print(QTextStream & strm) const +{ + strm << "UserIdentity: {\n"; + localData.print(strm); + + if (type.isSet()) { + strm << " type = " + << type.ref() << "\n"; + } + else { + strm << " type is not set\n"; + } + + if (stringIdentifier.isSet()) { + strm << " stringIdentifier = " + << stringIdentifier.ref() << "\n"; + } + else { + strm << " stringIdentifier is not set\n"; + } + + if (longIdentifier.isSet()) { + strm << " longIdentifier = " + << longIdentifier.ref() << "\n"; + } + else { + strm << " longIdentifier is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writePublicUserInfo( + ThriftBinaryBufferWriter & writer, + const PublicUserInfo & s) +{ + writer.writeStructBegin(QStringLiteral("PublicUserInfo")); + writer.writeFieldBegin( + QStringLiteral("userId"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(s.userId); + writer.writeFieldEnd(); + + if (s.serviceLevel.isSet()) { + writer.writeFieldBegin( + QStringLiteral("serviceLevel"), + ThriftFieldType::T_I32, + 7); + + writer.writeI32(static_cast(s.serviceLevel.ref())); + writer.writeFieldEnd(); + } + + if (s.username.isSet()) { + writer.writeFieldBegin( + QStringLiteral("username"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.username.ref()); + writer.writeFieldEnd(); + } + + if (s.noteStoreUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteStoreUrl"), + ThriftFieldType::T_STRING, + 5); + + writer.writeString(s.noteStoreUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.webApiUrlPrefix.isSet()) { + writer.writeFieldBegin( + QStringLiteral("webApiUrlPrefix"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.webApiUrlPrefix.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readPublicUserInfo( + ThriftBinaryBufferReader & reader, + PublicUserInfo & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool userId_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + userId_isset = true; + UserID v; + reader.readI32(v); + s.userId = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_I32) { + ServiceLevel v; + readEnumServiceLevel(reader, v); + s.serviceLevel = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.username = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.noteStoreUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.webApiUrlPrefix = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!userId_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("PublicUserInfo.userId has no value")); +} + +void PublicUserInfo::print(QTextStream & strm) const +{ + strm << "PublicUserInfo: {\n"; + localData.print(strm); + strm << " userId = " + << userId << "\n"; + + if (serviceLevel.isSet()) { + strm << " serviceLevel = " + << serviceLevel.ref() << "\n"; + } + else { + strm << " serviceLevel is not set\n"; + } + + if (username.isSet()) { + strm << " username = " + << username.ref() << "\n"; + } + else { + strm << " username is not set\n"; + } + + if (noteStoreUrl.isSet()) { + strm << " noteStoreUrl = " + << noteStoreUrl.ref() << "\n"; + } + else { + strm << " noteStoreUrl is not set\n"; + } + + if (webApiUrlPrefix.isSet()) { + strm << " webApiUrlPrefix = " + << webApiUrlPrefix.ref() << "\n"; + } + else { + strm << " webApiUrlPrefix is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeUserUrls( + ThriftBinaryBufferWriter & writer, + const UserUrls & s) +{ + writer.writeStructBegin(QStringLiteral("UserUrls")); + if (s.noteStoreUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteStoreUrl"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.noteStoreUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.webApiUrlPrefix.isSet()) { + writer.writeFieldBegin( + QStringLiteral("webApiUrlPrefix"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.webApiUrlPrefix.ref()); + writer.writeFieldEnd(); + } + + if (s.userStoreUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userStoreUrl"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.userStoreUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.utilityUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("utilityUrl"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.utilityUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.messageStoreUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("messageStoreUrl"), + ThriftFieldType::T_STRING, + 5); + + writer.writeString(s.messageStoreUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.userWebSocketUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("userWebSocketUrl"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.userWebSocketUrl.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readUserUrls( + ThriftBinaryBufferReader & reader, + UserUrls & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.noteStoreUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.webApiUrlPrefix = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.userStoreUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.utilityUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.messageStoreUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.userWebSocketUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void UserUrls::print(QTextStream & strm) const +{ + strm << "UserUrls: {\n"; + localData.print(strm); + + if (noteStoreUrl.isSet()) { + strm << " noteStoreUrl = " + << noteStoreUrl.ref() << "\n"; + } + else { + strm << " noteStoreUrl is not set\n"; + } + + if (webApiUrlPrefix.isSet()) { + strm << " webApiUrlPrefix = " + << webApiUrlPrefix.ref() << "\n"; + } + else { + strm << " webApiUrlPrefix is not set\n"; + } + + if (userStoreUrl.isSet()) { + strm << " userStoreUrl = " + << userStoreUrl.ref() << "\n"; + } + else { + strm << " userStoreUrl is not set\n"; + } + + if (utilityUrl.isSet()) { + strm << " utilityUrl = " + << utilityUrl.ref() << "\n"; + } + else { + strm << " utilityUrl is not set\n"; + } + + if (messageStoreUrl.isSet()) { + strm << " messageStoreUrl = " + << messageStoreUrl.ref() << "\n"; + } + else { + strm << " messageStoreUrl is not set\n"; + } + + if (userWebSocketUrl.isSet()) { + strm << " userWebSocketUrl = " + << userWebSocketUrl.ref() << "\n"; + } + else { + strm << " userWebSocketUrl is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeAuthenticationResult( + ThriftBinaryBufferWriter & writer, + const AuthenticationResult & s) +{ + writer.writeStructBegin(QStringLiteral("AuthenticationResult")); + writer.writeFieldBegin( + QStringLiteral("currentTime"), + ThriftFieldType::T_I64, + 1); + + writer.writeI64(s.currentTime); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("authenticationToken"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.authenticationToken); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("expiration"), + ThriftFieldType::T_I64, + 3); + + writer.writeI64(s.expiration); + writer.writeFieldEnd(); + + if (s.user.isSet()) { + writer.writeFieldBegin( + QStringLiteral("user"), + ThriftFieldType::T_STRUCT, + 4); + + writeUser(writer, s.user.ref()); + writer.writeFieldEnd(); + } + + if (s.publicUserInfo.isSet()) { + writer.writeFieldBegin( + QStringLiteral("publicUserInfo"), + ThriftFieldType::T_STRUCT, + 5); + + writePublicUserInfo(writer, s.publicUserInfo.ref()); + writer.writeFieldEnd(); + } + + if (s.noteStoreUrl.isSet()) { + writer.writeFieldBegin( + QStringLiteral("noteStoreUrl"), + ThriftFieldType::T_STRING, + 6); + + writer.writeString(s.noteStoreUrl.ref()); + writer.writeFieldEnd(); + } + + if (s.webApiUrlPrefix.isSet()) { + writer.writeFieldBegin( + QStringLiteral("webApiUrlPrefix"), + ThriftFieldType::T_STRING, + 7); + + writer.writeString(s.webApiUrlPrefix.ref()); + writer.writeFieldEnd(); + } + + if (s.secondFactorRequired.isSet()) { + writer.writeFieldBegin( + QStringLiteral("secondFactorRequired"), + ThriftFieldType::T_BOOL, + 8); + + writer.writeBool(s.secondFactorRequired.ref()); + writer.writeFieldEnd(); + } + + if (s.secondFactorDeliveryHint.isSet()) { + writer.writeFieldBegin( + QStringLiteral("secondFactorDeliveryHint"), + ThriftFieldType::T_STRING, + 9); + + writer.writeString(s.secondFactorDeliveryHint.ref()); + writer.writeFieldEnd(); + } + + if (s.urls.isSet()) { + writer.writeFieldBegin( + QStringLiteral("urls"), + ThriftFieldType::T_STRUCT, + 10); + + writeUserUrls(writer, s.urls.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readAuthenticationResult( + ThriftBinaryBufferReader & reader, + AuthenticationResult & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool currentTime_isset = false; + bool authenticationToken_isset = false; + bool expiration_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I64) { + currentTime_isset = true; + qint64 v; + reader.readI64(v); + s.currentTime = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + authenticationToken_isset = true; + QString v; + reader.readString(v); + s.authenticationToken = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I64) { + expiration_isset = true; + qint64 v; + reader.readI64(v); + s.expiration = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRUCT) { + User v; + readUser(reader, v); + s.user = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_STRUCT) { + PublicUserInfo v; + readPublicUserInfo(reader, v); + s.publicUserInfo = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.noteStoreUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.webApiUrlPrefix = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.secondFactorRequired = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.secondFactorDeliveryHint = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_STRUCT) { + UserUrls v; + readUserUrls(reader, v); + s.urls = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!currentTime_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("AuthenticationResult.currentTime has no value")); + if (!authenticationToken_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("AuthenticationResult.authenticationToken has no value")); + if (!expiration_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("AuthenticationResult.expiration has no value")); +} + +void AuthenticationResult::print(QTextStream & strm) const +{ + strm << "AuthenticationResult: {\n"; + localData.print(strm); + strm << " currentTime = " + << currentTime << "\n"; + strm << " authenticationToken = " + << authenticationToken << "\n"; + strm << " expiration = " + << expiration << "\n"; + + if (user.isSet()) { + strm << " user = " + << user.ref() << "\n"; + } + else { + strm << " user is not set\n"; + } + + if (publicUserInfo.isSet()) { + strm << " publicUserInfo = " + << publicUserInfo.ref() << "\n"; + } + else { + strm << " publicUserInfo is not set\n"; + } + + if (noteStoreUrl.isSet()) { + strm << " noteStoreUrl = " + << noteStoreUrl.ref() << "\n"; + } + else { + strm << " noteStoreUrl is not set\n"; + } + + if (webApiUrlPrefix.isSet()) { + strm << " webApiUrlPrefix = " + << webApiUrlPrefix.ref() << "\n"; + } + else { + strm << " webApiUrlPrefix is not set\n"; + } + + if (secondFactorRequired.isSet()) { + strm << " secondFactorRequired = " + << secondFactorRequired.ref() << "\n"; + } + else { + strm << " secondFactorRequired is not set\n"; + } + + if (secondFactorDeliveryHint.isSet()) { + strm << " secondFactorDeliveryHint = " + << secondFactorDeliveryHint.ref() << "\n"; + } + else { + strm << " secondFactorDeliveryHint is not set\n"; + } + + if (urls.isSet()) { + strm << " urls = " + << urls.ref() << "\n"; + } + else { + strm << " urls is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeBootstrapSettings( + ThriftBinaryBufferWriter & writer, + const BootstrapSettings & s) +{ + writer.writeStructBegin(QStringLiteral("BootstrapSettings")); + writer.writeFieldBegin( + QStringLiteral("serviceHost"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.serviceHost); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("marketingUrl"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.marketingUrl); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("supportUrl"), + ThriftFieldType::T_STRING, + 3); + + writer.writeString(s.supportUrl); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("accountEmailDomain"), + ThriftFieldType::T_STRING, + 4); + + writer.writeString(s.accountEmailDomain); + writer.writeFieldEnd(); + + if (s.enableFacebookSharing.isSet()) { + writer.writeFieldBegin( + QStringLiteral("enableFacebookSharing"), + ThriftFieldType::T_BOOL, + 5); + + writer.writeBool(s.enableFacebookSharing.ref()); + writer.writeFieldEnd(); + } + + if (s.enableGiftSubscriptions.isSet()) { + writer.writeFieldBegin( + QStringLiteral("enableGiftSubscriptions"), + ThriftFieldType::T_BOOL, + 6); + + writer.writeBool(s.enableGiftSubscriptions.ref()); + writer.writeFieldEnd(); + } + + if (s.enableSupportTickets.isSet()) { + writer.writeFieldBegin( + QStringLiteral("enableSupportTickets"), + ThriftFieldType::T_BOOL, + 7); + + writer.writeBool(s.enableSupportTickets.ref()); + writer.writeFieldEnd(); + } + + if (s.enableSharedNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("enableSharedNotebooks"), + ThriftFieldType::T_BOOL, + 8); + + writer.writeBool(s.enableSharedNotebooks.ref()); + writer.writeFieldEnd(); + } + + if (s.enableSingleNoteSharing.isSet()) { + writer.writeFieldBegin( + QStringLiteral("enableSingleNoteSharing"), + ThriftFieldType::T_BOOL, + 9); + + writer.writeBool(s.enableSingleNoteSharing.ref()); + writer.writeFieldEnd(); + } + + if (s.enableSponsoredAccounts.isSet()) { + writer.writeFieldBegin( + QStringLiteral("enableSponsoredAccounts"), + ThriftFieldType::T_BOOL, + 10); + + writer.writeBool(s.enableSponsoredAccounts.ref()); + writer.writeFieldEnd(); + } + + if (s.enableTwitterSharing.isSet()) { + writer.writeFieldBegin( + QStringLiteral("enableTwitterSharing"), + ThriftFieldType::T_BOOL, + 11); + + writer.writeBool(s.enableTwitterSharing.ref()); + writer.writeFieldEnd(); + } + + if (s.enableLinkedInSharing.isSet()) { + writer.writeFieldBegin( + QStringLiteral("enableLinkedInSharing"), + ThriftFieldType::T_BOOL, + 12); + + writer.writeBool(s.enableLinkedInSharing.ref()); + writer.writeFieldEnd(); + } + + if (s.enablePublicNotebooks.isSet()) { + writer.writeFieldBegin( + QStringLiteral("enablePublicNotebooks"), + ThriftFieldType::T_BOOL, + 13); + + writer.writeBool(s.enablePublicNotebooks.ref()); + writer.writeFieldEnd(); + } + + if (s.enableGoogle.isSet()) { + writer.writeFieldBegin( + QStringLiteral("enableGoogle"), + ThriftFieldType::T_BOOL, + 16); + + writer.writeBool(s.enableGoogle.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readBootstrapSettings( + ThriftBinaryBufferReader & reader, + BootstrapSettings & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool serviceHost_isset = false; + bool marketingUrl_isset = false; + bool supportUrl_isset = false; + bool accountEmailDomain_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + serviceHost_isset = true; + QString v; + reader.readString(v); + s.serviceHost = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + marketingUrl_isset = true; + QString v; + reader.readString(v); + s.marketingUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_STRING) { + supportUrl_isset = true; + QString v; + reader.readString(v); + s.supportUrl = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 4) { + if (fieldType == ThriftFieldType::T_STRING) { + accountEmailDomain_isset = true; + QString v; + reader.readString(v); + s.accountEmailDomain = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 5) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.enableFacebookSharing = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 6) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.enableGiftSubscriptions = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 7) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.enableSupportTickets = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 8) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.enableSharedNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 9) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.enableSingleNoteSharing = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 10) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.enableSponsoredAccounts = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 11) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.enableTwitterSharing = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 12) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.enableLinkedInSharing = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 13) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.enablePublicNotebooks = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 16) { + if (fieldType == ThriftFieldType::T_BOOL) { + bool v; + reader.readBool(v); + s.enableGoogle = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!serviceHost_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapSettings.serviceHost has no value")); + if (!marketingUrl_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapSettings.marketingUrl has no value")); + if (!supportUrl_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapSettings.supportUrl has no value")); + if (!accountEmailDomain_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapSettings.accountEmailDomain has no value")); +} + +void BootstrapSettings::print(QTextStream & strm) const +{ + strm << "BootstrapSettings: {\n"; + localData.print(strm); + strm << " serviceHost = " + << serviceHost << "\n"; + strm << " marketingUrl = " + << marketingUrl << "\n"; + strm << " supportUrl = " + << supportUrl << "\n"; + strm << " accountEmailDomain = " + << accountEmailDomain << "\n"; + + if (enableFacebookSharing.isSet()) { + strm << " enableFacebookSharing = " + << enableFacebookSharing.ref() << "\n"; + } + else { + strm << " enableFacebookSharing is not set\n"; + } + + if (enableGiftSubscriptions.isSet()) { + strm << " enableGiftSubscriptions = " + << enableGiftSubscriptions.ref() << "\n"; + } + else { + strm << " enableGiftSubscriptions is not set\n"; + } + + if (enableSupportTickets.isSet()) { + strm << " enableSupportTickets = " + << enableSupportTickets.ref() << "\n"; + } + else { + strm << " enableSupportTickets is not set\n"; + } + + if (enableSharedNotebooks.isSet()) { + strm << " enableSharedNotebooks = " + << enableSharedNotebooks.ref() << "\n"; + } + else { + strm << " enableSharedNotebooks is not set\n"; + } + + if (enableSingleNoteSharing.isSet()) { + strm << " enableSingleNoteSharing = " + << enableSingleNoteSharing.ref() << "\n"; + } + else { + strm << " enableSingleNoteSharing is not set\n"; + } + + if (enableSponsoredAccounts.isSet()) { + strm << " enableSponsoredAccounts = " + << enableSponsoredAccounts.ref() << "\n"; + } + else { + strm << " enableSponsoredAccounts is not set\n"; + } + + if (enableTwitterSharing.isSet()) { + strm << " enableTwitterSharing = " + << enableTwitterSharing.ref() << "\n"; + } + else { + strm << " enableTwitterSharing is not set\n"; + } + + if (enableLinkedInSharing.isSet()) { + strm << " enableLinkedInSharing = " + << enableLinkedInSharing.ref() << "\n"; + } + else { + strm << " enableLinkedInSharing is not set\n"; + } + + if (enablePublicNotebooks.isSet()) { + strm << " enablePublicNotebooks = " + << enablePublicNotebooks.ref() << "\n"; + } + else { + strm << " enablePublicNotebooks is not set\n"; + } + + if (enableGoogle.isSet()) { + strm << " enableGoogle = " + << enableGoogle.ref() << "\n"; + } + else { + strm << " enableGoogle is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeBootstrapProfile( + ThriftBinaryBufferWriter & writer, + const BootstrapProfile & s) +{ + writer.writeStructBegin(QStringLiteral("BootstrapProfile")); + writer.writeFieldBegin( + QStringLiteral("name"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.name); + writer.writeFieldEnd(); + + writer.writeFieldBegin( + QStringLiteral("settings"), + ThriftFieldType::T_STRUCT, + 2); + + writeBootstrapSettings(writer, s.settings); + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readBootstrapProfile( + ThriftBinaryBufferReader & reader, + BootstrapProfile & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool name_isset = false; + bool settings_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + name_isset = true; + QString v; + reader.readString(v); + s.name = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRUCT) { + settings_isset = true; + BootstrapSettings v; + readBootstrapSettings(reader, v); + s.settings = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!name_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapProfile.name has no value")); + if (!settings_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapProfile.settings has no value")); +} + +void BootstrapProfile::print(QTextStream & strm) const +{ + strm << "BootstrapProfile: {\n"; + localData.print(strm); + strm << " name = " + << name << "\n"; + strm << " settings = " + << settings << "\n"; + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +void writeBootstrapInfo( + ThriftBinaryBufferWriter & writer, + const BootstrapInfo & s) +{ + writer.writeStructBegin(QStringLiteral("BootstrapInfo")); + writer.writeFieldBegin( + QStringLiteral("profiles"), + ThriftFieldType::T_LIST, + 1); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.profiles.length()); + for(const auto & value: qAsConst(s.profiles)) { + writeBootstrapProfile(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readBootstrapInfo( + ThriftBinaryBufferReader & reader, + BootstrapInfo & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool profiles_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_LIST) { + profiles_isset = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (BootstrapInfo.profiles)")); + } + for(qint32 i = 0; i < size; i++) { + BootstrapProfile elem; + readBootstrapProfile(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.profiles = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!profiles_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapInfo.profiles has no value")); +} + +void BootstrapInfo::print(QTextStream & strm) const +{ + strm << "BootstrapInfo: {\n"; + localData.print(strm); + strm << " profiles = " + << "QList {"; + for(const auto & v: profiles) { + strm << " " << v << "\n"; + } + strm << "}\n"; + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +EDAMUserException::EDAMUserException() {} +EDAMUserException::~EDAMUserException() noexcept {} +EDAMUserException::EDAMUserException(const EDAMUserException& other) : EvernoteException(other) +{ + errorCode = other.errorCode; + parameter = other.parameter; +} +void writeEDAMUserException( + ThriftBinaryBufferWriter & writer, + const EDAMUserException & s) +{ + writer.writeStructBegin(QStringLiteral("EDAMUserException")); + writer.writeFieldBegin( + QStringLiteral("errorCode"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(static_cast(s.errorCode)); + writer.writeFieldEnd(); + + if (s.parameter.isSet()) { + writer.writeFieldBegin( + QStringLiteral("parameter"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.parameter.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readEDAMUserException( + ThriftBinaryBufferReader & reader, + EDAMUserException & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool errorCode_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + errorCode_isset = true; + EDAMErrorCode v; + readEnumEDAMErrorCode(reader, v); + s.errorCode = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.parameter = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!errorCode_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("EDAMUserException.errorCode has no value")); +} + +void EDAMUserException::print(QTextStream & strm) const +{ + strm << "EDAMUserException: {\n"; + strm << " errorCode = " + << errorCode << "\n"; + + if (parameter.isSet()) { + strm << " parameter = " + << parameter.ref() << "\n"; + } + else { + strm << " parameter is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +EDAMSystemException::EDAMSystemException() {} +EDAMSystemException::~EDAMSystemException() noexcept {} +EDAMSystemException::EDAMSystemException(const EDAMSystemException& other) : EvernoteException(other) +{ + errorCode = other.errorCode; + message = other.message; + rateLimitDuration = other.rateLimitDuration; +} +void writeEDAMSystemException( + ThriftBinaryBufferWriter & writer, + const EDAMSystemException & s) +{ + writer.writeStructBegin(QStringLiteral("EDAMSystemException")); + writer.writeFieldBegin( + QStringLiteral("errorCode"), + ThriftFieldType::T_I32, + 1); + + writer.writeI32(static_cast(s.errorCode)); + writer.writeFieldEnd(); + + if (s.message.isSet()) { + writer.writeFieldBegin( + QStringLiteral("message"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.message.ref()); + writer.writeFieldEnd(); + } + + if (s.rateLimitDuration.isSet()) { + writer.writeFieldBegin( + QStringLiteral("rateLimitDuration"), + ThriftFieldType::T_I32, + 3); + + writer.writeI32(s.rateLimitDuration.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readEDAMSystemException( + ThriftBinaryBufferReader & reader, + EDAMSystemException & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool errorCode_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_I32) { + errorCode_isset = true; + EDAMErrorCode v; + readEnumEDAMErrorCode(reader, v); + s.errorCode = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.message = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_I32) { + qint32 v; + reader.readI32(v); + s.rateLimitDuration = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!errorCode_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("EDAMSystemException.errorCode has no value")); +} + +void EDAMSystemException::print(QTextStream & strm) const +{ + strm << "EDAMSystemException: {\n"; + strm << " errorCode = " + << errorCode << "\n"; + + if (message.isSet()) { + strm << " message = " + << message.ref() << "\n"; + } + else { + strm << " message is not set\n"; + } + + if (rateLimitDuration.isSet()) { + strm << " rateLimitDuration = " + << rateLimitDuration.ref() << "\n"; + } + else { + strm << " rateLimitDuration is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +EDAMNotFoundException::EDAMNotFoundException() {} +EDAMNotFoundException::~EDAMNotFoundException() noexcept {} +EDAMNotFoundException::EDAMNotFoundException(const EDAMNotFoundException& other) : EvernoteException(other) +{ + identifier = other.identifier; + key = other.key; +} +void writeEDAMNotFoundException( + ThriftBinaryBufferWriter & writer, + const EDAMNotFoundException & s) +{ + writer.writeStructBegin(QStringLiteral("EDAMNotFoundException")); + if (s.identifier.isSet()) { + writer.writeFieldBegin( + QStringLiteral("identifier"), + ThriftFieldType::T_STRING, + 1); + + writer.writeString(s.identifier.ref()); + writer.writeFieldEnd(); + } + + if (s.key.isSet()) { + writer.writeFieldBegin( + QStringLiteral("key"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.key.ref()); + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readEDAMNotFoundException( + ThriftBinaryBufferReader & reader, + EDAMNotFoundException & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.identifier = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.key = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); +} + +void EDAMNotFoundException::print(QTextStream & strm) const +{ + strm << "EDAMNotFoundException: {\n"; + + if (identifier.isSet()) { + strm << " identifier = " + << identifier.ref() << "\n"; + } + else { + strm << " identifier is not set\n"; + } + + if (key.isSet()) { + strm << " key = " + << key.ref() << "\n"; + } + else { + strm << " key is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +EDAMInvalidContactsException::EDAMInvalidContactsException() {} +EDAMInvalidContactsException::~EDAMInvalidContactsException() noexcept {} +EDAMInvalidContactsException::EDAMInvalidContactsException(const EDAMInvalidContactsException& other) : EvernoteException(other) +{ + contacts = other.contacts; + parameter = other.parameter; + reasons = other.reasons; +} +void writeEDAMInvalidContactsException( + ThriftBinaryBufferWriter & writer, + const EDAMInvalidContactsException & s) +{ + writer.writeStructBegin(QStringLiteral("EDAMInvalidContactsException")); + writer.writeFieldBegin( + QStringLiteral("contacts"), + ThriftFieldType::T_LIST, + 1); + + writer.writeListBegin(ThriftFieldType::T_STRUCT, s.contacts.length()); + for(const auto & value: qAsConst(s.contacts)) { + writeContact(writer, value); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + + if (s.parameter.isSet()) { + writer.writeFieldBegin( + QStringLiteral("parameter"), + ThriftFieldType::T_STRING, + 2); + + writer.writeString(s.parameter.ref()); + writer.writeFieldEnd(); + } + + if (s.reasons.isSet()) { + writer.writeFieldBegin( + QStringLiteral("reasons"), + ThriftFieldType::T_LIST, + 3); + + writer.writeListBegin(ThriftFieldType::T_I32, s.reasons.ref().length()); + for(const auto & value: qAsConst(s.reasons.ref())) { + writer.writeI32(static_cast(value)); + } + writer.writeListEnd(); + + writer.writeFieldEnd(); + } + + writer.writeFieldStop(); + writer.writeStructEnd(); +} + +void readEDAMInvalidContactsException( + ThriftBinaryBufferReader & reader, + EDAMInvalidContactsException & s) +{ + QString fname; + ThriftFieldType fieldType; + qint16 fieldId; + bool contacts_isset = false; + reader.readStructBegin(fname); + while(true) + { + reader.readFieldBegin(fname, fieldType, fieldId); + if (fieldType == ThriftFieldType::T_STOP) break; + if (fieldId == 1) { + if (fieldType == ThriftFieldType::T_LIST) { + contacts_isset = true; + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_STRUCT) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (EDAMInvalidContactsException.contacts)")); + } + for(qint32 i = 0; i < size; i++) { + Contact elem; + readContact(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.contacts = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 2) { + if (fieldType == ThriftFieldType::T_STRING) { + QString v; + reader.readString(v); + s.parameter = v; + } + else { + reader.skip(fieldType); + } + } + else + if (fieldId == 3) { + if (fieldType == ThriftFieldType::T_LIST) { + QList v; + qint32 size; + ThriftFieldType elemType; + reader.readListBegin(elemType, size); + v.reserve(size); + if (elemType != ThriftFieldType::T_I32) { + throw ThriftException( + ThriftException::Type::INVALID_DATA, + QStringLiteral("Incorrect list type (EDAMInvalidContactsException.reasons)")); + } + for(qint32 i = 0; i < size; i++) { + EDAMInvalidContactReason elem; + readEnumEDAMInvalidContactReason(reader, elem); + v.append(elem); + } + reader.readListEnd(); + s.reasons = v; + } + else { + reader.skip(fieldType); + } + } + else + { + reader.skip(fieldType); + } + reader.readFieldEnd(); + } + reader.readStructEnd(); + if (!contacts_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("EDAMInvalidContactsException.contacts has no value")); +} + +void EDAMInvalidContactsException::print(QTextStream & strm) const +{ + strm << "EDAMInvalidContactsException: {\n"; + strm << " contacts = " + << "QList {"; + for(const auto & v: contacts) { + strm << " " << v << "\n"; + } + strm << "}\n"; + + if (parameter.isSet()) { + strm << " parameter = " + << parameter.ref() << "\n"; + } + else { + strm << " parameter is not set\n"; + } + + if (reasons.isSet()) { + strm << " reasons = " + << "QList {"; + for(const auto & v: reasons.ref()) { + strm << " " << v << "\n"; + } + strm << " }\n"; + } + else { + strm << " reasons is not set\n"; + } + + strm << "}\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +/** @endcond */ + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/generated/Types_io.h b/src/qevercloud/QEverCloud/src/generated/Types_io.h new file mode 100644 index 00000000..4d6ace74 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/generated/Types_io.h @@ -0,0 +1,207 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + * + * This file was generated from Evernote Thrift API + */ + +#ifndef QEVERCLOUD_GENERATED_TYPES_IO_H +#define QEVERCLOUD_GENERATED_TYPES_IO_H + +#include "../Impl.h" +#include +#include + +namespace qevercloud { + +/** @cond HIDDEN_SYMBOLS */ + +void writeSyncState(ThriftBinaryBufferWriter & writer, const SyncState & s); +void readSyncState(ThriftBinaryBufferReader & reader, SyncState & s); +void writeSyncChunk(ThriftBinaryBufferWriter & writer, const SyncChunk & s); +void readSyncChunk(ThriftBinaryBufferReader & reader, SyncChunk & s); +void writeSyncChunkFilter(ThriftBinaryBufferWriter & writer, const SyncChunkFilter & s); +void readSyncChunkFilter(ThriftBinaryBufferReader & reader, SyncChunkFilter & s); +void writeNoteFilter(ThriftBinaryBufferWriter & writer, const NoteFilter & s); +void readNoteFilter(ThriftBinaryBufferReader & reader, NoteFilter & s); +void writeNoteList(ThriftBinaryBufferWriter & writer, const NoteList & s); +void readNoteList(ThriftBinaryBufferReader & reader, NoteList & s); +void writeNoteMetadata(ThriftBinaryBufferWriter & writer, const NoteMetadata & s); +void readNoteMetadata(ThriftBinaryBufferReader & reader, NoteMetadata & s); +void writeNotesMetadataList(ThriftBinaryBufferWriter & writer, const NotesMetadataList & s); +void readNotesMetadataList(ThriftBinaryBufferReader & reader, NotesMetadataList & s); +void writeNotesMetadataResultSpec(ThriftBinaryBufferWriter & writer, const NotesMetadataResultSpec & s); +void readNotesMetadataResultSpec(ThriftBinaryBufferReader & reader, NotesMetadataResultSpec & s); +void writeNoteCollectionCounts(ThriftBinaryBufferWriter & writer, const NoteCollectionCounts & s); +void readNoteCollectionCounts(ThriftBinaryBufferReader & reader, NoteCollectionCounts & s); +void writeNoteResultSpec(ThriftBinaryBufferWriter & writer, const NoteResultSpec & s); +void readNoteResultSpec(ThriftBinaryBufferReader & reader, NoteResultSpec & s); +void writeNoteEmailParameters(ThriftBinaryBufferWriter & writer, const NoteEmailParameters & s); +void readNoteEmailParameters(ThriftBinaryBufferReader & reader, NoteEmailParameters & s); +void writeNoteVersionId(ThriftBinaryBufferWriter & writer, const NoteVersionId & s); +void readNoteVersionId(ThriftBinaryBufferReader & reader, NoteVersionId & s); +void writeRelatedQuery(ThriftBinaryBufferWriter & writer, const RelatedQuery & s); +void readRelatedQuery(ThriftBinaryBufferReader & reader, RelatedQuery & s); +void writeRelatedResult(ThriftBinaryBufferWriter & writer, const RelatedResult & s); +void readRelatedResult(ThriftBinaryBufferReader & reader, RelatedResult & s); +void writeRelatedResultSpec(ThriftBinaryBufferWriter & writer, const RelatedResultSpec & s); +void readRelatedResultSpec(ThriftBinaryBufferReader & reader, RelatedResultSpec & s); +void writeUpdateNoteIfUsnMatchesResult(ThriftBinaryBufferWriter & writer, const UpdateNoteIfUsnMatchesResult & s); +void readUpdateNoteIfUsnMatchesResult(ThriftBinaryBufferReader & reader, UpdateNoteIfUsnMatchesResult & s); +void writeShareRelationshipRestrictions(ThriftBinaryBufferWriter & writer, const ShareRelationshipRestrictions & s); +void readShareRelationshipRestrictions(ThriftBinaryBufferReader & reader, ShareRelationshipRestrictions & s); +void writeInvitationShareRelationship(ThriftBinaryBufferWriter & writer, const InvitationShareRelationship & s); +void readInvitationShareRelationship(ThriftBinaryBufferReader & reader, InvitationShareRelationship & s); +void writeMemberShareRelationship(ThriftBinaryBufferWriter & writer, const MemberShareRelationship & s); +void readMemberShareRelationship(ThriftBinaryBufferReader & reader, MemberShareRelationship & s); +void writeShareRelationships(ThriftBinaryBufferWriter & writer, const ShareRelationships & s); +void readShareRelationships(ThriftBinaryBufferReader & reader, ShareRelationships & s); +void writeManageNotebookSharesParameters(ThriftBinaryBufferWriter & writer, const ManageNotebookSharesParameters & s); +void readManageNotebookSharesParameters(ThriftBinaryBufferReader & reader, ManageNotebookSharesParameters & s); +void writeManageNotebookSharesError(ThriftBinaryBufferWriter & writer, const ManageNotebookSharesError & s); +void readManageNotebookSharesError(ThriftBinaryBufferReader & reader, ManageNotebookSharesError & s); +void writeManageNotebookSharesResult(ThriftBinaryBufferWriter & writer, const ManageNotebookSharesResult & s); +void readManageNotebookSharesResult(ThriftBinaryBufferReader & reader, ManageNotebookSharesResult & s); +void writeSharedNoteTemplate(ThriftBinaryBufferWriter & writer, const SharedNoteTemplate & s); +void readSharedNoteTemplate(ThriftBinaryBufferReader & reader, SharedNoteTemplate & s); +void writeNotebookShareTemplate(ThriftBinaryBufferWriter & writer, const NotebookShareTemplate & s); +void readNotebookShareTemplate(ThriftBinaryBufferReader & reader, NotebookShareTemplate & s); +void writeCreateOrUpdateNotebookSharesResult(ThriftBinaryBufferWriter & writer, const CreateOrUpdateNotebookSharesResult & s); +void readCreateOrUpdateNotebookSharesResult(ThriftBinaryBufferReader & reader, CreateOrUpdateNotebookSharesResult & s); +void writeNoteShareRelationshipRestrictions(ThriftBinaryBufferWriter & writer, const NoteShareRelationshipRestrictions & s); +void readNoteShareRelationshipRestrictions(ThriftBinaryBufferReader & reader, NoteShareRelationshipRestrictions & s); +void writeNoteMemberShareRelationship(ThriftBinaryBufferWriter & writer, const NoteMemberShareRelationship & s); +void readNoteMemberShareRelationship(ThriftBinaryBufferReader & reader, NoteMemberShareRelationship & s); +void writeNoteInvitationShareRelationship(ThriftBinaryBufferWriter & writer, const NoteInvitationShareRelationship & s); +void readNoteInvitationShareRelationship(ThriftBinaryBufferReader & reader, NoteInvitationShareRelationship & s); +void writeNoteShareRelationships(ThriftBinaryBufferWriter & writer, const NoteShareRelationships & s); +void readNoteShareRelationships(ThriftBinaryBufferReader & reader, NoteShareRelationships & s); +void writeManageNoteSharesParameters(ThriftBinaryBufferWriter & writer, const ManageNoteSharesParameters & s); +void readManageNoteSharesParameters(ThriftBinaryBufferReader & reader, ManageNoteSharesParameters & s); +void writeManageNoteSharesError(ThriftBinaryBufferWriter & writer, const ManageNoteSharesError & s); +void readManageNoteSharesError(ThriftBinaryBufferReader & reader, ManageNoteSharesError & s); +void writeManageNoteSharesResult(ThriftBinaryBufferWriter & writer, const ManageNoteSharesResult & s); +void readManageNoteSharesResult(ThriftBinaryBufferReader & reader, ManageNoteSharesResult & s); +void writeData(ThriftBinaryBufferWriter & writer, const Data & s); +void readData(ThriftBinaryBufferReader & reader, Data & s); +void writeUserAttributes(ThriftBinaryBufferWriter & writer, const UserAttributes & s); +void readUserAttributes(ThriftBinaryBufferReader & reader, UserAttributes & s); +void writeBusinessUserAttributes(ThriftBinaryBufferWriter & writer, const BusinessUserAttributes & s); +void readBusinessUserAttributes(ThriftBinaryBufferReader & reader, BusinessUserAttributes & s); +void writeAccounting(ThriftBinaryBufferWriter & writer, const Accounting & s); +void readAccounting(ThriftBinaryBufferReader & reader, Accounting & s); +void writeBusinessUserInfo(ThriftBinaryBufferWriter & writer, const BusinessUserInfo & s); +void readBusinessUserInfo(ThriftBinaryBufferReader & reader, BusinessUserInfo & s); +void writeAccountLimits(ThriftBinaryBufferWriter & writer, const AccountLimits & s); +void readAccountLimits(ThriftBinaryBufferReader & reader, AccountLimits & s); +void writeUser(ThriftBinaryBufferWriter & writer, const User & s); +void readUser(ThriftBinaryBufferReader & reader, User & s); +void writeContact(ThriftBinaryBufferWriter & writer, const Contact & s); +void readContact(ThriftBinaryBufferReader & reader, Contact & s); +void writeIdentity(ThriftBinaryBufferWriter & writer, const Identity & s); +void readIdentity(ThriftBinaryBufferReader & reader, Identity & s); +void writeTag(ThriftBinaryBufferWriter & writer, const Tag & s); +void readTag(ThriftBinaryBufferReader & reader, Tag & s); +void writeLazyMap(ThriftBinaryBufferWriter & writer, const LazyMap & s); +void readLazyMap(ThriftBinaryBufferReader & reader, LazyMap & s); +void writeResourceAttributes(ThriftBinaryBufferWriter & writer, const ResourceAttributes & s); +void readResourceAttributes(ThriftBinaryBufferReader & reader, ResourceAttributes & s); +void writeResource(ThriftBinaryBufferWriter & writer, const Resource & s); +void readResource(ThriftBinaryBufferReader & reader, Resource & s); +void writeNoteAttributes(ThriftBinaryBufferWriter & writer, const NoteAttributes & s); +void readNoteAttributes(ThriftBinaryBufferReader & reader, NoteAttributes & s); +void writeSharedNote(ThriftBinaryBufferWriter & writer, const SharedNote & s); +void readSharedNote(ThriftBinaryBufferReader & reader, SharedNote & s); +void writeNoteRestrictions(ThriftBinaryBufferWriter & writer, const NoteRestrictions & s); +void readNoteRestrictions(ThriftBinaryBufferReader & reader, NoteRestrictions & s); +void writeNoteLimits(ThriftBinaryBufferWriter & writer, const NoteLimits & s); +void readNoteLimits(ThriftBinaryBufferReader & reader, NoteLimits & s); +void writeNote(ThriftBinaryBufferWriter & writer, const Note & s); +void readNote(ThriftBinaryBufferReader & reader, Note & s); +void writePublishing(ThriftBinaryBufferWriter & writer, const Publishing & s); +void readPublishing(ThriftBinaryBufferReader & reader, Publishing & s); +void writeBusinessNotebook(ThriftBinaryBufferWriter & writer, const BusinessNotebook & s); +void readBusinessNotebook(ThriftBinaryBufferReader & reader, BusinessNotebook & s); +void writeSavedSearchScope(ThriftBinaryBufferWriter & writer, const SavedSearchScope & s); +void readSavedSearchScope(ThriftBinaryBufferReader & reader, SavedSearchScope & s); +void writeSavedSearch(ThriftBinaryBufferWriter & writer, const SavedSearch & s); +void readSavedSearch(ThriftBinaryBufferReader & reader, SavedSearch & s); +void writeSharedNotebookRecipientSettings(ThriftBinaryBufferWriter & writer, const SharedNotebookRecipientSettings & s); +void readSharedNotebookRecipientSettings(ThriftBinaryBufferReader & reader, SharedNotebookRecipientSettings & s); +void writeNotebookRecipientSettings(ThriftBinaryBufferWriter & writer, const NotebookRecipientSettings & s); +void readNotebookRecipientSettings(ThriftBinaryBufferReader & reader, NotebookRecipientSettings & s); +void writeSharedNotebook(ThriftBinaryBufferWriter & writer, const SharedNotebook & s); +void readSharedNotebook(ThriftBinaryBufferReader & reader, SharedNotebook & s); +void writeCanMoveToContainerRestrictions(ThriftBinaryBufferWriter & writer, const CanMoveToContainerRestrictions & s); +void readCanMoveToContainerRestrictions(ThriftBinaryBufferReader & reader, CanMoveToContainerRestrictions & s); +void writeNotebookRestrictions(ThriftBinaryBufferWriter & writer, const NotebookRestrictions & s); +void readNotebookRestrictions(ThriftBinaryBufferReader & reader, NotebookRestrictions & s); +void writeNotebook(ThriftBinaryBufferWriter & writer, const Notebook & s); +void readNotebook(ThriftBinaryBufferReader & reader, Notebook & s); +void writeLinkedNotebook(ThriftBinaryBufferWriter & writer, const LinkedNotebook & s); +void readLinkedNotebook(ThriftBinaryBufferReader & reader, LinkedNotebook & s); +void writeNotebookDescriptor(ThriftBinaryBufferWriter & writer, const NotebookDescriptor & s); +void readNotebookDescriptor(ThriftBinaryBufferReader & reader, NotebookDescriptor & s); +void writeUserProfile(ThriftBinaryBufferWriter & writer, const UserProfile & s); +void readUserProfile(ThriftBinaryBufferReader & reader, UserProfile & s); +void writeRelatedContentImage(ThriftBinaryBufferWriter & writer, const RelatedContentImage & s); +void readRelatedContentImage(ThriftBinaryBufferReader & reader, RelatedContentImage & s); +void writeRelatedContent(ThriftBinaryBufferWriter & writer, const RelatedContent & s); +void readRelatedContent(ThriftBinaryBufferReader & reader, RelatedContent & s); +void writeBusinessInvitation(ThriftBinaryBufferWriter & writer, const BusinessInvitation & s); +void readBusinessInvitation(ThriftBinaryBufferReader & reader, BusinessInvitation & s); +void writeUserIdentity(ThriftBinaryBufferWriter & writer, const UserIdentity & s); +void readUserIdentity(ThriftBinaryBufferReader & reader, UserIdentity & s); +void writePublicUserInfo(ThriftBinaryBufferWriter & writer, const PublicUserInfo & s); +void readPublicUserInfo(ThriftBinaryBufferReader & reader, PublicUserInfo & s); +void writeUserUrls(ThriftBinaryBufferWriter & writer, const UserUrls & s); +void readUserUrls(ThriftBinaryBufferReader & reader, UserUrls & s); +void writeAuthenticationResult(ThriftBinaryBufferWriter & writer, const AuthenticationResult & s); +void readAuthenticationResult(ThriftBinaryBufferReader & reader, AuthenticationResult & s); +void writeBootstrapSettings(ThriftBinaryBufferWriter & writer, const BootstrapSettings & s); +void readBootstrapSettings(ThriftBinaryBufferReader & reader, BootstrapSettings & s); +void writeBootstrapProfile(ThriftBinaryBufferWriter & writer, const BootstrapProfile & s); +void readBootstrapProfile(ThriftBinaryBufferReader & reader, BootstrapProfile & s); +void writeBootstrapInfo(ThriftBinaryBufferWriter & writer, const BootstrapInfo & s); +void readBootstrapInfo(ThriftBinaryBufferReader & reader, BootstrapInfo & s); +void writeEDAMUserException(ThriftBinaryBufferWriter & writer, const EDAMUserException & s); +void readEDAMUserException(ThriftBinaryBufferReader & reader, EDAMUserException & s); +void writeEDAMSystemException(ThriftBinaryBufferWriter & writer, const EDAMSystemException & s); +void readEDAMSystemException(ThriftBinaryBufferReader & reader, EDAMSystemException & s); +void writeEDAMNotFoundException(ThriftBinaryBufferWriter & writer, const EDAMNotFoundException & s); +void readEDAMNotFoundException(ThriftBinaryBufferReader & reader, EDAMNotFoundException & s); +void writeEDAMInvalidContactsException(ThriftBinaryBufferWriter & writer, const EDAMInvalidContactsException & s); +void readEDAMInvalidContactsException(ThriftBinaryBufferReader & reader, EDAMInvalidContactsException & s); + +void readEnumEDAMErrorCode(ThriftBinaryBufferReader & reader, EDAMErrorCode & e); +void readEnumEDAMInvalidContactReason(ThriftBinaryBufferReader & reader, EDAMInvalidContactReason & e); +void readEnumShareRelationshipPrivilegeLevel(ThriftBinaryBufferReader & reader, ShareRelationshipPrivilegeLevel & e); +void readEnumPrivilegeLevel(ThriftBinaryBufferReader & reader, PrivilegeLevel & e); +void readEnumServiceLevel(ThriftBinaryBufferReader & reader, ServiceLevel & e); +void readEnumQueryFormat(ThriftBinaryBufferReader & reader, QueryFormat & e); +void readEnumNoteSortOrder(ThriftBinaryBufferReader & reader, NoteSortOrder & e); +void readEnumPremiumOrderStatus(ThriftBinaryBufferReader & reader, PremiumOrderStatus & e); +void readEnumSharedNotebookPrivilegeLevel(ThriftBinaryBufferReader & reader, SharedNotebookPrivilegeLevel & e); +void readEnumSharedNotePrivilegeLevel(ThriftBinaryBufferReader & reader, SharedNotePrivilegeLevel & e); +void readEnumSponsoredGroupRole(ThriftBinaryBufferReader & reader, SponsoredGroupRole & e); +void readEnumBusinessUserRole(ThriftBinaryBufferReader & reader, BusinessUserRole & e); +void readEnumBusinessUserStatus(ThriftBinaryBufferReader & reader, BusinessUserStatus & e); +void readEnumSharedNotebookInstanceRestrictions(ThriftBinaryBufferReader & reader, SharedNotebookInstanceRestrictions & e); +void readEnumReminderEmailConfig(ThriftBinaryBufferReader & reader, ReminderEmailConfig & e); +void readEnumBusinessInvitationStatus(ThriftBinaryBufferReader & reader, BusinessInvitationStatus & e); +void readEnumContactType(ThriftBinaryBufferReader & reader, ContactType & e); +void readEnumEntityType(ThriftBinaryBufferReader & reader, EntityType & e); +void readEnumRecipientStatus(ThriftBinaryBufferReader & reader, RecipientStatus & e); +void readEnumCanMoveToContainerStatus(ThriftBinaryBufferReader & reader, CanMoveToContainerStatus & e); +void readEnumRelatedContentType(ThriftBinaryBufferReader & reader, RelatedContentType & e); +void readEnumRelatedContentAccess(ThriftBinaryBufferReader & reader, RelatedContentAccess & e); +void readEnumUserIdentityType(ThriftBinaryBufferReader & reader, UserIdentityType & e); + +/** @endcond */ +} // namespace qevercloud + +#endif // QEVERCLOUD_GENERATED_TYPES_IO_H diff --git a/src/qevercloud/QEverCloud/src/generated/services.cpp b/src/qevercloud/QEverCloud/src/generated/services.cpp deleted file mode 100644 index dca33693..00000000 --- a/src/qevercloud/QEverCloud/src/generated/services.cpp +++ /dev/null @@ -1,11055 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - * - * This file was generated from Evernote Thrift API - */ - - -#include -#include "../impl.h" -#include "../impl.h" -#include "types_impl.h" -#include - -namespace qevercloud { -QByteArray NoteStore_getSyncState_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getSyncState"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getSyncState_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -SyncState NoteStore_getSyncState_readReply(QByteArray reply) -{ - bool resultIsSet = false; - SyncState result = SyncState(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getSyncState")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - SyncState v; - readSyncState(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getSyncState: missing result")); - } - return result; -} - -QVariant NoteStore_getSyncState_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getSyncState_readReply(reply)); -} - -SyncState NoteStore::getSyncState(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getSyncState_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getSyncState_readReply(reply); -} - -AsyncResult* NoteStore::getSyncStateAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getSyncState_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, NoteStore_getSyncState_readReplyAsync); -} - -QByteArray NoteStore_getFilteredSyncChunk_prepareParams(QString authenticationToken, qint32 afterUSN, qint32 maxEntries, const SyncChunkFilter& filter) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getFilteredSyncChunk"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getFilteredSyncChunk_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("afterUSN"), ThriftFieldType::T_I32, 2); - w.writeI32(afterUSN); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("maxEntries"), ThriftFieldType::T_I32, 3); - w.writeI32(maxEntries); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("filter"), ThriftFieldType::T_STRUCT, 4); - writeSyncChunkFilter(w, filter); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -SyncChunk NoteStore_getFilteredSyncChunk_readReply(QByteArray reply) -{ - bool resultIsSet = false; - SyncChunk result = SyncChunk(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getFilteredSyncChunk")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - SyncChunk v; - readSyncChunk(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getFilteredSyncChunk: missing result")); - } - return result; -} - -QVariant NoteStore_getFilteredSyncChunk_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getFilteredSyncChunk_readReply(reply)); -} - -SyncChunk NoteStore::getFilteredSyncChunk(qint32 afterUSN, qint32 maxEntries, const SyncChunkFilter& filter, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getFilteredSyncChunk_prepareParams(authenticationToken, afterUSN, maxEntries, filter); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getFilteredSyncChunk_readReply(reply); -} - -AsyncResult* NoteStore::getFilteredSyncChunkAsync(qint32 afterUSN, qint32 maxEntries, const SyncChunkFilter& filter, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getFilteredSyncChunk_prepareParams(authenticationToken, afterUSN, maxEntries, filter); - return new AsyncResult(m_url, params, NoteStore_getFilteredSyncChunk_readReplyAsync); -} - -QByteArray NoteStore_getLinkedNotebookSyncState_prepareParams(QString authenticationToken, const LinkedNotebook& linkedNotebook) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getLinkedNotebookSyncState"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getLinkedNotebookSyncState_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("linkedNotebook"), ThriftFieldType::T_STRUCT, 2); - writeLinkedNotebook(w, linkedNotebook); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -SyncState NoteStore_getLinkedNotebookSyncState_readReply(QByteArray reply) -{ - bool resultIsSet = false; - SyncState result = SyncState(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getLinkedNotebookSyncState")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - SyncState v; - readSyncState(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getLinkedNotebookSyncState: missing result")); - } - return result; -} - -QVariant NoteStore_getLinkedNotebookSyncState_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getLinkedNotebookSyncState_readReply(reply)); -} - -SyncState NoteStore::getLinkedNotebookSyncState(const LinkedNotebook& linkedNotebook, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getLinkedNotebookSyncState_prepareParams(authenticationToken, linkedNotebook); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getLinkedNotebookSyncState_readReply(reply); -} - -AsyncResult* NoteStore::getLinkedNotebookSyncStateAsync(const LinkedNotebook& linkedNotebook, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getLinkedNotebookSyncState_prepareParams(authenticationToken, linkedNotebook); - return new AsyncResult(m_url, params, NoteStore_getLinkedNotebookSyncState_readReplyAsync); -} - -QByteArray NoteStore_getLinkedNotebookSyncChunk_prepareParams(QString authenticationToken, const LinkedNotebook& linkedNotebook, qint32 afterUSN, qint32 maxEntries, bool fullSyncOnly) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getLinkedNotebookSyncChunk"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getLinkedNotebookSyncChunk_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("linkedNotebook"), ThriftFieldType::T_STRUCT, 2); - writeLinkedNotebook(w, linkedNotebook); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("afterUSN"), ThriftFieldType::T_I32, 3); - w.writeI32(afterUSN); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("maxEntries"), ThriftFieldType::T_I32, 4); - w.writeI32(maxEntries); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("fullSyncOnly"), ThriftFieldType::T_BOOL, 5); - w.writeBool(fullSyncOnly); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -SyncChunk NoteStore_getLinkedNotebookSyncChunk_readReply(QByteArray reply) -{ - bool resultIsSet = false; - SyncChunk result = SyncChunk(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getLinkedNotebookSyncChunk")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - SyncChunk v; - readSyncChunk(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getLinkedNotebookSyncChunk: missing result")); - } - return result; -} - -QVariant NoteStore_getLinkedNotebookSyncChunk_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getLinkedNotebookSyncChunk_readReply(reply)); -} - -SyncChunk NoteStore::getLinkedNotebookSyncChunk(const LinkedNotebook& linkedNotebook, qint32 afterUSN, qint32 maxEntries, bool fullSyncOnly, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getLinkedNotebookSyncChunk_prepareParams(authenticationToken, linkedNotebook, afterUSN, maxEntries, fullSyncOnly); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getLinkedNotebookSyncChunk_readReply(reply); -} - -AsyncResult* NoteStore::getLinkedNotebookSyncChunkAsync(const LinkedNotebook& linkedNotebook, qint32 afterUSN, qint32 maxEntries, bool fullSyncOnly, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getLinkedNotebookSyncChunk_prepareParams(authenticationToken, linkedNotebook, afterUSN, maxEntries, fullSyncOnly); - return new AsyncResult(m_url, params, NoteStore_getLinkedNotebookSyncChunk_readReplyAsync); -} - -QByteArray NoteStore_listNotebooks_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("listNotebooks"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_listNotebooks_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QList< Notebook > NoteStore_listNotebooks_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QList< Notebook > result = QList< Notebook >(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("listNotebooks")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_LIST) { - resultIsSet = true; - QList< Notebook > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (listNotebooks.result)")); - for(qint32 i = 0; i < size; i++) { - Notebook elem; - readNotebook(r, elem); - v.append(elem); - } - r.readListEnd(); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("listNotebooks: missing result")); - } - return result; -} - -QVariant NoteStore_listNotebooks_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_listNotebooks_readReply(reply)); -} - -QList< Notebook > NoteStore::listNotebooks(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listNotebooks_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_listNotebooks_readReply(reply); -} - -AsyncResult* NoteStore::listNotebooksAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listNotebooks_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, NoteStore_listNotebooks_readReplyAsync); -} - -QByteArray NoteStore_listAccessibleBusinessNotebooks_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("listAccessibleBusinessNotebooks"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_listAccessibleBusinessNotebooks_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QList< Notebook > NoteStore_listAccessibleBusinessNotebooks_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QList< Notebook > result = QList< Notebook >(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("listAccessibleBusinessNotebooks")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_LIST) { - resultIsSet = true; - QList< Notebook > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (listAccessibleBusinessNotebooks.result)")); - for(qint32 i = 0; i < size; i++) { - Notebook elem; - readNotebook(r, elem); - v.append(elem); - } - r.readListEnd(); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("listAccessibleBusinessNotebooks: missing result")); - } - return result; -} - -QVariant NoteStore_listAccessibleBusinessNotebooks_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_listAccessibleBusinessNotebooks_readReply(reply)); -} - -QList< Notebook > NoteStore::listAccessibleBusinessNotebooks(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listAccessibleBusinessNotebooks_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_listAccessibleBusinessNotebooks_readReply(reply); -} - -AsyncResult* NoteStore::listAccessibleBusinessNotebooksAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listAccessibleBusinessNotebooks_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, NoteStore_listAccessibleBusinessNotebooks_readReplyAsync); -} - -QByteArray NoteStore_getNotebook_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Notebook NoteStore_getNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Notebook result = Notebook(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Notebook v; - readNotebook(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_getNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getNotebook_readReply(reply)); -} - -Notebook NoteStore::getNotebook(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNotebook_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getNotebook_readReply(reply); -} - -AsyncResult* NoteStore::getNotebookAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNotebook_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_getNotebook_readReplyAsync); -} - -QByteArray NoteStore_getDefaultNotebook_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getDefaultNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getDefaultNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Notebook NoteStore_getDefaultNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Notebook result = Notebook(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getDefaultNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Notebook v; - readNotebook(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getDefaultNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_getDefaultNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getDefaultNotebook_readReply(reply)); -} - -Notebook NoteStore::getDefaultNotebook(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getDefaultNotebook_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getDefaultNotebook_readReply(reply); -} - -AsyncResult* NoteStore::getDefaultNotebookAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getDefaultNotebook_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, NoteStore_getDefaultNotebook_readReplyAsync); -} - -QByteArray NoteStore_createNotebook_prepareParams(QString authenticationToken, const Notebook& notebook) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("createNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_createNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("notebook"), ThriftFieldType::T_STRUCT, 2); - writeNotebook(w, notebook); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Notebook NoteStore_createNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Notebook result = Notebook(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("createNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Notebook v; - readNotebook(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("createNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_createNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_createNotebook_readReply(reply)); -} - -Notebook NoteStore::createNotebook(const Notebook& notebook, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_createNotebook_prepareParams(authenticationToken, notebook); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_createNotebook_readReply(reply); -} - -AsyncResult* NoteStore::createNotebookAsync(const Notebook& notebook, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_createNotebook_prepareParams(authenticationToken, notebook); - return new AsyncResult(m_url, params, NoteStore_createNotebook_readReplyAsync); -} - -QByteArray NoteStore_updateNotebook_prepareParams(QString authenticationToken, const Notebook& notebook) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("updateNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_updateNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("notebook"), ThriftFieldType::T_STRUCT, 2); - writeNotebook(w, notebook); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_updateNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("updateNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("updateNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_updateNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_updateNotebook_readReply(reply)); -} - -qint32 NoteStore::updateNotebook(const Notebook& notebook, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateNotebook_prepareParams(authenticationToken, notebook); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_updateNotebook_readReply(reply); -} - -AsyncResult* NoteStore::updateNotebookAsync(const Notebook& notebook, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateNotebook_prepareParams(authenticationToken, notebook); - return new AsyncResult(m_url, params, NoteStore_updateNotebook_readReplyAsync); -} - -QByteArray NoteStore_expungeNotebook_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("expungeNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_expungeNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_expungeNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("expungeNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("expungeNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_expungeNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_expungeNotebook_readReply(reply)); -} - -qint32 NoteStore::expungeNotebook(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_expungeNotebook_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_expungeNotebook_readReply(reply); -} - -AsyncResult* NoteStore::expungeNotebookAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_expungeNotebook_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_expungeNotebook_readReplyAsync); -} - -QByteArray NoteStore_listTags_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("listTags"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_listTags_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QList< Tag > NoteStore_listTags_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QList< Tag > result = QList< Tag >(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("listTags")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_LIST) { - resultIsSet = true; - QList< Tag > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (listTags.result)")); - for(qint32 i = 0; i < size; i++) { - Tag elem; - readTag(r, elem); - v.append(elem); - } - r.readListEnd(); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("listTags: missing result")); - } - return result; -} - -QVariant NoteStore_listTags_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_listTags_readReply(reply)); -} - -QList< Tag > NoteStore::listTags(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listTags_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_listTags_readReply(reply); -} - -AsyncResult* NoteStore::listTagsAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listTags_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, NoteStore_listTags_readReplyAsync); -} - -QByteArray NoteStore_listTagsByNotebook_prepareParams(QString authenticationToken, Guid notebookGuid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("listTagsByNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_listTagsByNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("notebookGuid"), ThriftFieldType::T_STRING, 2); - w.writeString(notebookGuid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QList< Tag > NoteStore_listTagsByNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QList< Tag > result = QList< Tag >(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("listTagsByNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_LIST) { - resultIsSet = true; - QList< Tag > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (listTagsByNotebook.result)")); - for(qint32 i = 0; i < size; i++) { - Tag elem; - readTag(r, elem); - v.append(elem); - } - r.readListEnd(); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("listTagsByNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_listTagsByNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_listTagsByNotebook_readReply(reply)); -} - -QList< Tag > NoteStore::listTagsByNotebook(Guid notebookGuid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listTagsByNotebook_prepareParams(authenticationToken, notebookGuid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_listTagsByNotebook_readReply(reply); -} - -AsyncResult* NoteStore::listTagsByNotebookAsync(Guid notebookGuid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listTagsByNotebook_prepareParams(authenticationToken, notebookGuid); - return new AsyncResult(m_url, params, NoteStore_listTagsByNotebook_readReplyAsync); -} - -QByteArray NoteStore_getTag_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getTag"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getTag_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Tag NoteStore_getTag_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Tag result = Tag(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getTag")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Tag v; - readTag(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getTag: missing result")); - } - return result; -} - -QVariant NoteStore_getTag_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getTag_readReply(reply)); -} - -Tag NoteStore::getTag(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getTag_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getTag_readReply(reply); -} - -AsyncResult* NoteStore::getTagAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getTag_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_getTag_readReplyAsync); -} - -QByteArray NoteStore_createTag_prepareParams(QString authenticationToken, const Tag& tag) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("createTag"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_createTag_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("tag"), ThriftFieldType::T_STRUCT, 2); - writeTag(w, tag); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Tag NoteStore_createTag_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Tag result = Tag(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("createTag")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Tag v; - readTag(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("createTag: missing result")); - } - return result; -} - -QVariant NoteStore_createTag_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_createTag_readReply(reply)); -} - -Tag NoteStore::createTag(const Tag& tag, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_createTag_prepareParams(authenticationToken, tag); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_createTag_readReply(reply); -} - -AsyncResult* NoteStore::createTagAsync(const Tag& tag, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_createTag_prepareParams(authenticationToken, tag); - return new AsyncResult(m_url, params, NoteStore_createTag_readReplyAsync); -} - -QByteArray NoteStore_updateTag_prepareParams(QString authenticationToken, const Tag& tag) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("updateTag"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_updateTag_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("tag"), ThriftFieldType::T_STRUCT, 2); - writeTag(w, tag); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_updateTag_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("updateTag")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("updateTag: missing result")); - } - return result; -} - -QVariant NoteStore_updateTag_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_updateTag_readReply(reply)); -} - -qint32 NoteStore::updateTag(const Tag& tag, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateTag_prepareParams(authenticationToken, tag); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_updateTag_readReply(reply); -} - -AsyncResult* NoteStore::updateTagAsync(const Tag& tag, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateTag_prepareParams(authenticationToken, tag); - return new AsyncResult(m_url, params, NoteStore_updateTag_readReplyAsync); -} - -QByteArray NoteStore_untagAll_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("untagAll"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_untagAll_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -void NoteStore_untagAll_readReply(QByteArray reply) -{ - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("untagAll")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); -} - -QVariant NoteStore_untagAll_readReplyAsync(QByteArray reply) -{ - NoteStore_untagAll_readReply(reply); - return QVariant(); -} - -void NoteStore::untagAll(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_untagAll_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - NoteStore_untagAll_readReply(reply); -} - -AsyncResult* NoteStore::untagAllAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_untagAll_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_untagAll_readReplyAsync); -} - -QByteArray NoteStore_expungeTag_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("expungeTag"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_expungeTag_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_expungeTag_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("expungeTag")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("expungeTag: missing result")); - } - return result; -} - -QVariant NoteStore_expungeTag_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_expungeTag_readReply(reply)); -} - -qint32 NoteStore::expungeTag(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_expungeTag_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_expungeTag_readReply(reply); -} - -AsyncResult* NoteStore::expungeTagAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_expungeTag_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_expungeTag_readReplyAsync); -} - -QByteArray NoteStore_listSearches_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("listSearches"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_listSearches_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QList< SavedSearch > NoteStore_listSearches_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QList< SavedSearch > result = QList< SavedSearch >(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("listSearches")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_LIST) { - resultIsSet = true; - QList< SavedSearch > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (listSearches.result)")); - for(qint32 i = 0; i < size; i++) { - SavedSearch elem; - readSavedSearch(r, elem); - v.append(elem); - } - r.readListEnd(); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("listSearches: missing result")); - } - return result; -} - -QVariant NoteStore_listSearches_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_listSearches_readReply(reply)); -} - -QList< SavedSearch > NoteStore::listSearches(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listSearches_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_listSearches_readReply(reply); -} - -AsyncResult* NoteStore::listSearchesAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listSearches_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, NoteStore_listSearches_readReplyAsync); -} - -QByteArray NoteStore_getSearch_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getSearch"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getSearch_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -SavedSearch NoteStore_getSearch_readReply(QByteArray reply) -{ - bool resultIsSet = false; - SavedSearch result = SavedSearch(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getSearch")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - SavedSearch v; - readSavedSearch(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getSearch: missing result")); - } - return result; -} - -QVariant NoteStore_getSearch_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getSearch_readReply(reply)); -} - -SavedSearch NoteStore::getSearch(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getSearch_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getSearch_readReply(reply); -} - -AsyncResult* NoteStore::getSearchAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getSearch_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_getSearch_readReplyAsync); -} - -QByteArray NoteStore_createSearch_prepareParams(QString authenticationToken, const SavedSearch& search) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("createSearch"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_createSearch_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("search"), ThriftFieldType::T_STRUCT, 2); - writeSavedSearch(w, search); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -SavedSearch NoteStore_createSearch_readReply(QByteArray reply) -{ - bool resultIsSet = false; - SavedSearch result = SavedSearch(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("createSearch")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - SavedSearch v; - readSavedSearch(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("createSearch: missing result")); - } - return result; -} - -QVariant NoteStore_createSearch_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_createSearch_readReply(reply)); -} - -SavedSearch NoteStore::createSearch(const SavedSearch& search, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_createSearch_prepareParams(authenticationToken, search); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_createSearch_readReply(reply); -} - -AsyncResult* NoteStore::createSearchAsync(const SavedSearch& search, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_createSearch_prepareParams(authenticationToken, search); - return new AsyncResult(m_url, params, NoteStore_createSearch_readReplyAsync); -} - -QByteArray NoteStore_updateSearch_prepareParams(QString authenticationToken, const SavedSearch& search) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("updateSearch"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_updateSearch_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("search"), ThriftFieldType::T_STRUCT, 2); - writeSavedSearch(w, search); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_updateSearch_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("updateSearch")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("updateSearch: missing result")); - } - return result; -} - -QVariant NoteStore_updateSearch_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_updateSearch_readReply(reply)); -} - -qint32 NoteStore::updateSearch(const SavedSearch& search, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateSearch_prepareParams(authenticationToken, search); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_updateSearch_readReply(reply); -} - -AsyncResult* NoteStore::updateSearchAsync(const SavedSearch& search, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateSearch_prepareParams(authenticationToken, search); - return new AsyncResult(m_url, params, NoteStore_updateSearch_readReplyAsync); -} - -QByteArray NoteStore_expungeSearch_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("expungeSearch"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_expungeSearch_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_expungeSearch_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("expungeSearch")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("expungeSearch: missing result")); - } - return result; -} - -QVariant NoteStore_expungeSearch_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_expungeSearch_readReply(reply)); -} - -qint32 NoteStore::expungeSearch(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_expungeSearch_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_expungeSearch_readReply(reply); -} - -AsyncResult* NoteStore::expungeSearchAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_expungeSearch_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_expungeSearch_readReplyAsync); -} - -QByteArray NoteStore_findNoteOffset_prepareParams(QString authenticationToken, const NoteFilter& filter, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("findNoteOffset"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_findNoteOffset_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("filter"), ThriftFieldType::T_STRUCT, 2); - writeNoteFilter(w, filter); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 3); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_findNoteOffset_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("findNoteOffset")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("findNoteOffset: missing result")); - } - return result; -} - -QVariant NoteStore_findNoteOffset_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_findNoteOffset_readReply(reply)); -} - -qint32 NoteStore::findNoteOffset(const NoteFilter& filter, Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_findNoteOffset_prepareParams(authenticationToken, filter, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_findNoteOffset_readReply(reply); -} - -AsyncResult* NoteStore::findNoteOffsetAsync(const NoteFilter& filter, Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_findNoteOffset_prepareParams(authenticationToken, filter, guid); - return new AsyncResult(m_url, params, NoteStore_findNoteOffset_readReplyAsync); -} - -QByteArray NoteStore_findNotesMetadata_prepareParams(QString authenticationToken, const NoteFilter& filter, qint32 offset, qint32 maxNotes, const NotesMetadataResultSpec& resultSpec) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("findNotesMetadata"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_findNotesMetadata_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("filter"), ThriftFieldType::T_STRUCT, 2); - writeNoteFilter(w, filter); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("offset"), ThriftFieldType::T_I32, 3); - w.writeI32(offset); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("maxNotes"), ThriftFieldType::T_I32, 4); - w.writeI32(maxNotes); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("resultSpec"), ThriftFieldType::T_STRUCT, 5); - writeNotesMetadataResultSpec(w, resultSpec); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -NotesMetadataList NoteStore_findNotesMetadata_readReply(QByteArray reply) -{ - bool resultIsSet = false; - NotesMetadataList result = NotesMetadataList(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("findNotesMetadata")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - NotesMetadataList v; - readNotesMetadataList(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("findNotesMetadata: missing result")); - } - return result; -} - -QVariant NoteStore_findNotesMetadata_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_findNotesMetadata_readReply(reply)); -} - -NotesMetadataList NoteStore::findNotesMetadata(const NoteFilter& filter, qint32 offset, qint32 maxNotes, const NotesMetadataResultSpec& resultSpec, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_findNotesMetadata_prepareParams(authenticationToken, filter, offset, maxNotes, resultSpec); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_findNotesMetadata_readReply(reply); -} - -AsyncResult* NoteStore::findNotesMetadataAsync(const NoteFilter& filter, qint32 offset, qint32 maxNotes, const NotesMetadataResultSpec& resultSpec, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_findNotesMetadata_prepareParams(authenticationToken, filter, offset, maxNotes, resultSpec); - return new AsyncResult(m_url, params, NoteStore_findNotesMetadata_readReplyAsync); -} - -QByteArray NoteStore_findNoteCounts_prepareParams(QString authenticationToken, const NoteFilter& filter, bool withTrash) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("findNoteCounts"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_findNoteCounts_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("filter"), ThriftFieldType::T_STRUCT, 2); - writeNoteFilter(w, filter); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withTrash"), ThriftFieldType::T_BOOL, 3); - w.writeBool(withTrash); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -NoteCollectionCounts NoteStore_findNoteCounts_readReply(QByteArray reply) -{ - bool resultIsSet = false; - NoteCollectionCounts result = NoteCollectionCounts(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("findNoteCounts")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - NoteCollectionCounts v; - readNoteCollectionCounts(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("findNoteCounts: missing result")); - } - return result; -} - -QVariant NoteStore_findNoteCounts_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_findNoteCounts_readReply(reply)); -} - -NoteCollectionCounts NoteStore::findNoteCounts(const NoteFilter& filter, bool withTrash, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_findNoteCounts_prepareParams(authenticationToken, filter, withTrash); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_findNoteCounts_readReply(reply); -} - -AsyncResult* NoteStore::findNoteCountsAsync(const NoteFilter& filter, bool withTrash, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_findNoteCounts_prepareParams(authenticationToken, filter, withTrash); - return new AsyncResult(m_url, params, NoteStore_findNoteCounts_readReplyAsync); -} - -QByteArray NoteStore_getNoteWithResultSpec_prepareParams(QString authenticationToken, Guid guid, const NoteResultSpec& resultSpec) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getNoteWithResultSpec"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getNoteWithResultSpec_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("resultSpec"), ThriftFieldType::T_STRUCT, 3); - writeNoteResultSpec(w, resultSpec); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Note NoteStore_getNoteWithResultSpec_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Note result = Note(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getNoteWithResultSpec")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Note v; - readNote(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getNoteWithResultSpec: missing result")); - } - return result; -} - -QVariant NoteStore_getNoteWithResultSpec_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getNoteWithResultSpec_readReply(reply)); -} - -Note NoteStore::getNoteWithResultSpec(Guid guid, const NoteResultSpec& resultSpec, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteWithResultSpec_prepareParams(authenticationToken, guid, resultSpec); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getNoteWithResultSpec_readReply(reply); -} - -AsyncResult* NoteStore::getNoteWithResultSpecAsync(Guid guid, const NoteResultSpec& resultSpec, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteWithResultSpec_prepareParams(authenticationToken, guid, resultSpec); - return new AsyncResult(m_url, params, NoteStore_getNoteWithResultSpec_readReplyAsync); -} - -QByteArray NoteStore_getNote_prepareParams(QString authenticationToken, Guid guid, bool withContent, bool withResourcesData, bool withResourcesRecognition, bool withResourcesAlternateData) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getNote"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getNote_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withContent"), ThriftFieldType::T_BOOL, 3); - w.writeBool(withContent); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withResourcesData"), ThriftFieldType::T_BOOL, 4); - w.writeBool(withResourcesData); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withResourcesRecognition"), ThriftFieldType::T_BOOL, 5); - w.writeBool(withResourcesRecognition); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withResourcesAlternateData"), ThriftFieldType::T_BOOL, 6); - w.writeBool(withResourcesAlternateData); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Note NoteStore_getNote_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Note result = Note(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getNote")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Note v; - readNote(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getNote: missing result")); - } - return result; -} - -QVariant NoteStore_getNote_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getNote_readReply(reply)); -} - -Note NoteStore::getNote(Guid guid, bool withContent, bool withResourcesData, bool withResourcesRecognition, bool withResourcesAlternateData, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNote_prepareParams(authenticationToken, guid, withContent, withResourcesData, withResourcesRecognition, withResourcesAlternateData); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getNote_readReply(reply); -} - -AsyncResult* NoteStore::getNoteAsync(Guid guid, bool withContent, bool withResourcesData, bool withResourcesRecognition, bool withResourcesAlternateData, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNote_prepareParams(authenticationToken, guid, withContent, withResourcesData, withResourcesRecognition, withResourcesAlternateData); - return new AsyncResult(m_url, params, NoteStore_getNote_readReplyAsync); -} - -QByteArray NoteStore_getNoteApplicationData_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getNoteApplicationData"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getNoteApplicationData_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -LazyMap NoteStore_getNoteApplicationData_readReply(QByteArray reply) -{ - bool resultIsSet = false; - LazyMap result = LazyMap(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getNoteApplicationData")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - LazyMap v; - readLazyMap(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getNoteApplicationData: missing result")); - } - return result; -} - -QVariant NoteStore_getNoteApplicationData_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getNoteApplicationData_readReply(reply)); -} - -LazyMap NoteStore::getNoteApplicationData(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteApplicationData_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getNoteApplicationData_readReply(reply); -} - -AsyncResult* NoteStore::getNoteApplicationDataAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteApplicationData_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_getNoteApplicationData_readReplyAsync); -} - -QByteArray NoteStore_getNoteApplicationDataEntry_prepareParams(QString authenticationToken, Guid guid, QString key) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getNoteApplicationDataEntry"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getNoteApplicationDataEntry_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("key"), ThriftFieldType::T_STRING, 3); - w.writeString(key); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QString NoteStore_getNoteApplicationDataEntry_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QString result = QString(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getNoteApplicationDataEntry")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRING) { - resultIsSet = true; - QString v; - r.readString(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getNoteApplicationDataEntry: missing result")); - } - return result; -} - -QVariant NoteStore_getNoteApplicationDataEntry_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getNoteApplicationDataEntry_readReply(reply)); -} - -QString NoteStore::getNoteApplicationDataEntry(Guid guid, QString key, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteApplicationDataEntry_prepareParams(authenticationToken, guid, key); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getNoteApplicationDataEntry_readReply(reply); -} - -AsyncResult* NoteStore::getNoteApplicationDataEntryAsync(Guid guid, QString key, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteApplicationDataEntry_prepareParams(authenticationToken, guid, key); - return new AsyncResult(m_url, params, NoteStore_getNoteApplicationDataEntry_readReplyAsync); -} - -QByteArray NoteStore_setNoteApplicationDataEntry_prepareParams(QString authenticationToken, Guid guid, QString key, QString value) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("setNoteApplicationDataEntry"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_setNoteApplicationDataEntry_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("key"), ThriftFieldType::T_STRING, 3); - w.writeString(key); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("value"), ThriftFieldType::T_STRING, 4); - w.writeString(value); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_setNoteApplicationDataEntry_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("setNoteApplicationDataEntry")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("setNoteApplicationDataEntry: missing result")); - } - return result; -} - -QVariant NoteStore_setNoteApplicationDataEntry_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_setNoteApplicationDataEntry_readReply(reply)); -} - -qint32 NoteStore::setNoteApplicationDataEntry(Guid guid, QString key, QString value, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_setNoteApplicationDataEntry_prepareParams(authenticationToken, guid, key, value); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_setNoteApplicationDataEntry_readReply(reply); -} - -AsyncResult* NoteStore::setNoteApplicationDataEntryAsync(Guid guid, QString key, QString value, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_setNoteApplicationDataEntry_prepareParams(authenticationToken, guid, key, value); - return new AsyncResult(m_url, params, NoteStore_setNoteApplicationDataEntry_readReplyAsync); -} - -QByteArray NoteStore_unsetNoteApplicationDataEntry_prepareParams(QString authenticationToken, Guid guid, QString key) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("unsetNoteApplicationDataEntry"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_unsetNoteApplicationDataEntry_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("key"), ThriftFieldType::T_STRING, 3); - w.writeString(key); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_unsetNoteApplicationDataEntry_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("unsetNoteApplicationDataEntry")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("unsetNoteApplicationDataEntry: missing result")); - } - return result; -} - -QVariant NoteStore_unsetNoteApplicationDataEntry_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_unsetNoteApplicationDataEntry_readReply(reply)); -} - -qint32 NoteStore::unsetNoteApplicationDataEntry(Guid guid, QString key, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_unsetNoteApplicationDataEntry_prepareParams(authenticationToken, guid, key); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_unsetNoteApplicationDataEntry_readReply(reply); -} - -AsyncResult* NoteStore::unsetNoteApplicationDataEntryAsync(Guid guid, QString key, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_unsetNoteApplicationDataEntry_prepareParams(authenticationToken, guid, key); - return new AsyncResult(m_url, params, NoteStore_unsetNoteApplicationDataEntry_readReplyAsync); -} - -QByteArray NoteStore_getNoteContent_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getNoteContent"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getNoteContent_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QString NoteStore_getNoteContent_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QString result = QString(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getNoteContent")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRING) { - resultIsSet = true; - QString v; - r.readString(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getNoteContent: missing result")); - } - return result; -} - -QVariant NoteStore_getNoteContent_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getNoteContent_readReply(reply)); -} - -QString NoteStore::getNoteContent(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteContent_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getNoteContent_readReply(reply); -} - -AsyncResult* NoteStore::getNoteContentAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteContent_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_getNoteContent_readReplyAsync); -} - -QByteArray NoteStore_getNoteSearchText_prepareParams(QString authenticationToken, Guid guid, bool noteOnly, bool tokenizeForIndexing) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getNoteSearchText"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getNoteSearchText_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("noteOnly"), ThriftFieldType::T_BOOL, 3); - w.writeBool(noteOnly); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("tokenizeForIndexing"), ThriftFieldType::T_BOOL, 4); - w.writeBool(tokenizeForIndexing); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QString NoteStore_getNoteSearchText_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QString result = QString(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getNoteSearchText")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRING) { - resultIsSet = true; - QString v; - r.readString(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getNoteSearchText: missing result")); - } - return result; -} - -QVariant NoteStore_getNoteSearchText_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getNoteSearchText_readReply(reply)); -} - -QString NoteStore::getNoteSearchText(Guid guid, bool noteOnly, bool tokenizeForIndexing, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteSearchText_prepareParams(authenticationToken, guid, noteOnly, tokenizeForIndexing); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getNoteSearchText_readReply(reply); -} - -AsyncResult* NoteStore::getNoteSearchTextAsync(Guid guid, bool noteOnly, bool tokenizeForIndexing, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteSearchText_prepareParams(authenticationToken, guid, noteOnly, tokenizeForIndexing); - return new AsyncResult(m_url, params, NoteStore_getNoteSearchText_readReplyAsync); -} - -QByteArray NoteStore_getResourceSearchText_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getResourceSearchText"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getResourceSearchText_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QString NoteStore_getResourceSearchText_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QString result = QString(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getResourceSearchText")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRING) { - resultIsSet = true; - QString v; - r.readString(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getResourceSearchText: missing result")); - } - return result; -} - -QVariant NoteStore_getResourceSearchText_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getResourceSearchText_readReply(reply)); -} - -QString NoteStore::getResourceSearchText(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceSearchText_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getResourceSearchText_readReply(reply); -} - -AsyncResult* NoteStore::getResourceSearchTextAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceSearchText_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_getResourceSearchText_readReplyAsync); -} - -QByteArray NoteStore_getNoteTagNames_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getNoteTagNames"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getNoteTagNames_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QStringList NoteStore_getNoteTagNames_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QStringList result = QStringList(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getNoteTagNames")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_LIST) { - resultIsSet = true; - QStringList v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (getNoteTagNames.result)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getNoteTagNames: missing result")); - } - return result; -} - -QVariant NoteStore_getNoteTagNames_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getNoteTagNames_readReply(reply)); -} - -QStringList NoteStore::getNoteTagNames(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteTagNames_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getNoteTagNames_readReply(reply); -} - -AsyncResult* NoteStore::getNoteTagNamesAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteTagNames_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_getNoteTagNames_readReplyAsync); -} - -QByteArray NoteStore_createNote_prepareParams(QString authenticationToken, const Note& note) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("createNote"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_createNote_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("note"), ThriftFieldType::T_STRUCT, 2); - writeNote(w, note); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Note NoteStore_createNote_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Note result = Note(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("createNote")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Note v; - readNote(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("createNote: missing result")); - } - return result; -} - -QVariant NoteStore_createNote_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_createNote_readReply(reply)); -} - -Note NoteStore::createNote(const Note& note, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_createNote_prepareParams(authenticationToken, note); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_createNote_readReply(reply); -} - -AsyncResult* NoteStore::createNoteAsync(const Note& note, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_createNote_prepareParams(authenticationToken, note); - return new AsyncResult(m_url, params, NoteStore_createNote_readReplyAsync); -} - -QByteArray NoteStore_updateNote_prepareParams(QString authenticationToken, const Note& note) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("updateNote"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_updateNote_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("note"), ThriftFieldType::T_STRUCT, 2); - writeNote(w, note); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Note NoteStore_updateNote_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Note result = Note(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("updateNote")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Note v; - readNote(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("updateNote: missing result")); - } - return result; -} - -QVariant NoteStore_updateNote_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_updateNote_readReply(reply)); -} - -Note NoteStore::updateNote(const Note& note, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateNote_prepareParams(authenticationToken, note); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_updateNote_readReply(reply); -} - -AsyncResult* NoteStore::updateNoteAsync(const Note& note, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateNote_prepareParams(authenticationToken, note); - return new AsyncResult(m_url, params, NoteStore_updateNote_readReplyAsync); -} - -QByteArray NoteStore_deleteNote_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("deleteNote"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_deleteNote_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_deleteNote_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("deleteNote")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("deleteNote: missing result")); - } - return result; -} - -QVariant NoteStore_deleteNote_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_deleteNote_readReply(reply)); -} - -qint32 NoteStore::deleteNote(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_deleteNote_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_deleteNote_readReply(reply); -} - -AsyncResult* NoteStore::deleteNoteAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_deleteNote_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_deleteNote_readReplyAsync); -} - -QByteArray NoteStore_expungeNote_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("expungeNote"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_expungeNote_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_expungeNote_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("expungeNote")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("expungeNote: missing result")); - } - return result; -} - -QVariant NoteStore_expungeNote_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_expungeNote_readReply(reply)); -} - -qint32 NoteStore::expungeNote(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_expungeNote_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_expungeNote_readReply(reply); -} - -AsyncResult* NoteStore::expungeNoteAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_expungeNote_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_expungeNote_readReplyAsync); -} - -QByteArray NoteStore_copyNote_prepareParams(QString authenticationToken, Guid noteGuid, Guid toNotebookGuid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("copyNote"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_copyNote_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("noteGuid"), ThriftFieldType::T_STRING, 2); - w.writeString(noteGuid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("toNotebookGuid"), ThriftFieldType::T_STRING, 3); - w.writeString(toNotebookGuid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Note NoteStore_copyNote_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Note result = Note(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("copyNote")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Note v; - readNote(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("copyNote: missing result")); - } - return result; -} - -QVariant NoteStore_copyNote_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_copyNote_readReply(reply)); -} - -Note NoteStore::copyNote(Guid noteGuid, Guid toNotebookGuid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_copyNote_prepareParams(authenticationToken, noteGuid, toNotebookGuid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_copyNote_readReply(reply); -} - -AsyncResult* NoteStore::copyNoteAsync(Guid noteGuid, Guid toNotebookGuid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_copyNote_prepareParams(authenticationToken, noteGuid, toNotebookGuid); - return new AsyncResult(m_url, params, NoteStore_copyNote_readReplyAsync); -} - -QByteArray NoteStore_listNoteVersions_prepareParams(QString authenticationToken, Guid noteGuid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("listNoteVersions"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_listNoteVersions_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("noteGuid"), ThriftFieldType::T_STRING, 2); - w.writeString(noteGuid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QList< NoteVersionId > NoteStore_listNoteVersions_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QList< NoteVersionId > result = QList< NoteVersionId >(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("listNoteVersions")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_LIST) { - resultIsSet = true; - QList< NoteVersionId > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (listNoteVersions.result)")); - for(qint32 i = 0; i < size; i++) { - NoteVersionId elem; - readNoteVersionId(r, elem); - v.append(elem); - } - r.readListEnd(); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("listNoteVersions: missing result")); - } - return result; -} - -QVariant NoteStore_listNoteVersions_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_listNoteVersions_readReply(reply)); -} - -QList< NoteVersionId > NoteStore::listNoteVersions(Guid noteGuid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listNoteVersions_prepareParams(authenticationToken, noteGuid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_listNoteVersions_readReply(reply); -} - -AsyncResult* NoteStore::listNoteVersionsAsync(Guid noteGuid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listNoteVersions_prepareParams(authenticationToken, noteGuid); - return new AsyncResult(m_url, params, NoteStore_listNoteVersions_readReplyAsync); -} - -QByteArray NoteStore_getNoteVersion_prepareParams(QString authenticationToken, Guid noteGuid, qint32 updateSequenceNum, bool withResourcesData, bool withResourcesRecognition, bool withResourcesAlternateData) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getNoteVersion"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getNoteVersion_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("noteGuid"), ThriftFieldType::T_STRING, 2); - w.writeString(noteGuid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("updateSequenceNum"), ThriftFieldType::T_I32, 3); - w.writeI32(updateSequenceNum); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withResourcesData"), ThriftFieldType::T_BOOL, 4); - w.writeBool(withResourcesData); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withResourcesRecognition"), ThriftFieldType::T_BOOL, 5); - w.writeBool(withResourcesRecognition); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withResourcesAlternateData"), ThriftFieldType::T_BOOL, 6); - w.writeBool(withResourcesAlternateData); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Note NoteStore_getNoteVersion_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Note result = Note(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getNoteVersion")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Note v; - readNote(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getNoteVersion: missing result")); - } - return result; -} - -QVariant NoteStore_getNoteVersion_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getNoteVersion_readReply(reply)); -} - -Note NoteStore::getNoteVersion(Guid noteGuid, qint32 updateSequenceNum, bool withResourcesData, bool withResourcesRecognition, bool withResourcesAlternateData, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteVersion_prepareParams(authenticationToken, noteGuid, updateSequenceNum, withResourcesData, withResourcesRecognition, withResourcesAlternateData); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getNoteVersion_readReply(reply); -} - -AsyncResult* NoteStore::getNoteVersionAsync(Guid noteGuid, qint32 updateSequenceNum, bool withResourcesData, bool withResourcesRecognition, bool withResourcesAlternateData, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNoteVersion_prepareParams(authenticationToken, noteGuid, updateSequenceNum, withResourcesData, withResourcesRecognition, withResourcesAlternateData); - return new AsyncResult(m_url, params, NoteStore_getNoteVersion_readReplyAsync); -} - -QByteArray NoteStore_getResource_prepareParams(QString authenticationToken, Guid guid, bool withData, bool withRecognition, bool withAttributes, bool withAlternateData) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getResource"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getResource_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withData"), ThriftFieldType::T_BOOL, 3); - w.writeBool(withData); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withRecognition"), ThriftFieldType::T_BOOL, 4); - w.writeBool(withRecognition); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withAttributes"), ThriftFieldType::T_BOOL, 5); - w.writeBool(withAttributes); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withAlternateData"), ThriftFieldType::T_BOOL, 6); - w.writeBool(withAlternateData); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Resource NoteStore_getResource_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Resource result = Resource(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getResource")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Resource v; - readResource(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getResource: missing result")); - } - return result; -} - -QVariant NoteStore_getResource_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getResource_readReply(reply)); -} - -Resource NoteStore::getResource(Guid guid, bool withData, bool withRecognition, bool withAttributes, bool withAlternateData, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResource_prepareParams(authenticationToken, guid, withData, withRecognition, withAttributes, withAlternateData); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getResource_readReply(reply); -} - -AsyncResult* NoteStore::getResourceAsync(Guid guid, bool withData, bool withRecognition, bool withAttributes, bool withAlternateData, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResource_prepareParams(authenticationToken, guid, withData, withRecognition, withAttributes, withAlternateData); - return new AsyncResult(m_url, params, NoteStore_getResource_readReplyAsync); -} - -QByteArray NoteStore_getResourceApplicationData_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getResourceApplicationData"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getResourceApplicationData_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -LazyMap NoteStore_getResourceApplicationData_readReply(QByteArray reply) -{ - bool resultIsSet = false; - LazyMap result = LazyMap(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getResourceApplicationData")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - LazyMap v; - readLazyMap(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getResourceApplicationData: missing result")); - } - return result; -} - -QVariant NoteStore_getResourceApplicationData_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getResourceApplicationData_readReply(reply)); -} - -LazyMap NoteStore::getResourceApplicationData(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceApplicationData_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getResourceApplicationData_readReply(reply); -} - -AsyncResult* NoteStore::getResourceApplicationDataAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceApplicationData_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_getResourceApplicationData_readReplyAsync); -} - -QByteArray NoteStore_getResourceApplicationDataEntry_prepareParams(QString authenticationToken, Guid guid, QString key) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getResourceApplicationDataEntry"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getResourceApplicationDataEntry_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("key"), ThriftFieldType::T_STRING, 3); - w.writeString(key); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QString NoteStore_getResourceApplicationDataEntry_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QString result = QString(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getResourceApplicationDataEntry")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRING) { - resultIsSet = true; - QString v; - r.readString(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getResourceApplicationDataEntry: missing result")); - } - return result; -} - -QVariant NoteStore_getResourceApplicationDataEntry_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getResourceApplicationDataEntry_readReply(reply)); -} - -QString NoteStore::getResourceApplicationDataEntry(Guid guid, QString key, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceApplicationDataEntry_prepareParams(authenticationToken, guid, key); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getResourceApplicationDataEntry_readReply(reply); -} - -AsyncResult* NoteStore::getResourceApplicationDataEntryAsync(Guid guid, QString key, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceApplicationDataEntry_prepareParams(authenticationToken, guid, key); - return new AsyncResult(m_url, params, NoteStore_getResourceApplicationDataEntry_readReplyAsync); -} - -QByteArray NoteStore_setResourceApplicationDataEntry_prepareParams(QString authenticationToken, Guid guid, QString key, QString value) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("setResourceApplicationDataEntry"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_setResourceApplicationDataEntry_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("key"), ThriftFieldType::T_STRING, 3); - w.writeString(key); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("value"), ThriftFieldType::T_STRING, 4); - w.writeString(value); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_setResourceApplicationDataEntry_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("setResourceApplicationDataEntry")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("setResourceApplicationDataEntry: missing result")); - } - return result; -} - -QVariant NoteStore_setResourceApplicationDataEntry_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_setResourceApplicationDataEntry_readReply(reply)); -} - -qint32 NoteStore::setResourceApplicationDataEntry(Guid guid, QString key, QString value, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_setResourceApplicationDataEntry_prepareParams(authenticationToken, guid, key, value); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_setResourceApplicationDataEntry_readReply(reply); -} - -AsyncResult* NoteStore::setResourceApplicationDataEntryAsync(Guid guid, QString key, QString value, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_setResourceApplicationDataEntry_prepareParams(authenticationToken, guid, key, value); - return new AsyncResult(m_url, params, NoteStore_setResourceApplicationDataEntry_readReplyAsync); -} - -QByteArray NoteStore_unsetResourceApplicationDataEntry_prepareParams(QString authenticationToken, Guid guid, QString key) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("unsetResourceApplicationDataEntry"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_unsetResourceApplicationDataEntry_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("key"), ThriftFieldType::T_STRING, 3); - w.writeString(key); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_unsetResourceApplicationDataEntry_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("unsetResourceApplicationDataEntry")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("unsetResourceApplicationDataEntry: missing result")); - } - return result; -} - -QVariant NoteStore_unsetResourceApplicationDataEntry_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_unsetResourceApplicationDataEntry_readReply(reply)); -} - -qint32 NoteStore::unsetResourceApplicationDataEntry(Guid guid, QString key, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_unsetResourceApplicationDataEntry_prepareParams(authenticationToken, guid, key); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_unsetResourceApplicationDataEntry_readReply(reply); -} - -AsyncResult* NoteStore::unsetResourceApplicationDataEntryAsync(Guid guid, QString key, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_unsetResourceApplicationDataEntry_prepareParams(authenticationToken, guid, key); - return new AsyncResult(m_url, params, NoteStore_unsetResourceApplicationDataEntry_readReplyAsync); -} - -QByteArray NoteStore_updateResource_prepareParams(QString authenticationToken, const Resource& resource) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("updateResource"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_updateResource_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("resource"), ThriftFieldType::T_STRUCT, 2); - writeResource(w, resource); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_updateResource_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("updateResource")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("updateResource: missing result")); - } - return result; -} - -QVariant NoteStore_updateResource_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_updateResource_readReply(reply)); -} - -qint32 NoteStore::updateResource(const Resource& resource, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateResource_prepareParams(authenticationToken, resource); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_updateResource_readReply(reply); -} - -AsyncResult* NoteStore::updateResourceAsync(const Resource& resource, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateResource_prepareParams(authenticationToken, resource); - return new AsyncResult(m_url, params, NoteStore_updateResource_readReplyAsync); -} - -QByteArray NoteStore_getResourceData_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getResourceData"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getResourceData_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QByteArray NoteStore_getResourceData_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QByteArray result = QByteArray(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getResourceData")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRING) { - resultIsSet = true; - QByteArray v; - r.readBinary(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getResourceData: missing result")); - } - return result; -} - -QVariant NoteStore_getResourceData_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getResourceData_readReply(reply)); -} - -QByteArray NoteStore::getResourceData(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceData_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getResourceData_readReply(reply); -} - -AsyncResult* NoteStore::getResourceDataAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceData_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_getResourceData_readReplyAsync); -} - -QByteArray NoteStore_getResourceByHash_prepareParams(QString authenticationToken, Guid noteGuid, QByteArray contentHash, bool withData, bool withRecognition, bool withAlternateData) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getResourceByHash"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getResourceByHash_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("noteGuid"), ThriftFieldType::T_STRING, 2); - w.writeString(noteGuid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("contentHash"), ThriftFieldType::T_STRING, 3); - w.writeBinary(contentHash); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withData"), ThriftFieldType::T_BOOL, 4); - w.writeBool(withData); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withRecognition"), ThriftFieldType::T_BOOL, 5); - w.writeBool(withRecognition); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("withAlternateData"), ThriftFieldType::T_BOOL, 6); - w.writeBool(withAlternateData); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Resource NoteStore_getResourceByHash_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Resource result = Resource(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getResourceByHash")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Resource v; - readResource(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getResourceByHash: missing result")); - } - return result; -} - -QVariant NoteStore_getResourceByHash_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getResourceByHash_readReply(reply)); -} - -Resource NoteStore::getResourceByHash(Guid noteGuid, QByteArray contentHash, bool withData, bool withRecognition, bool withAlternateData, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceByHash_prepareParams(authenticationToken, noteGuid, contentHash, withData, withRecognition, withAlternateData); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getResourceByHash_readReply(reply); -} - -AsyncResult* NoteStore::getResourceByHashAsync(Guid noteGuid, QByteArray contentHash, bool withData, bool withRecognition, bool withAlternateData, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceByHash_prepareParams(authenticationToken, noteGuid, contentHash, withData, withRecognition, withAlternateData); - return new AsyncResult(m_url, params, NoteStore_getResourceByHash_readReplyAsync); -} - -QByteArray NoteStore_getResourceRecognition_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getResourceRecognition"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getResourceRecognition_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QByteArray NoteStore_getResourceRecognition_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QByteArray result = QByteArray(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getResourceRecognition")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRING) { - resultIsSet = true; - QByteArray v; - r.readBinary(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getResourceRecognition: missing result")); - } - return result; -} - -QVariant NoteStore_getResourceRecognition_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getResourceRecognition_readReply(reply)); -} - -QByteArray NoteStore::getResourceRecognition(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceRecognition_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getResourceRecognition_readReply(reply); -} - -AsyncResult* NoteStore::getResourceRecognitionAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceRecognition_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_getResourceRecognition_readReplyAsync); -} - -QByteArray NoteStore_getResourceAlternateData_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getResourceAlternateData"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getResourceAlternateData_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QByteArray NoteStore_getResourceAlternateData_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QByteArray result = QByteArray(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getResourceAlternateData")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRING) { - resultIsSet = true; - QByteArray v; - r.readBinary(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getResourceAlternateData: missing result")); - } - return result; -} - -QVariant NoteStore_getResourceAlternateData_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getResourceAlternateData_readReply(reply)); -} - -QByteArray NoteStore::getResourceAlternateData(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceAlternateData_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getResourceAlternateData_readReply(reply); -} - -AsyncResult* NoteStore::getResourceAlternateDataAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceAlternateData_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_getResourceAlternateData_readReplyAsync); -} - -QByteArray NoteStore_getResourceAttributes_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getResourceAttributes"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getResourceAttributes_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -ResourceAttributes NoteStore_getResourceAttributes_readReply(QByteArray reply) -{ - bool resultIsSet = false; - ResourceAttributes result = ResourceAttributes(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getResourceAttributes")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - ResourceAttributes v; - readResourceAttributes(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getResourceAttributes: missing result")); - } - return result; -} - -QVariant NoteStore_getResourceAttributes_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getResourceAttributes_readReply(reply)); -} - -ResourceAttributes NoteStore::getResourceAttributes(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceAttributes_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getResourceAttributes_readReply(reply); -} - -AsyncResult* NoteStore::getResourceAttributesAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getResourceAttributes_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_getResourceAttributes_readReplyAsync); -} - -QByteArray NoteStore_getPublicNotebook_prepareParams(UserID userId, QString publicUri) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getPublicNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getPublicNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("userId"), ThriftFieldType::T_I32, 1); - w.writeI32(userId); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("publicUri"), ThriftFieldType::T_STRING, 2); - w.writeString(publicUri); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Notebook NoteStore_getPublicNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Notebook result = Notebook(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getPublicNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Notebook v; - readNotebook(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getPublicNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_getPublicNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getPublicNotebook_readReply(reply)); -} - -Notebook NoteStore::getPublicNotebook(UserID userId, QString publicUri) -{ - QByteArray params = NoteStore_getPublicNotebook_prepareParams(userId, publicUri); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getPublicNotebook_readReply(reply); -} - -AsyncResult* NoteStore::getPublicNotebookAsync(UserID userId, QString publicUri) -{ - QByteArray params = NoteStore_getPublicNotebook_prepareParams(userId, publicUri); - return new AsyncResult(m_url, params, NoteStore_getPublicNotebook_readReplyAsync); -} - -QByteArray NoteStore_shareNotebook_prepareParams(QString authenticationToken, const SharedNotebook& sharedNotebook, QString message) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("shareNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_shareNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("sharedNotebook"), ThriftFieldType::T_STRUCT, 2); - writeSharedNotebook(w, sharedNotebook); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("message"), ThriftFieldType::T_STRING, 3); - w.writeString(message); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -SharedNotebook NoteStore_shareNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - SharedNotebook result = SharedNotebook(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("shareNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - SharedNotebook v; - readSharedNotebook(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("shareNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_shareNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_shareNotebook_readReply(reply)); -} - -SharedNotebook NoteStore::shareNotebook(const SharedNotebook& sharedNotebook, QString message, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_shareNotebook_prepareParams(authenticationToken, sharedNotebook, message); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_shareNotebook_readReply(reply); -} - -AsyncResult* NoteStore::shareNotebookAsync(const SharedNotebook& sharedNotebook, QString message, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_shareNotebook_prepareParams(authenticationToken, sharedNotebook, message); - return new AsyncResult(m_url, params, NoteStore_shareNotebook_readReplyAsync); -} - -QByteArray NoteStore_createOrUpdateNotebookShares_prepareParams(QString authenticationToken, const NotebookShareTemplate& shareTemplate) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("createOrUpdateNotebookShares"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_createOrUpdateNotebookShares_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("shareTemplate"), ThriftFieldType::T_STRUCT, 2); - writeNotebookShareTemplate(w, shareTemplate); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -CreateOrUpdateNotebookSharesResult NoteStore_createOrUpdateNotebookShares_readReply(QByteArray reply) -{ - bool resultIsSet = false; - CreateOrUpdateNotebookSharesResult result = CreateOrUpdateNotebookSharesResult(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("createOrUpdateNotebookShares")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - CreateOrUpdateNotebookSharesResult v; - readCreateOrUpdateNotebookSharesResult(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMInvalidContactsException e; - readEDAMInvalidContactsException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("createOrUpdateNotebookShares: missing result")); - } - return result; -} - -QVariant NoteStore_createOrUpdateNotebookShares_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_createOrUpdateNotebookShares_readReply(reply)); -} - -CreateOrUpdateNotebookSharesResult NoteStore::createOrUpdateNotebookShares(const NotebookShareTemplate& shareTemplate, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_createOrUpdateNotebookShares_prepareParams(authenticationToken, shareTemplate); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_createOrUpdateNotebookShares_readReply(reply); -} - -AsyncResult* NoteStore::createOrUpdateNotebookSharesAsync(const NotebookShareTemplate& shareTemplate, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_createOrUpdateNotebookShares_prepareParams(authenticationToken, shareTemplate); - return new AsyncResult(m_url, params, NoteStore_createOrUpdateNotebookShares_readReplyAsync); -} - -QByteArray NoteStore_updateSharedNotebook_prepareParams(QString authenticationToken, const SharedNotebook& sharedNotebook) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("updateSharedNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_updateSharedNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("sharedNotebook"), ThriftFieldType::T_STRUCT, 2); - writeSharedNotebook(w, sharedNotebook); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_updateSharedNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("updateSharedNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("updateSharedNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_updateSharedNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_updateSharedNotebook_readReply(reply)); -} - -qint32 NoteStore::updateSharedNotebook(const SharedNotebook& sharedNotebook, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateSharedNotebook_prepareParams(authenticationToken, sharedNotebook); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_updateSharedNotebook_readReply(reply); -} - -AsyncResult* NoteStore::updateSharedNotebookAsync(const SharedNotebook& sharedNotebook, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateSharedNotebook_prepareParams(authenticationToken, sharedNotebook); - return new AsyncResult(m_url, params, NoteStore_updateSharedNotebook_readReplyAsync); -} - -QByteArray NoteStore_setNotebookRecipientSettings_prepareParams(QString authenticationToken, QString notebookGuid, const NotebookRecipientSettings& recipientSettings) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("setNotebookRecipientSettings"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_setNotebookRecipientSettings_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("notebookGuid"), ThriftFieldType::T_STRING, 2); - w.writeString(notebookGuid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("recipientSettings"), ThriftFieldType::T_STRUCT, 3); - writeNotebookRecipientSettings(w, recipientSettings); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -Notebook NoteStore_setNotebookRecipientSettings_readReply(QByteArray reply) -{ - bool resultIsSet = false; - Notebook result = Notebook(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("setNotebookRecipientSettings")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - Notebook v; - readNotebook(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("setNotebookRecipientSettings: missing result")); - } - return result; -} - -QVariant NoteStore_setNotebookRecipientSettings_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_setNotebookRecipientSettings_readReply(reply)); -} - -Notebook NoteStore::setNotebookRecipientSettings(QString notebookGuid, const NotebookRecipientSettings& recipientSettings, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_setNotebookRecipientSettings_prepareParams(authenticationToken, notebookGuid, recipientSettings); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_setNotebookRecipientSettings_readReply(reply); -} - -AsyncResult* NoteStore::setNotebookRecipientSettingsAsync(QString notebookGuid, const NotebookRecipientSettings& recipientSettings, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_setNotebookRecipientSettings_prepareParams(authenticationToken, notebookGuid, recipientSettings); - return new AsyncResult(m_url, params, NoteStore_setNotebookRecipientSettings_readReplyAsync); -} - -QByteArray NoteStore_listSharedNotebooks_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("listSharedNotebooks"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_listSharedNotebooks_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QList< SharedNotebook > NoteStore_listSharedNotebooks_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QList< SharedNotebook > result = QList< SharedNotebook >(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("listSharedNotebooks")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_LIST) { - resultIsSet = true; - QList< SharedNotebook > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (listSharedNotebooks.result)")); - for(qint32 i = 0; i < size; i++) { - SharedNotebook elem; - readSharedNotebook(r, elem); - v.append(elem); - } - r.readListEnd(); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("listSharedNotebooks: missing result")); - } - return result; -} - -QVariant NoteStore_listSharedNotebooks_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_listSharedNotebooks_readReply(reply)); -} - -QList< SharedNotebook > NoteStore::listSharedNotebooks(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listSharedNotebooks_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_listSharedNotebooks_readReply(reply); -} - -AsyncResult* NoteStore::listSharedNotebooksAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listSharedNotebooks_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, NoteStore_listSharedNotebooks_readReplyAsync); -} - -QByteArray NoteStore_createLinkedNotebook_prepareParams(QString authenticationToken, const LinkedNotebook& linkedNotebook) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("createLinkedNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_createLinkedNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("linkedNotebook"), ThriftFieldType::T_STRUCT, 2); - writeLinkedNotebook(w, linkedNotebook); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -LinkedNotebook NoteStore_createLinkedNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - LinkedNotebook result = LinkedNotebook(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("createLinkedNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - LinkedNotebook v; - readLinkedNotebook(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("createLinkedNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_createLinkedNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_createLinkedNotebook_readReply(reply)); -} - -LinkedNotebook NoteStore::createLinkedNotebook(const LinkedNotebook& linkedNotebook, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_createLinkedNotebook_prepareParams(authenticationToken, linkedNotebook); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_createLinkedNotebook_readReply(reply); -} - -AsyncResult* NoteStore::createLinkedNotebookAsync(const LinkedNotebook& linkedNotebook, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_createLinkedNotebook_prepareParams(authenticationToken, linkedNotebook); - return new AsyncResult(m_url, params, NoteStore_createLinkedNotebook_readReplyAsync); -} - -QByteArray NoteStore_updateLinkedNotebook_prepareParams(QString authenticationToken, const LinkedNotebook& linkedNotebook) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("updateLinkedNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_updateLinkedNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("linkedNotebook"), ThriftFieldType::T_STRUCT, 2); - writeLinkedNotebook(w, linkedNotebook); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_updateLinkedNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("updateLinkedNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("updateLinkedNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_updateLinkedNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_updateLinkedNotebook_readReply(reply)); -} - -qint32 NoteStore::updateLinkedNotebook(const LinkedNotebook& linkedNotebook, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateLinkedNotebook_prepareParams(authenticationToken, linkedNotebook); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_updateLinkedNotebook_readReply(reply); -} - -AsyncResult* NoteStore::updateLinkedNotebookAsync(const LinkedNotebook& linkedNotebook, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateLinkedNotebook_prepareParams(authenticationToken, linkedNotebook); - return new AsyncResult(m_url, params, NoteStore_updateLinkedNotebook_readReplyAsync); -} - -QByteArray NoteStore_listLinkedNotebooks_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("listLinkedNotebooks"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_listLinkedNotebooks_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QList< LinkedNotebook > NoteStore_listLinkedNotebooks_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QList< LinkedNotebook > result = QList< LinkedNotebook >(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("listLinkedNotebooks")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_LIST) { - resultIsSet = true; - QList< LinkedNotebook > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (listLinkedNotebooks.result)")); - for(qint32 i = 0; i < size; i++) { - LinkedNotebook elem; - readLinkedNotebook(r, elem); - v.append(elem); - } - r.readListEnd(); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("listLinkedNotebooks: missing result")); - } - return result; -} - -QVariant NoteStore_listLinkedNotebooks_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_listLinkedNotebooks_readReply(reply)); -} - -QList< LinkedNotebook > NoteStore::listLinkedNotebooks(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listLinkedNotebooks_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_listLinkedNotebooks_readReply(reply); -} - -AsyncResult* NoteStore::listLinkedNotebooksAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_listLinkedNotebooks_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, NoteStore_listLinkedNotebooks_readReplyAsync); -} - -QByteArray NoteStore_expungeLinkedNotebook_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("expungeLinkedNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_expungeLinkedNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -qint32 NoteStore_expungeLinkedNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - qint32 result = qint32(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("expungeLinkedNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_I32) { - resultIsSet = true; - qint32 v; - r.readI32(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("expungeLinkedNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_expungeLinkedNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_expungeLinkedNotebook_readReply(reply)); -} - -qint32 NoteStore::expungeLinkedNotebook(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_expungeLinkedNotebook_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_expungeLinkedNotebook_readReply(reply); -} - -AsyncResult* NoteStore::expungeLinkedNotebookAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_expungeLinkedNotebook_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_expungeLinkedNotebook_readReplyAsync); -} - -QByteArray NoteStore_authenticateToSharedNotebook_prepareParams(QString shareKeyOrGlobalId, QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("authenticateToSharedNotebook"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_authenticateToSharedNotebook_pargs")); - w.writeFieldBegin(QStringLiteral("shareKeyOrGlobalId"), ThriftFieldType::T_STRING, 1); - w.writeString(shareKeyOrGlobalId); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 2); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -AuthenticationResult NoteStore_authenticateToSharedNotebook_readReply(QByteArray reply) -{ - bool resultIsSet = false; - AuthenticationResult result = AuthenticationResult(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("authenticateToSharedNotebook")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - AuthenticationResult v; - readAuthenticationResult(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("authenticateToSharedNotebook: missing result")); - } - return result; -} - -QVariant NoteStore_authenticateToSharedNotebook_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_authenticateToSharedNotebook_readReply(reply)); -} - -AuthenticationResult NoteStore::authenticateToSharedNotebook(QString shareKeyOrGlobalId, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_authenticateToSharedNotebook_prepareParams(shareKeyOrGlobalId, authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_authenticateToSharedNotebook_readReply(reply); -} - -AsyncResult* NoteStore::authenticateToSharedNotebookAsync(QString shareKeyOrGlobalId, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_authenticateToSharedNotebook_prepareParams(shareKeyOrGlobalId, authenticationToken); - return new AsyncResult(m_url, params, NoteStore_authenticateToSharedNotebook_readReplyAsync); -} - -QByteArray NoteStore_getSharedNotebookByAuth_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getSharedNotebookByAuth"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getSharedNotebookByAuth_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -SharedNotebook NoteStore_getSharedNotebookByAuth_readReply(QByteArray reply) -{ - bool resultIsSet = false; - SharedNotebook result = SharedNotebook(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getSharedNotebookByAuth")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - SharedNotebook v; - readSharedNotebook(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getSharedNotebookByAuth: missing result")); - } - return result; -} - -QVariant NoteStore_getSharedNotebookByAuth_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getSharedNotebookByAuth_readReply(reply)); -} - -SharedNotebook NoteStore::getSharedNotebookByAuth(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getSharedNotebookByAuth_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getSharedNotebookByAuth_readReply(reply); -} - -AsyncResult* NoteStore::getSharedNotebookByAuthAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getSharedNotebookByAuth_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, NoteStore_getSharedNotebookByAuth_readReplyAsync); -} - -QByteArray NoteStore_emailNote_prepareParams(QString authenticationToken, const NoteEmailParameters& parameters) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("emailNote"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_emailNote_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("parameters"), ThriftFieldType::T_STRUCT, 2); - writeNoteEmailParameters(w, parameters); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -void NoteStore_emailNote_readReply(QByteArray reply) -{ - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("emailNote")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); -} - -QVariant NoteStore_emailNote_readReplyAsync(QByteArray reply) -{ - NoteStore_emailNote_readReply(reply); - return QVariant(); -} - -void NoteStore::emailNote(const NoteEmailParameters& parameters, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_emailNote_prepareParams(authenticationToken, parameters); - QByteArray reply = askEvernote(m_url, params); - NoteStore_emailNote_readReply(reply); -} - -AsyncResult* NoteStore::emailNoteAsync(const NoteEmailParameters& parameters, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_emailNote_prepareParams(authenticationToken, parameters); - return new AsyncResult(m_url, params, NoteStore_emailNote_readReplyAsync); -} - -QByteArray NoteStore_shareNote_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("shareNote"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_shareNote_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QString NoteStore_shareNote_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QString result = QString(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("shareNote")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRING) { - resultIsSet = true; - QString v; - r.readString(v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("shareNote: missing result")); - } - return result; -} - -QVariant NoteStore_shareNote_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_shareNote_readReply(reply)); -} - -QString NoteStore::shareNote(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_shareNote_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_shareNote_readReply(reply); -} - -AsyncResult* NoteStore::shareNoteAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_shareNote_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_shareNote_readReplyAsync); -} - -QByteArray NoteStore_stopSharingNote_prepareParams(QString authenticationToken, Guid guid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("stopSharingNote"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_stopSharingNote_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 2); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -void NoteStore_stopSharingNote_readReply(QByteArray reply) -{ - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("stopSharingNote")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); -} - -QVariant NoteStore_stopSharingNote_readReplyAsync(QByteArray reply) -{ - NoteStore_stopSharingNote_readReply(reply); - return QVariant(); -} - -void NoteStore::stopSharingNote(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_stopSharingNote_prepareParams(authenticationToken, guid); - QByteArray reply = askEvernote(m_url, params); - NoteStore_stopSharingNote_readReply(reply); -} - -AsyncResult* NoteStore::stopSharingNoteAsync(Guid guid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_stopSharingNote_prepareParams(authenticationToken, guid); - return new AsyncResult(m_url, params, NoteStore_stopSharingNote_readReplyAsync); -} - -QByteArray NoteStore_authenticateToSharedNote_prepareParams(QString guid, QString noteKey, QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("authenticateToSharedNote"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_authenticateToSharedNote_pargs")); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 1); - w.writeString(guid); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("noteKey"), ThriftFieldType::T_STRING, 2); - w.writeString(noteKey); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 3); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -AuthenticationResult NoteStore_authenticateToSharedNote_readReply(QByteArray reply) -{ - bool resultIsSet = false; - AuthenticationResult result = AuthenticationResult(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("authenticateToSharedNote")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - AuthenticationResult v; - readAuthenticationResult(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("authenticateToSharedNote: missing result")); - } - return result; -} - -QVariant NoteStore_authenticateToSharedNote_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_authenticateToSharedNote_readReply(reply)); -} - -AuthenticationResult NoteStore::authenticateToSharedNote(QString guid, QString noteKey, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_authenticateToSharedNote_prepareParams(guid, noteKey, authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_authenticateToSharedNote_readReply(reply); -} - -AsyncResult* NoteStore::authenticateToSharedNoteAsync(QString guid, QString noteKey, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_authenticateToSharedNote_prepareParams(guid, noteKey, authenticationToken); - return new AsyncResult(m_url, params, NoteStore_authenticateToSharedNote_readReplyAsync); -} - -QByteArray NoteStore_findRelated_prepareParams(QString authenticationToken, const RelatedQuery& query, const RelatedResultSpec& resultSpec) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("findRelated"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_findRelated_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("query"), ThriftFieldType::T_STRUCT, 2); - writeRelatedQuery(w, query); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("resultSpec"), ThriftFieldType::T_STRUCT, 3); - writeRelatedResultSpec(w, resultSpec); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -RelatedResult NoteStore_findRelated_readReply(QByteArray reply) -{ - bool resultIsSet = false; - RelatedResult result = RelatedResult(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("findRelated")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - RelatedResult v; - readRelatedResult(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("findRelated: missing result")); - } - return result; -} - -QVariant NoteStore_findRelated_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_findRelated_readReply(reply)); -} - -RelatedResult NoteStore::findRelated(const RelatedQuery& query, const RelatedResultSpec& resultSpec, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_findRelated_prepareParams(authenticationToken, query, resultSpec); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_findRelated_readReply(reply); -} - -AsyncResult* NoteStore::findRelatedAsync(const RelatedQuery& query, const RelatedResultSpec& resultSpec, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_findRelated_prepareParams(authenticationToken, query, resultSpec); - return new AsyncResult(m_url, params, NoteStore_findRelated_readReplyAsync); -} - -QByteArray NoteStore_updateNoteIfUsnMatches_prepareParams(QString authenticationToken, const Note& note) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("updateNoteIfUsnMatches"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_updateNoteIfUsnMatches_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("note"), ThriftFieldType::T_STRUCT, 2); - writeNote(w, note); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -UpdateNoteIfUsnMatchesResult NoteStore_updateNoteIfUsnMatches_readReply(QByteArray reply) -{ - bool resultIsSet = false; - UpdateNoteIfUsnMatchesResult result = UpdateNoteIfUsnMatchesResult(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("updateNoteIfUsnMatches")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - UpdateNoteIfUsnMatchesResult v; - readUpdateNoteIfUsnMatchesResult(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("updateNoteIfUsnMatches: missing result")); - } - return result; -} - -QVariant NoteStore_updateNoteIfUsnMatches_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_updateNoteIfUsnMatches_readReply(reply)); -} - -UpdateNoteIfUsnMatchesResult NoteStore::updateNoteIfUsnMatches(const Note& note, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateNoteIfUsnMatches_prepareParams(authenticationToken, note); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_updateNoteIfUsnMatches_readReply(reply); -} - -AsyncResult* NoteStore::updateNoteIfUsnMatchesAsync(const Note& note, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_updateNoteIfUsnMatches_prepareParams(authenticationToken, note); - return new AsyncResult(m_url, params, NoteStore_updateNoteIfUsnMatches_readReplyAsync); -} - -QByteArray NoteStore_manageNotebookShares_prepareParams(QString authenticationToken, const ManageNotebookSharesParameters& parameters) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("manageNotebookShares"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_manageNotebookShares_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("parameters"), ThriftFieldType::T_STRUCT, 2); - writeManageNotebookSharesParameters(w, parameters); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -ManageNotebookSharesResult NoteStore_manageNotebookShares_readReply(QByteArray reply) -{ - bool resultIsSet = false; - ManageNotebookSharesResult result = ManageNotebookSharesResult(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("manageNotebookShares")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - ManageNotebookSharesResult v; - readManageNotebookSharesResult(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("manageNotebookShares: missing result")); - } - return result; -} - -QVariant NoteStore_manageNotebookShares_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_manageNotebookShares_readReply(reply)); -} - -ManageNotebookSharesResult NoteStore::manageNotebookShares(const ManageNotebookSharesParameters& parameters, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_manageNotebookShares_prepareParams(authenticationToken, parameters); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_manageNotebookShares_readReply(reply); -} - -AsyncResult* NoteStore::manageNotebookSharesAsync(const ManageNotebookSharesParameters& parameters, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_manageNotebookShares_prepareParams(authenticationToken, parameters); - return new AsyncResult(m_url, params, NoteStore_manageNotebookShares_readReplyAsync); -} - -QByteArray NoteStore_getNotebookShares_prepareParams(QString authenticationToken, QString notebookGuid) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getNotebookShares"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("NoteStore_getNotebookShares_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("notebookGuid"), ThriftFieldType::T_STRING, 2); - w.writeString(notebookGuid); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -ShareRelationships NoteStore_getNotebookShares_readReply(QByteArray reply) -{ - bool resultIsSet = false; - ShareRelationships result = ShareRelationships(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getNotebookShares")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - ShareRelationships v; - readShareRelationships(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getNotebookShares: missing result")); - } - return result; -} - -QVariant NoteStore_getNotebookShares_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(NoteStore_getNotebookShares_readReply(reply)); -} - -ShareRelationships NoteStore::getNotebookShares(QString notebookGuid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNotebookShares_prepareParams(authenticationToken, notebookGuid); - QByteArray reply = askEvernote(m_url, params); - return NoteStore_getNotebookShares_readReply(reply); -} - -AsyncResult* NoteStore::getNotebookSharesAsync(QString notebookGuid, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = NoteStore_getNotebookShares_prepareParams(authenticationToken, notebookGuid); - return new AsyncResult(m_url, params, NoteStore_getNotebookShares_readReplyAsync); -} - -QByteArray UserStore_checkVersion_prepareParams(QString clientName, qint16 edamVersionMajor, qint16 edamVersionMinor) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("checkVersion"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_checkVersion_pargs")); - w.writeFieldBegin(QStringLiteral("clientName"), ThriftFieldType::T_STRING, 1); - w.writeString(clientName); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("edamVersionMajor"), ThriftFieldType::T_I16, 2); - w.writeI16(edamVersionMajor); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("edamVersionMinor"), ThriftFieldType::T_I16, 3); - w.writeI16(edamVersionMinor); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -bool UserStore_checkVersion_readReply(QByteArray reply) -{ - bool resultIsSet = false; - bool result = bool(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("checkVersion")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_BOOL) { - resultIsSet = true; - bool v; - r.readBool(v); - result = v; - } else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("checkVersion: missing result")); - } - return result; -} - -QVariant UserStore_checkVersion_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(UserStore_checkVersion_readReply(reply)); -} - -bool UserStore::checkVersion(QString clientName, qint16 edamVersionMajor, qint16 edamVersionMinor) -{ - QByteArray params = UserStore_checkVersion_prepareParams(clientName, edamVersionMajor, edamVersionMinor); - QByteArray reply = askEvernote(m_url, params); - return UserStore_checkVersion_readReply(reply); -} - -AsyncResult* UserStore::checkVersionAsync(QString clientName, qint16 edamVersionMajor, qint16 edamVersionMinor) -{ - QByteArray params = UserStore_checkVersion_prepareParams(clientName, edamVersionMajor, edamVersionMinor); - return new AsyncResult(m_url, params, UserStore_checkVersion_readReplyAsync); -} - -QByteArray UserStore_getBootstrapInfo_prepareParams(QString locale) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getBootstrapInfo"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_getBootstrapInfo_pargs")); - w.writeFieldBegin(QStringLiteral("locale"), ThriftFieldType::T_STRING, 1); - w.writeString(locale); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -BootstrapInfo UserStore_getBootstrapInfo_readReply(QByteArray reply) -{ - bool resultIsSet = false; - BootstrapInfo result = BootstrapInfo(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getBootstrapInfo")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - BootstrapInfo v; - readBootstrapInfo(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getBootstrapInfo: missing result")); - } - return result; -} - -QVariant UserStore_getBootstrapInfo_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(UserStore_getBootstrapInfo_readReply(reply)); -} - -BootstrapInfo UserStore::getBootstrapInfo(QString locale) -{ - QByteArray params = UserStore_getBootstrapInfo_prepareParams(locale); - QByteArray reply = askEvernote(m_url, params); - return UserStore_getBootstrapInfo_readReply(reply); -} - -AsyncResult* UserStore::getBootstrapInfoAsync(QString locale) -{ - QByteArray params = UserStore_getBootstrapInfo_prepareParams(locale); - return new AsyncResult(m_url, params, UserStore_getBootstrapInfo_readReplyAsync); -} - -QByteArray UserStore_authenticateLongSession_prepareParams(QString username, QString password, QString consumerKey, QString consumerSecret, QString deviceIdentifier, QString deviceDescription, bool supportsTwoFactor) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("authenticateLongSession"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_authenticateLongSession_pargs")); - w.writeFieldBegin(QStringLiteral("username"), ThriftFieldType::T_STRING, 1); - w.writeString(username); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("password"), ThriftFieldType::T_STRING, 2); - w.writeString(password); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("consumerKey"), ThriftFieldType::T_STRING, 3); - w.writeString(consumerKey); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("consumerSecret"), ThriftFieldType::T_STRING, 4); - w.writeString(consumerSecret); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("deviceIdentifier"), ThriftFieldType::T_STRING, 5); - w.writeString(deviceIdentifier); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("deviceDescription"), ThriftFieldType::T_STRING, 6); - w.writeString(deviceDescription); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("supportsTwoFactor"), ThriftFieldType::T_BOOL, 7); - w.writeBool(supportsTwoFactor); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -AuthenticationResult UserStore_authenticateLongSession_readReply(QByteArray reply) -{ - bool resultIsSet = false; - AuthenticationResult result = AuthenticationResult(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("authenticateLongSession")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - AuthenticationResult v; - readAuthenticationResult(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("authenticateLongSession: missing result")); - } - return result; -} - -QVariant UserStore_authenticateLongSession_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(UserStore_authenticateLongSession_readReply(reply)); -} - -AuthenticationResult UserStore::authenticateLongSession(QString username, QString password, QString consumerKey, QString consumerSecret, QString deviceIdentifier, QString deviceDescription, bool supportsTwoFactor) -{ - QByteArray params = UserStore_authenticateLongSession_prepareParams(username, password, consumerKey, consumerSecret, deviceIdentifier, deviceDescription, supportsTwoFactor); - QByteArray reply = askEvernote(m_url, params); - return UserStore_authenticateLongSession_readReply(reply); -} - -AsyncResult* UserStore::authenticateLongSessionAsync(QString username, QString password, QString consumerKey, QString consumerSecret, QString deviceIdentifier, QString deviceDescription, bool supportsTwoFactor) -{ - QByteArray params = UserStore_authenticateLongSession_prepareParams(username, password, consumerKey, consumerSecret, deviceIdentifier, deviceDescription, supportsTwoFactor); - return new AsyncResult(m_url, params, UserStore_authenticateLongSession_readReplyAsync); -} - -QByteArray UserStore_completeTwoFactorAuthentication_prepareParams(QString authenticationToken, QString oneTimeCode, QString deviceIdentifier, QString deviceDescription) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("completeTwoFactorAuthentication"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_completeTwoFactorAuthentication_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("oneTimeCode"), ThriftFieldType::T_STRING, 2); - w.writeString(oneTimeCode); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("deviceIdentifier"), ThriftFieldType::T_STRING, 3); - w.writeString(deviceIdentifier); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("deviceDescription"), ThriftFieldType::T_STRING, 4); - w.writeString(deviceDescription); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -AuthenticationResult UserStore_completeTwoFactorAuthentication_readReply(QByteArray reply) -{ - bool resultIsSet = false; - AuthenticationResult result = AuthenticationResult(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("completeTwoFactorAuthentication")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - AuthenticationResult v; - readAuthenticationResult(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("completeTwoFactorAuthentication: missing result")); - } - return result; -} - -QVariant UserStore_completeTwoFactorAuthentication_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(UserStore_completeTwoFactorAuthentication_readReply(reply)); -} - -AuthenticationResult UserStore::completeTwoFactorAuthentication(QString oneTimeCode, QString deviceIdentifier, QString deviceDescription, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_completeTwoFactorAuthentication_prepareParams(authenticationToken, oneTimeCode, deviceIdentifier, deviceDescription); - QByteArray reply = askEvernote(m_url, params); - return UserStore_completeTwoFactorAuthentication_readReply(reply); -} - -AsyncResult* UserStore::completeTwoFactorAuthenticationAsync(QString oneTimeCode, QString deviceIdentifier, QString deviceDescription, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_completeTwoFactorAuthentication_prepareParams(authenticationToken, oneTimeCode, deviceIdentifier, deviceDescription); - return new AsyncResult(m_url, params, UserStore_completeTwoFactorAuthentication_readReplyAsync); -} - -QByteArray UserStore_revokeLongSession_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("revokeLongSession"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_revokeLongSession_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -void UserStore_revokeLongSession_readReply(QByteArray reply) -{ - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("revokeLongSession")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); -} - -QVariant UserStore_revokeLongSession_readReplyAsync(QByteArray reply) -{ - UserStore_revokeLongSession_readReply(reply); - return QVariant(); -} - -void UserStore::revokeLongSession(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_revokeLongSession_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - UserStore_revokeLongSession_readReply(reply); -} - -AsyncResult* UserStore::revokeLongSessionAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_revokeLongSession_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, UserStore_revokeLongSession_readReplyAsync); -} - -QByteArray UserStore_authenticateToBusiness_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("authenticateToBusiness"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_authenticateToBusiness_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -AuthenticationResult UserStore_authenticateToBusiness_readReply(QByteArray reply) -{ - bool resultIsSet = false; - AuthenticationResult result = AuthenticationResult(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("authenticateToBusiness")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - AuthenticationResult v; - readAuthenticationResult(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("authenticateToBusiness: missing result")); - } - return result; -} - -QVariant UserStore_authenticateToBusiness_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(UserStore_authenticateToBusiness_readReply(reply)); -} - -AuthenticationResult UserStore::authenticateToBusiness(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_authenticateToBusiness_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return UserStore_authenticateToBusiness_readReply(reply); -} - -AsyncResult* UserStore::authenticateToBusinessAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_authenticateToBusiness_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, UserStore_authenticateToBusiness_readReplyAsync); -} - -QByteArray UserStore_getUser_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getUser"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_getUser_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -User UserStore_getUser_readReply(QByteArray reply) -{ - bool resultIsSet = false; - User result = User(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getUser")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - User v; - readUser(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getUser: missing result")); - } - return result; -} - -QVariant UserStore_getUser_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(UserStore_getUser_readReply(reply)); -} - -User UserStore::getUser(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_getUser_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return UserStore_getUser_readReply(reply); -} - -AsyncResult* UserStore::getUserAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_getUser_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, UserStore_getUser_readReplyAsync); -} - -QByteArray UserStore_getPublicUserInfo_prepareParams(QString username) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getPublicUserInfo"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_getPublicUserInfo_pargs")); - w.writeFieldBegin(QStringLiteral("username"), ThriftFieldType::T_STRING, 1); - w.writeString(username); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -PublicUserInfo UserStore_getPublicUserInfo_readReply(QByteArray reply) -{ - bool resultIsSet = false; - PublicUserInfo result = PublicUserInfo(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getPublicUserInfo")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - PublicUserInfo v; - readPublicUserInfo(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getPublicUserInfo: missing result")); - } - return result; -} - -QVariant UserStore_getPublicUserInfo_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(UserStore_getPublicUserInfo_readReply(reply)); -} - -PublicUserInfo UserStore::getPublicUserInfo(QString username) -{ - QByteArray params = UserStore_getPublicUserInfo_prepareParams(username); - QByteArray reply = askEvernote(m_url, params); - return UserStore_getPublicUserInfo_readReply(reply); -} - -AsyncResult* UserStore::getPublicUserInfoAsync(QString username) -{ - QByteArray params = UserStore_getPublicUserInfo_prepareParams(username); - return new AsyncResult(m_url, params, UserStore_getPublicUserInfo_readReplyAsync); -} - -QByteArray UserStore_getUserUrls_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getUserUrls"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_getUserUrls_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -UserUrls UserStore_getUserUrls_readReply(QByteArray reply) -{ - bool resultIsSet = false; - UserUrls result = UserUrls(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getUserUrls")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - UserUrls v; - readUserUrls(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getUserUrls: missing result")); - } - return result; -} - -QVariant UserStore_getUserUrls_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(UserStore_getUserUrls_readReply(reply)); -} - -UserUrls UserStore::getUserUrls(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_getUserUrls_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return UserStore_getUserUrls_readReply(reply); -} - -AsyncResult* UserStore::getUserUrlsAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_getUserUrls_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, UserStore_getUserUrls_readReplyAsync); -} - -QByteArray UserStore_inviteToBusiness_prepareParams(QString authenticationToken, QString emailAddress) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("inviteToBusiness"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_inviteToBusiness_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("emailAddress"), ThriftFieldType::T_STRING, 2); - w.writeString(emailAddress); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -void UserStore_inviteToBusiness_readReply(QByteArray reply) -{ - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("inviteToBusiness")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); -} - -QVariant UserStore_inviteToBusiness_readReplyAsync(QByteArray reply) -{ - UserStore_inviteToBusiness_readReply(reply); - return QVariant(); -} - -void UserStore::inviteToBusiness(QString emailAddress, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_inviteToBusiness_prepareParams(authenticationToken, emailAddress); - QByteArray reply = askEvernote(m_url, params); - UserStore_inviteToBusiness_readReply(reply); -} - -AsyncResult* UserStore::inviteToBusinessAsync(QString emailAddress, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_inviteToBusiness_prepareParams(authenticationToken, emailAddress); - return new AsyncResult(m_url, params, UserStore_inviteToBusiness_readReplyAsync); -} - -QByteArray UserStore_removeFromBusiness_prepareParams(QString authenticationToken, QString emailAddress) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("removeFromBusiness"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_removeFromBusiness_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("emailAddress"), ThriftFieldType::T_STRING, 2); - w.writeString(emailAddress); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -void UserStore_removeFromBusiness_readReply(QByteArray reply) -{ - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("removeFromBusiness")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); -} - -QVariant UserStore_removeFromBusiness_readReplyAsync(QByteArray reply) -{ - UserStore_removeFromBusiness_readReply(reply); - return QVariant(); -} - -void UserStore::removeFromBusiness(QString emailAddress, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_removeFromBusiness_prepareParams(authenticationToken, emailAddress); - QByteArray reply = askEvernote(m_url, params); - UserStore_removeFromBusiness_readReply(reply); -} - -AsyncResult* UserStore::removeFromBusinessAsync(QString emailAddress, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_removeFromBusiness_prepareParams(authenticationToken, emailAddress); - return new AsyncResult(m_url, params, UserStore_removeFromBusiness_readReplyAsync); -} - -QByteArray UserStore_updateBusinessUserIdentifier_prepareParams(QString authenticationToken, QString oldEmailAddress, QString newEmailAddress) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("updateBusinessUserIdentifier"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_updateBusinessUserIdentifier_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("oldEmailAddress"), ThriftFieldType::T_STRING, 2); - w.writeString(oldEmailAddress); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("newEmailAddress"), ThriftFieldType::T_STRING, 3); - w.writeString(newEmailAddress); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -void UserStore_updateBusinessUserIdentifier_readReply(QByteArray reply) -{ - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("updateBusinessUserIdentifier")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException e; - readEDAMNotFoundException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); -} - -QVariant UserStore_updateBusinessUserIdentifier_readReplyAsync(QByteArray reply) -{ - UserStore_updateBusinessUserIdentifier_readReply(reply); - return QVariant(); -} - -void UserStore::updateBusinessUserIdentifier(QString oldEmailAddress, QString newEmailAddress, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_updateBusinessUserIdentifier_prepareParams(authenticationToken, oldEmailAddress, newEmailAddress); - QByteArray reply = askEvernote(m_url, params); - UserStore_updateBusinessUserIdentifier_readReply(reply); -} - -AsyncResult* UserStore::updateBusinessUserIdentifierAsync(QString oldEmailAddress, QString newEmailAddress, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_updateBusinessUserIdentifier_prepareParams(authenticationToken, oldEmailAddress, newEmailAddress); - return new AsyncResult(m_url, params, UserStore_updateBusinessUserIdentifier_readReplyAsync); -} - -QByteArray UserStore_listBusinessUsers_prepareParams(QString authenticationToken) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("listBusinessUsers"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_listBusinessUsers_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QList< UserProfile > UserStore_listBusinessUsers_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QList< UserProfile > result = QList< UserProfile >(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("listBusinessUsers")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_LIST) { - resultIsSet = true; - QList< UserProfile > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (listBusinessUsers.result)")); - for(qint32 i = 0; i < size; i++) { - UserProfile elem; - readUserProfile(r, elem); - v.append(elem); - } - r.readListEnd(); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("listBusinessUsers: missing result")); - } - return result; -} - -QVariant UserStore_listBusinessUsers_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(UserStore_listBusinessUsers_readReply(reply)); -} - -QList< UserProfile > UserStore::listBusinessUsers(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_listBusinessUsers_prepareParams(authenticationToken); - QByteArray reply = askEvernote(m_url, params); - return UserStore_listBusinessUsers_readReply(reply); -} - -AsyncResult* UserStore::listBusinessUsersAsync(QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_listBusinessUsers_prepareParams(authenticationToken); - return new AsyncResult(m_url, params, UserStore_listBusinessUsers_readReplyAsync); -} - -QByteArray UserStore_listBusinessInvitations_prepareParams(QString authenticationToken, bool includeRequestedInvitations) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("listBusinessInvitations"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_listBusinessInvitations_pargs")); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 1); - w.writeString(authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("includeRequestedInvitations"), ThriftFieldType::T_BOOL, 2); - w.writeBool(includeRequestedInvitations); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -QList< BusinessInvitation > UserStore_listBusinessInvitations_readReply(QByteArray reply) -{ - bool resultIsSet = false; - QList< BusinessInvitation > result = QList< BusinessInvitation >(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("listBusinessInvitations")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_LIST) { - resultIsSet = true; - QList< BusinessInvitation > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (listBusinessInvitations.result)")); - for(qint32 i = 0; i < size; i++) { - BusinessInvitation elem; - readBusinessInvitation(r, elem); - v.append(elem); - } - r.readListEnd(); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMSystemException e; - readEDAMSystemException(r, e); - throwEDAMSystemException(e); - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("listBusinessInvitations: missing result")); - } - return result; -} - -QVariant UserStore_listBusinessInvitations_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(UserStore_listBusinessInvitations_readReply(reply)); -} - -QList< BusinessInvitation > UserStore::listBusinessInvitations(bool includeRequestedInvitations, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_listBusinessInvitations_prepareParams(authenticationToken, includeRequestedInvitations); - QByteArray reply = askEvernote(m_url, params); - return UserStore_listBusinessInvitations_readReply(reply); -} - -AsyncResult* UserStore::listBusinessInvitationsAsync(bool includeRequestedInvitations, QString authenticationToken) -{ - if (authenticationToken.isEmpty()) { - authenticationToken = m_authenticationToken; - } - QByteArray params = UserStore_listBusinessInvitations_prepareParams(authenticationToken, includeRequestedInvitations); - return new AsyncResult(m_url, params, UserStore_listBusinessInvitations_readReplyAsync); -} - -QByteArray UserStore_getAccountLimits_prepareParams(ServiceLevel::type serviceLevel) -{ - ThriftBinaryBufferWriter w; - qint32 cseqid = 0; - w.writeMessageBegin(QStringLiteral("getAccountLimits"), ThriftMessageType::T_CALL, cseqid); - w.writeStructBegin(QStringLiteral("UserStore_getAccountLimits_pargs")); - w.writeFieldBegin(QStringLiteral("serviceLevel"), ThriftFieldType::T_I32, 1); - w.writeI32(static_cast(serviceLevel)); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); - w.writeMessageEnd(); - return w.buffer(); -} - -AccountLimits UserStore_getAccountLimits_readReply(QByteArray reply) -{ - bool resultIsSet = false; - AccountLimits result = AccountLimits(); - ThriftBinaryBufferReader r(reply); - qint32 rseqid = 0; - QString fname; - ThriftMessageType::type mtype; - r.readMessageBegin(fname, mtype, rseqid); - if (mtype == ThriftMessageType::T_EXCEPTION) { - ThriftException e = readThriftException(r); - r.readMessageEnd(); - throw e; - } - if (mtype != ThriftMessageType::T_REPLY) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::INVALID_MESSAGE_TYPE); - } - if (fname.compare(QStringLiteral("getAccountLimits")) != 0) { - r.skip(ThriftFieldType::T_STRUCT); - r.readMessageEnd(); - throw ThriftException(ThriftException::Type::WRONG_METHOD_NAME); - } - - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) { - r.readFieldBegin(fname, fieldType, fieldId); - if(fieldType == ThriftFieldType::T_STOP) break; - if(fieldId == 0) { - if(fieldType == ThriftFieldType::T_STRUCT) { - resultIsSet = true; - AccountLimits v; - readAccountLimits(r, v); - result = v; - } else { - r.skip(fieldType); - } - } - else if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException e; - readEDAMUserException(r, e); - throw e; - } - else { - r.skip(fieldType); - } - } - else { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - r.readMessageEnd(); - if (!resultIsSet) { - throw ThriftException(ThriftException::Type::MISSING_RESULT, QStringLiteral("getAccountLimits: missing result")); - } - return result; -} - -QVariant UserStore_getAccountLimits_readReplyAsync(QByteArray reply) -{ - return QVariant::fromValue(UserStore_getAccountLimits_readReply(reply)); -} - -AccountLimits UserStore::getAccountLimits(ServiceLevel::type serviceLevel) -{ - QByteArray params = UserStore_getAccountLimits_prepareParams(serviceLevel); - QByteArray reply = askEvernote(m_url, params); - return UserStore_getAccountLimits_readReply(reply); -} - -AsyncResult* UserStore::getAccountLimitsAsync(ServiceLevel::type serviceLevel) -{ - QByteArray params = UserStore_getAccountLimits_prepareParams(serviceLevel); - return new AsyncResult(m_url, params, UserStore_getAccountLimits_readReplyAsync); -} - - -} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/generated/types.cpp b/src/qevercloud/QEverCloud/src/generated/types.cpp deleted file mode 100644 index e0832058..00000000 --- a/src/qevercloud/QEverCloud/src/generated/types.cpp +++ /dev/null @@ -1,11330 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - * - * This file was generated from Evernote Thrift API - */ - - -#include -#include "../impl.h" -#include "../impl.h" -#include "types_impl.h" -#include - -namespace qevercloud { -/** @cond HIDDEN_SYMBOLS */ - -void readEnumEDAMErrorCode(ThriftBinaryBufferReader & r, EDAMErrorCode::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(EDAMErrorCode::UNKNOWN): e = EDAMErrorCode::UNKNOWN; break; - case static_cast(EDAMErrorCode::BAD_DATA_FORMAT): e = EDAMErrorCode::BAD_DATA_FORMAT; break; - case static_cast(EDAMErrorCode::PERMISSION_DENIED): e = EDAMErrorCode::PERMISSION_DENIED; break; - case static_cast(EDAMErrorCode::INTERNAL_ERROR): e = EDAMErrorCode::INTERNAL_ERROR; break; - case static_cast(EDAMErrorCode::DATA_REQUIRED): e = EDAMErrorCode::DATA_REQUIRED; break; - case static_cast(EDAMErrorCode::LIMIT_REACHED): e = EDAMErrorCode::LIMIT_REACHED; break; - case static_cast(EDAMErrorCode::QUOTA_REACHED): e = EDAMErrorCode::QUOTA_REACHED; break; - case static_cast(EDAMErrorCode::INVALID_AUTH): e = EDAMErrorCode::INVALID_AUTH; break; - case static_cast(EDAMErrorCode::AUTH_EXPIRED): e = EDAMErrorCode::AUTH_EXPIRED; break; - case static_cast(EDAMErrorCode::DATA_CONFLICT): e = EDAMErrorCode::DATA_CONFLICT; break; - case static_cast(EDAMErrorCode::ENML_VALIDATION): e = EDAMErrorCode::ENML_VALIDATION; break; - case static_cast(EDAMErrorCode::SHARD_UNAVAILABLE): e = EDAMErrorCode::SHARD_UNAVAILABLE; break; - case static_cast(EDAMErrorCode::LEN_TOO_SHORT): e = EDAMErrorCode::LEN_TOO_SHORT; break; - case static_cast(EDAMErrorCode::LEN_TOO_LONG): e = EDAMErrorCode::LEN_TOO_LONG; break; - case static_cast(EDAMErrorCode::TOO_FEW): e = EDAMErrorCode::TOO_FEW; break; - case static_cast(EDAMErrorCode::TOO_MANY): e = EDAMErrorCode::TOO_MANY; break; - case static_cast(EDAMErrorCode::UNSUPPORTED_OPERATION): e = EDAMErrorCode::UNSUPPORTED_OPERATION; break; - case static_cast(EDAMErrorCode::TAKEN_DOWN): e = EDAMErrorCode::TAKEN_DOWN; break; - case static_cast(EDAMErrorCode::RATE_LIMIT_REACHED): e = EDAMErrorCode::RATE_LIMIT_REACHED; break; - case static_cast(EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED): e = EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED; break; - case static_cast(EDAMErrorCode::DEVICE_LIMIT_REACHED): e = EDAMErrorCode::DEVICE_LIMIT_REACHED; break; - case static_cast(EDAMErrorCode::OPENID_ALREADY_TAKEN): e = EDAMErrorCode::OPENID_ALREADY_TAKEN; break; - case static_cast(EDAMErrorCode::INVALID_OPENID_TOKEN): e = EDAMErrorCode::INVALID_OPENID_TOKEN; break; - case static_cast(EDAMErrorCode::USER_NOT_ASSOCIATED): e = EDAMErrorCode::USER_NOT_ASSOCIATED; break; - case static_cast(EDAMErrorCode::USER_NOT_REGISTERED): e = EDAMErrorCode::USER_NOT_REGISTERED; break; - case static_cast(EDAMErrorCode::USER_ALREADY_ASSOCIATED): e = EDAMErrorCode::USER_ALREADY_ASSOCIATED; break; - case static_cast(EDAMErrorCode::ACCOUNT_CLEAR): e = EDAMErrorCode::ACCOUNT_CLEAR; break; - case static_cast(EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED): e = EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum EDAMErrorCode")); - } -} - -void readEnumEDAMInvalidContactReason(ThriftBinaryBufferReader & r, EDAMInvalidContactReason::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(EDAMInvalidContactReason::BAD_ADDRESS): e = EDAMInvalidContactReason::BAD_ADDRESS; break; - case static_cast(EDAMInvalidContactReason::DUPLICATE_CONTACT): e = EDAMInvalidContactReason::DUPLICATE_CONTACT; break; - case static_cast(EDAMInvalidContactReason::NO_CONNECTION): e = EDAMInvalidContactReason::NO_CONNECTION; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum EDAMInvalidContactReason")); - } -} - -void readEnumShareRelationshipPrivilegeLevel(ThriftBinaryBufferReader & r, ShareRelationshipPrivilegeLevel::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(ShareRelationshipPrivilegeLevel::READ_NOTEBOOK): e = ShareRelationshipPrivilegeLevel::READ_NOTEBOOK; break; - case static_cast(ShareRelationshipPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY): e = ShareRelationshipPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY; break; - case static_cast(ShareRelationshipPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY): e = ShareRelationshipPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY; break; - case static_cast(ShareRelationshipPrivilegeLevel::FULL_ACCESS): e = ShareRelationshipPrivilegeLevel::FULL_ACCESS; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum ShareRelationshipPrivilegeLevel")); - } -} - -void readEnumPrivilegeLevel(ThriftBinaryBufferReader & r, PrivilegeLevel::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(PrivilegeLevel::NORMAL): e = PrivilegeLevel::NORMAL; break; - case static_cast(PrivilegeLevel::PREMIUM): e = PrivilegeLevel::PREMIUM; break; - case static_cast(PrivilegeLevel::VIP): e = PrivilegeLevel::VIP; break; - case static_cast(PrivilegeLevel::MANAGER): e = PrivilegeLevel::MANAGER; break; - case static_cast(PrivilegeLevel::SUPPORT): e = PrivilegeLevel::SUPPORT; break; - case static_cast(PrivilegeLevel::ADMIN): e = PrivilegeLevel::ADMIN; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum PrivilegeLevel")); - } -} - -void readEnumServiceLevel(ThriftBinaryBufferReader & r, ServiceLevel::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(ServiceLevel::BASIC): e = ServiceLevel::BASIC; break; - case static_cast(ServiceLevel::PLUS): e = ServiceLevel::PLUS; break; - case static_cast(ServiceLevel::PREMIUM): e = ServiceLevel::PREMIUM; break; - case static_cast(ServiceLevel::BUSINESS): e = ServiceLevel::BUSINESS; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum ServiceLevel")); - } -} - -void readEnumQueryFormat(ThriftBinaryBufferReader & r, QueryFormat::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(QueryFormat::USER): e = QueryFormat::USER; break; - case static_cast(QueryFormat::SEXP): e = QueryFormat::SEXP; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum QueryFormat")); - } -} - -void readEnumNoteSortOrder(ThriftBinaryBufferReader & r, NoteSortOrder::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(NoteSortOrder::CREATED): e = NoteSortOrder::CREATED; break; - case static_cast(NoteSortOrder::UPDATED): e = NoteSortOrder::UPDATED; break; - case static_cast(NoteSortOrder::RELEVANCE): e = NoteSortOrder::RELEVANCE; break; - case static_cast(NoteSortOrder::UPDATE_SEQUENCE_NUMBER): e = NoteSortOrder::UPDATE_SEQUENCE_NUMBER; break; - case static_cast(NoteSortOrder::TITLE): e = NoteSortOrder::TITLE; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum NoteSortOrder")); - } -} - -void readEnumPremiumOrderStatus(ThriftBinaryBufferReader & r, PremiumOrderStatus::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(PremiumOrderStatus::NONE): e = PremiumOrderStatus::NONE; break; - case static_cast(PremiumOrderStatus::PENDING): e = PremiumOrderStatus::PENDING; break; - case static_cast(PremiumOrderStatus::ACTIVE): e = PremiumOrderStatus::ACTIVE; break; - case static_cast(PremiumOrderStatus::FAILED): e = PremiumOrderStatus::FAILED; break; - case static_cast(PremiumOrderStatus::CANCELLATION_PENDING): e = PremiumOrderStatus::CANCELLATION_PENDING; break; - case static_cast(PremiumOrderStatus::CANCELED): e = PremiumOrderStatus::CANCELED; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum PremiumOrderStatus")); - } -} - -void readEnumSharedNotebookPrivilegeLevel(ThriftBinaryBufferReader & r, SharedNotebookPrivilegeLevel::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(SharedNotebookPrivilegeLevel::READ_NOTEBOOK): e = SharedNotebookPrivilegeLevel::READ_NOTEBOOK; break; - case static_cast(SharedNotebookPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY): e = SharedNotebookPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY; break; - case static_cast(SharedNotebookPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY): e = SharedNotebookPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY; break; - case static_cast(SharedNotebookPrivilegeLevel::GROUP): e = SharedNotebookPrivilegeLevel::GROUP; break; - case static_cast(SharedNotebookPrivilegeLevel::FULL_ACCESS): e = SharedNotebookPrivilegeLevel::FULL_ACCESS; break; - case static_cast(SharedNotebookPrivilegeLevel::BUSINESS_FULL_ACCESS): e = SharedNotebookPrivilegeLevel::BUSINESS_FULL_ACCESS; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum SharedNotebookPrivilegeLevel")); - } -} - -void readEnumSharedNotePrivilegeLevel(ThriftBinaryBufferReader & r, SharedNotePrivilegeLevel::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(SharedNotePrivilegeLevel::READ_NOTE): e = SharedNotePrivilegeLevel::READ_NOTE; break; - case static_cast(SharedNotePrivilegeLevel::MODIFY_NOTE): e = SharedNotePrivilegeLevel::MODIFY_NOTE; break; - case static_cast(SharedNotePrivilegeLevel::FULL_ACCESS): e = SharedNotePrivilegeLevel::FULL_ACCESS; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum SharedNotePrivilegeLevel")); - } -} - -void readEnumSponsoredGroupRole(ThriftBinaryBufferReader & r, SponsoredGroupRole::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(SponsoredGroupRole::GROUP_MEMBER): e = SponsoredGroupRole::GROUP_MEMBER; break; - case static_cast(SponsoredGroupRole::GROUP_ADMIN): e = SponsoredGroupRole::GROUP_ADMIN; break; - case static_cast(SponsoredGroupRole::GROUP_OWNER): e = SponsoredGroupRole::GROUP_OWNER; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum SponsoredGroupRole")); - } -} - -void readEnumBusinessUserRole(ThriftBinaryBufferReader & r, BusinessUserRole::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(BusinessUserRole::ADMIN): e = BusinessUserRole::ADMIN; break; - case static_cast(BusinessUserRole::NORMAL): e = BusinessUserRole::NORMAL; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum BusinessUserRole")); - } -} - -void readEnumBusinessUserStatus(ThriftBinaryBufferReader & r, BusinessUserStatus::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(BusinessUserStatus::ACTIVE): e = BusinessUserStatus::ACTIVE; break; - case static_cast(BusinessUserStatus::DEACTIVATED): e = BusinessUserStatus::DEACTIVATED; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum BusinessUserStatus")); - } -} - -void readEnumSharedNotebookInstanceRestrictions(ThriftBinaryBufferReader & r, SharedNotebookInstanceRestrictions::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(SharedNotebookInstanceRestrictions::ASSIGNED): e = SharedNotebookInstanceRestrictions::ASSIGNED; break; - case static_cast(SharedNotebookInstanceRestrictions::NO_SHARED_NOTEBOOKS): e = SharedNotebookInstanceRestrictions::NO_SHARED_NOTEBOOKS; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum SharedNotebookInstanceRestrictions")); - } -} - -void readEnumReminderEmailConfig(ThriftBinaryBufferReader & r, ReminderEmailConfig::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(ReminderEmailConfig::DO_NOT_SEND): e = ReminderEmailConfig::DO_NOT_SEND; break; - case static_cast(ReminderEmailConfig::SEND_DAILY_EMAIL): e = ReminderEmailConfig::SEND_DAILY_EMAIL; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum ReminderEmailConfig")); - } -} - -void readEnumBusinessInvitationStatus(ThriftBinaryBufferReader & r, BusinessInvitationStatus::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(BusinessInvitationStatus::APPROVED): e = BusinessInvitationStatus::APPROVED; break; - case static_cast(BusinessInvitationStatus::REQUESTED): e = BusinessInvitationStatus::REQUESTED; break; - case static_cast(BusinessInvitationStatus::REDEEMED): e = BusinessInvitationStatus::REDEEMED; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum BusinessInvitationStatus")); - } -} - -void readEnumContactType(ThriftBinaryBufferReader & r, ContactType::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(ContactType::EVERNOTE): e = ContactType::EVERNOTE; break; - case static_cast(ContactType::SMS): e = ContactType::SMS; break; - case static_cast(ContactType::FACEBOOK): e = ContactType::FACEBOOK; break; - case static_cast(ContactType::EMAIL): e = ContactType::EMAIL; break; - case static_cast(ContactType::TWITTER): e = ContactType::TWITTER; break; - case static_cast(ContactType::LINKEDIN): e = ContactType::LINKEDIN; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum ContactType")); - } -} - -void readEnumEntityType(ThriftBinaryBufferReader & r, EntityType::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(EntityType::NOTE): e = EntityType::NOTE; break; - case static_cast(EntityType::NOTEBOOK): e = EntityType::NOTEBOOK; break; - case static_cast(EntityType::WORKSPACE): e = EntityType::WORKSPACE; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum EntityType")); - } -} - -void readEnumRecipientStatus(ThriftBinaryBufferReader & r, RecipientStatus::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(RecipientStatus::NOT_IN_MY_LIST): e = RecipientStatus::NOT_IN_MY_LIST; break; - case static_cast(RecipientStatus::IN_MY_LIST): e = RecipientStatus::IN_MY_LIST; break; - case static_cast(RecipientStatus::IN_MY_LIST_AND_DEFAULT_NOTEBOOK): e = RecipientStatus::IN_MY_LIST_AND_DEFAULT_NOTEBOOK; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum RecipientStatus")); - } -} - -void readEnumCanMoveToContainerStatus(ThriftBinaryBufferReader & r, CanMoveToContainerStatus::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(CanMoveToContainerStatus::CAN_BE_MOVED): e = CanMoveToContainerStatus::CAN_BE_MOVED; break; - case static_cast(CanMoveToContainerStatus::INSUFFICIENT_ENTITY_PRIVILEGE): e = CanMoveToContainerStatus::INSUFFICIENT_ENTITY_PRIVILEGE; break; - case static_cast(CanMoveToContainerStatus::INSUFFICIENT_CONTAINER_PRIVILEGE): e = CanMoveToContainerStatus::INSUFFICIENT_CONTAINER_PRIVILEGE; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum CanMoveToContainerStatus")); - } -} - -void readEnumRelatedContentType(ThriftBinaryBufferReader & r, RelatedContentType::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(RelatedContentType::NEWS_ARTICLE): e = RelatedContentType::NEWS_ARTICLE; break; - case static_cast(RelatedContentType::PROFILE_PERSON): e = RelatedContentType::PROFILE_PERSON; break; - case static_cast(RelatedContentType::PROFILE_ORGANIZATION): e = RelatedContentType::PROFILE_ORGANIZATION; break; - case static_cast(RelatedContentType::REFERENCE_MATERIAL): e = RelatedContentType::REFERENCE_MATERIAL; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum RelatedContentType")); - } -} - -void readEnumRelatedContentAccess(ThriftBinaryBufferReader & r, RelatedContentAccess::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(RelatedContentAccess::NOT_ACCESSIBLE): e = RelatedContentAccess::NOT_ACCESSIBLE; break; - case static_cast(RelatedContentAccess::DIRECT_LINK_ACCESS_OK): e = RelatedContentAccess::DIRECT_LINK_ACCESS_OK; break; - case static_cast(RelatedContentAccess::DIRECT_LINK_LOGIN_REQUIRED): e = RelatedContentAccess::DIRECT_LINK_LOGIN_REQUIRED; break; - case static_cast(RelatedContentAccess::DIRECT_LINK_EMBEDDED_VIEW): e = RelatedContentAccess::DIRECT_LINK_EMBEDDED_VIEW; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum RelatedContentAccess")); - } -} - -void readEnumUserIdentityType(ThriftBinaryBufferReader & r, UserIdentityType::type & e) { - qint32 i; - r.readI32(i); - switch(i) { - case static_cast(UserIdentityType::EVERNOTE_USERID): e = UserIdentityType::EVERNOTE_USERID; break; - case static_cast(UserIdentityType::EMAIL): e = UserIdentityType::EMAIL; break; - case static_cast(UserIdentityType::IDENTITYID): e = UserIdentityType::IDENTITYID; break; - default: throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect value for enum UserIdentityType")); - } -} - -void writeSyncState(ThriftBinaryBufferWriter & w, const SyncState & s) { - w.writeStructBegin(QStringLiteral("SyncState")); - w.writeFieldBegin(QStringLiteral("currentTime"), ThriftFieldType::T_I64, 1); - w.writeI64(s.currentTime); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("fullSyncBefore"), ThriftFieldType::T_I64, 2); - w.writeI64(s.fullSyncBefore); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("updateCount"), ThriftFieldType::T_I32, 3); - w.writeI32(s.updateCount); - w.writeFieldEnd(); - if(s.uploaded.isSet()) { - w.writeFieldBegin(QStringLiteral("uploaded"), ThriftFieldType::T_I64, 4); - w.writeI64(s.uploaded.ref()); - w.writeFieldEnd(); - } - if(s.userLastUpdated.isSet()) { - w.writeFieldBegin(QStringLiteral("userLastUpdated"), ThriftFieldType::T_I64, 5); - w.writeI64(s.userLastUpdated.ref()); - w.writeFieldEnd(); - } - if(s.userMaxMessageEventId.isSet()) { - w.writeFieldBegin(QStringLiteral("userMaxMessageEventId"), ThriftFieldType::T_I64, 6); - w.writeI64(s.userMaxMessageEventId.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readSyncState(ThriftBinaryBufferReader & r, SyncState & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool currentTime_isset = false; - bool fullSyncBefore_isset = false; - bool updateCount_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I64) { - currentTime_isset = true; - qint64 v; - r.readI64(v); - s.currentTime = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I64) { - fullSyncBefore_isset = true; - qint64 v; - r.readI64(v); - s.fullSyncBefore = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - updateCount_isset = true; - qint32 v; - r.readI32(v); - s.updateCount = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.uploaded = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.userLastUpdated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_I64) { - MessageEventID v; - r.readI64(v); - s.userMaxMessageEventId = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!currentTime_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("SyncState.currentTime has no value")); - if(!fullSyncBefore_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("SyncState.fullSyncBefore has no value")); - if(!updateCount_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("SyncState.updateCount has no value")); -} - -void writeSyncChunk(ThriftBinaryBufferWriter & w, const SyncChunk & s) { - w.writeStructBegin(QStringLiteral("SyncChunk")); - w.writeFieldBegin(QStringLiteral("currentTime"), ThriftFieldType::T_I64, 1); - w.writeI64(s.currentTime); - w.writeFieldEnd(); - if(s.chunkHighUSN.isSet()) { - w.writeFieldBegin(QStringLiteral("chunkHighUSN"), ThriftFieldType::T_I32, 2); - w.writeI32(s.chunkHighUSN.ref()); - w.writeFieldEnd(); - } - w.writeFieldBegin(QStringLiteral("updateCount"), ThriftFieldType::T_I32, 3); - w.writeI32(s.updateCount); - w.writeFieldEnd(); - if(s.notes.isSet()) { - w.writeFieldBegin(QStringLiteral("notes"), ThriftFieldType::T_LIST, 4); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.notes.ref().length()); - for(QList< Note >::const_iterator it = s.notes.ref().constBegin(), end = s.notes.ref().constEnd(); it != end; ++it) { - writeNote(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.notebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("notebooks"), ThriftFieldType::T_LIST, 5); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.notebooks.ref().length()); - for(QList< Notebook >::const_iterator it = s.notebooks.ref().constBegin(), end = s.notebooks.ref().constEnd(); it != end; ++it) { - writeNotebook(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.tags.isSet()) { - w.writeFieldBegin(QStringLiteral("tags"), ThriftFieldType::T_LIST, 6); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.tags.ref().length()); - for(QList< Tag >::const_iterator it = s.tags.ref().constBegin(), end = s.tags.ref().constEnd(); it != end; ++it) { - writeTag(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.searches.isSet()) { - w.writeFieldBegin(QStringLiteral("searches"), ThriftFieldType::T_LIST, 7); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.searches.ref().length()); - for(QList< SavedSearch >::const_iterator it = s.searches.ref().constBegin(), end = s.searches.ref().constEnd(); it != end; ++it) { - writeSavedSearch(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.resources.isSet()) { - w.writeFieldBegin(QStringLiteral("resources"), ThriftFieldType::T_LIST, 8); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.resources.ref().length()); - for(QList< Resource >::const_iterator it = s.resources.ref().constBegin(), end = s.resources.ref().constEnd(); it != end; ++it) { - writeResource(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.expungedNotes.isSet()) { - w.writeFieldBegin(QStringLiteral("expungedNotes"), ThriftFieldType::T_LIST, 9); - w.writeListBegin(ThriftFieldType::T_STRING, s.expungedNotes.ref().length()); - for(QList< Guid >::const_iterator it = s.expungedNotes.ref().constBegin(), end = s.expungedNotes.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.expungedNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("expungedNotebooks"), ThriftFieldType::T_LIST, 10); - w.writeListBegin(ThriftFieldType::T_STRING, s.expungedNotebooks.ref().length()); - for(QList< Guid >::const_iterator it = s.expungedNotebooks.ref().constBegin(), end = s.expungedNotebooks.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.expungedTags.isSet()) { - w.writeFieldBegin(QStringLiteral("expungedTags"), ThriftFieldType::T_LIST, 11); - w.writeListBegin(ThriftFieldType::T_STRING, s.expungedTags.ref().length()); - for(QList< Guid >::const_iterator it = s.expungedTags.ref().constBegin(), end = s.expungedTags.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.expungedSearches.isSet()) { - w.writeFieldBegin(QStringLiteral("expungedSearches"), ThriftFieldType::T_LIST, 12); - w.writeListBegin(ThriftFieldType::T_STRING, s.expungedSearches.ref().length()); - for(QList< Guid >::const_iterator it = s.expungedSearches.ref().constBegin(), end = s.expungedSearches.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.linkedNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("linkedNotebooks"), ThriftFieldType::T_LIST, 13); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.linkedNotebooks.ref().length()); - for(QList< LinkedNotebook >::const_iterator it = s.linkedNotebooks.ref().constBegin(), end = s.linkedNotebooks.ref().constEnd(); it != end; ++it) { - writeLinkedNotebook(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.expungedLinkedNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("expungedLinkedNotebooks"), ThriftFieldType::T_LIST, 14); - w.writeListBegin(ThriftFieldType::T_STRING, s.expungedLinkedNotebooks.ref().length()); - for(QList< Guid >::const_iterator it = s.expungedLinkedNotebooks.ref().constBegin(), end = s.expungedLinkedNotebooks.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readSyncChunk(ThriftBinaryBufferReader & r, SyncChunk & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool currentTime_isset = false; - bool updateCount_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I64) { - currentTime_isset = true; - qint64 v; - r.readI64(v); - s.currentTime = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.chunkHighUSN = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - updateCount_isset = true; - qint32 v; - r.readI32(v); - s.updateCount = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Note > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (SyncChunk.notes)")); - for(qint32 i = 0; i < size; i++) { - Note elem; - readNote(r, elem); - v.append(elem); - } - r.readListEnd(); - s.notes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Notebook > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (SyncChunk.notebooks)")); - for(qint32 i = 0; i < size; i++) { - Notebook elem; - readNotebook(r, elem); - v.append(elem); - } - r.readListEnd(); - s.notebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Tag > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (SyncChunk.tags)")); - for(qint32 i = 0; i < size; i++) { - Tag elem; - readTag(r, elem); - v.append(elem); - } - r.readListEnd(); - s.tags = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< SavedSearch > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (SyncChunk.searches)")); - for(qint32 i = 0; i < size; i++) { - SavedSearch elem; - readSavedSearch(r, elem); - v.append(elem); - } - r.readListEnd(); - s.searches = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Resource > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (SyncChunk.resources)")); - for(qint32 i = 0; i < size; i++) { - Resource elem; - readResource(r, elem); - v.append(elem); - } - r.readListEnd(); - s.resources = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Guid > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (SyncChunk.expungedNotes)")); - for(qint32 i = 0; i < size; i++) { - Guid elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.expungedNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Guid > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (SyncChunk.expungedNotebooks)")); - for(qint32 i = 0; i < size; i++) { - Guid elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.expungedNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Guid > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (SyncChunk.expungedTags)")); - for(qint32 i = 0; i < size; i++) { - Guid elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.expungedTags = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Guid > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (SyncChunk.expungedSearches)")); - for(qint32 i = 0; i < size; i++) { - Guid elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.expungedSearches = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< LinkedNotebook > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (SyncChunk.linkedNotebooks)")); - for(qint32 i = 0; i < size; i++) { - LinkedNotebook elem; - readLinkedNotebook(r, elem); - v.append(elem); - } - r.readListEnd(); - s.linkedNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 14) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Guid > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (SyncChunk.expungedLinkedNotebooks)")); - for(qint32 i = 0; i < size; i++) { - Guid elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.expungedLinkedNotebooks = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!currentTime_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("SyncChunk.currentTime has no value")); - if(!updateCount_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("SyncChunk.updateCount has no value")); -} - -void writeSyncChunkFilter(ThriftBinaryBufferWriter & w, const SyncChunkFilter & s) { - w.writeStructBegin(QStringLiteral("SyncChunkFilter")); - if(s.includeNotes.isSet()) { - w.writeFieldBegin(QStringLiteral("includeNotes"), ThriftFieldType::T_BOOL, 1); - w.writeBool(s.includeNotes.ref()); - w.writeFieldEnd(); - } - if(s.includeNoteResources.isSet()) { - w.writeFieldBegin(QStringLiteral("includeNoteResources"), ThriftFieldType::T_BOOL, 2); - w.writeBool(s.includeNoteResources.ref()); - w.writeFieldEnd(); - } - if(s.includeNoteAttributes.isSet()) { - w.writeFieldBegin(QStringLiteral("includeNoteAttributes"), ThriftFieldType::T_BOOL, 3); - w.writeBool(s.includeNoteAttributes.ref()); - w.writeFieldEnd(); - } - if(s.includeNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("includeNotebooks"), ThriftFieldType::T_BOOL, 4); - w.writeBool(s.includeNotebooks.ref()); - w.writeFieldEnd(); - } - if(s.includeTags.isSet()) { - w.writeFieldBegin(QStringLiteral("includeTags"), ThriftFieldType::T_BOOL, 5); - w.writeBool(s.includeTags.ref()); - w.writeFieldEnd(); - } - if(s.includeSearches.isSet()) { - w.writeFieldBegin(QStringLiteral("includeSearches"), ThriftFieldType::T_BOOL, 6); - w.writeBool(s.includeSearches.ref()); - w.writeFieldEnd(); - } - if(s.includeResources.isSet()) { - w.writeFieldBegin(QStringLiteral("includeResources"), ThriftFieldType::T_BOOL, 7); - w.writeBool(s.includeResources.ref()); - w.writeFieldEnd(); - } - if(s.includeLinkedNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("includeLinkedNotebooks"), ThriftFieldType::T_BOOL, 8); - w.writeBool(s.includeLinkedNotebooks.ref()); - w.writeFieldEnd(); - } - if(s.includeExpunged.isSet()) { - w.writeFieldBegin(QStringLiteral("includeExpunged"), ThriftFieldType::T_BOOL, 9); - w.writeBool(s.includeExpunged.ref()); - w.writeFieldEnd(); - } - if(s.includeNoteApplicationDataFullMap.isSet()) { - w.writeFieldBegin(QStringLiteral("includeNoteApplicationDataFullMap"), ThriftFieldType::T_BOOL, 10); - w.writeBool(s.includeNoteApplicationDataFullMap.ref()); - w.writeFieldEnd(); - } - if(s.includeResourceApplicationDataFullMap.isSet()) { - w.writeFieldBegin(QStringLiteral("includeResourceApplicationDataFullMap"), ThriftFieldType::T_BOOL, 12); - w.writeBool(s.includeResourceApplicationDataFullMap.ref()); - w.writeFieldEnd(); - } - if(s.includeNoteResourceApplicationDataFullMap.isSet()) { - w.writeFieldBegin(QStringLiteral("includeNoteResourceApplicationDataFullMap"), ThriftFieldType::T_BOOL, 13); - w.writeBool(s.includeNoteResourceApplicationDataFullMap.ref()); - w.writeFieldEnd(); - } - if(s.includeSharedNotes.isSet()) { - w.writeFieldBegin(QStringLiteral("includeSharedNotes"), ThriftFieldType::T_BOOL, 17); - w.writeBool(s.includeSharedNotes.ref()); - w.writeFieldEnd(); - } - if(s.omitSharedNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("omitSharedNotebooks"), ThriftFieldType::T_BOOL, 16); - w.writeBool(s.omitSharedNotebooks.ref()); - w.writeFieldEnd(); - } - if(s.requireNoteContentClass.isSet()) { - w.writeFieldBegin(QStringLiteral("requireNoteContentClass"), ThriftFieldType::T_STRING, 11); - w.writeString(s.requireNoteContentClass.ref()); - w.writeFieldEnd(); - } - if(s.notebookGuids.isSet()) { - w.writeFieldBegin(QStringLiteral("notebookGuids"), ThriftFieldType::T_SET, 15); - w.writeSetBegin(ThriftFieldType::T_STRING, s.notebookGuids.ref().count()); - for(QSet< QString >::const_iterator it = s.notebookGuids.ref().constBegin(), end = s.notebookGuids.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeSetEnd(); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readSyncChunkFilter(ThriftBinaryBufferReader & r, SyncChunkFilter & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeNoteResources = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeNoteAttributes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeTags = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeSearches = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeResources = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeLinkedNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeExpunged = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeNoteApplicationDataFullMap = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeResourceApplicationDataFullMap = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeNoteResourceApplicationDataFullMap = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 17) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeSharedNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 16) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.omitSharedNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.requireNoteContentClass = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 15) { - if (fieldType == ThriftFieldType::T_SET) { - QSet< QString > v; - qint32 size; - ThriftFieldType::type elemType; - r.readSetBegin(elemType, size); - v.reserve(size); - if (elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect set type (SyncChunkFilter.notebookGuids)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.insert(elem); - } - r.readSetEnd(); - s.notebookGuids = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteFilter(ThriftBinaryBufferWriter & w, const NoteFilter & s) { - w.writeStructBegin(QStringLiteral("NoteFilter")); - if(s.order.isSet()) { - w.writeFieldBegin(QStringLiteral("order"), ThriftFieldType::T_I32, 1); - w.writeI32(s.order.ref()); - w.writeFieldEnd(); - } - if(s.ascending.isSet()) { - w.writeFieldBegin(QStringLiteral("ascending"), ThriftFieldType::T_BOOL, 2); - w.writeBool(s.ascending.ref()); - w.writeFieldEnd(); - } - if(s.words.isSet()) { - w.writeFieldBegin(QStringLiteral("words"), ThriftFieldType::T_STRING, 3); - w.writeString(s.words.ref()); - w.writeFieldEnd(); - } - if(s.notebookGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("notebookGuid"), ThriftFieldType::T_STRING, 4); - w.writeString(s.notebookGuid.ref()); - w.writeFieldEnd(); - } - if(s.tagGuids.isSet()) { - w.writeFieldBegin(QStringLiteral("tagGuids"), ThriftFieldType::T_LIST, 5); - w.writeListBegin(ThriftFieldType::T_STRING, s.tagGuids.ref().length()); - for(QList< Guid >::const_iterator it = s.tagGuids.ref().constBegin(), end = s.tagGuids.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.timeZone.isSet()) { - w.writeFieldBegin(QStringLiteral("timeZone"), ThriftFieldType::T_STRING, 6); - w.writeString(s.timeZone.ref()); - w.writeFieldEnd(); - } - if(s.inactive.isSet()) { - w.writeFieldBegin(QStringLiteral("inactive"), ThriftFieldType::T_BOOL, 7); - w.writeBool(s.inactive.ref()); - w.writeFieldEnd(); - } - if(s.emphasized.isSet()) { - w.writeFieldBegin(QStringLiteral("emphasized"), ThriftFieldType::T_STRING, 8); - w.writeString(s.emphasized.ref()); - w.writeFieldEnd(); - } - if(s.includeAllReadableNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("includeAllReadableNotebooks"), ThriftFieldType::T_BOOL, 9); - w.writeBool(s.includeAllReadableNotebooks.ref()); - w.writeFieldEnd(); - } - if(s.includeAllReadableWorkspaces.isSet()) { - w.writeFieldBegin(QStringLiteral("includeAllReadableWorkspaces"), ThriftFieldType::T_BOOL, 15); - w.writeBool(s.includeAllReadableWorkspaces.ref()); - w.writeFieldEnd(); - } - if(s.context.isSet()) { - w.writeFieldBegin(QStringLiteral("context"), ThriftFieldType::T_STRING, 10); - w.writeString(s.context.ref()); - w.writeFieldEnd(); - } - if(s.rawWords.isSet()) { - w.writeFieldBegin(QStringLiteral("rawWords"), ThriftFieldType::T_STRING, 11); - w.writeString(s.rawWords.ref()); - w.writeFieldEnd(); - } - if(s.searchContextBytes.isSet()) { - w.writeFieldBegin(QStringLiteral("searchContextBytes"), ThriftFieldType::T_STRING, 12); - w.writeBinary(s.searchContextBytes.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteFilter(ThriftBinaryBufferReader & r, NoteFilter & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.order = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.ascending = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.words = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.notebookGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Guid > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NoteFilter.tagGuids)")); - for(qint32 i = 0; i < size; i++) { - Guid elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.tagGuids = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.timeZone = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.inactive = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.emphasized = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeAllReadableNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 15) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeAllReadableWorkspaces = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.context = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.rawWords = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_STRING) { - QByteArray v; - r.readBinary(v); - s.searchContextBytes = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteList(ThriftBinaryBufferWriter & w, const NoteList & s) { - w.writeStructBegin(QStringLiteral("NoteList")); - w.writeFieldBegin(QStringLiteral("startIndex"), ThriftFieldType::T_I32, 1); - w.writeI32(s.startIndex); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("totalNotes"), ThriftFieldType::T_I32, 2); - w.writeI32(s.totalNotes); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("notes"), ThriftFieldType::T_LIST, 3); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.notes.length()); - for(QList< Note >::const_iterator it = s.notes.constBegin(), end = s.notes.constEnd(); it != end; ++it) { - writeNote(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - if(s.stoppedWords.isSet()) { - w.writeFieldBegin(QStringLiteral("stoppedWords"), ThriftFieldType::T_LIST, 4); - w.writeListBegin(ThriftFieldType::T_STRING, s.stoppedWords.ref().length()); - for(QStringList::const_iterator it = s.stoppedWords.ref().constBegin(), end = s.stoppedWords.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.searchedWords.isSet()) { - w.writeFieldBegin(QStringLiteral("searchedWords"), ThriftFieldType::T_LIST, 5); - w.writeListBegin(ThriftFieldType::T_STRING, s.searchedWords.ref().length()); - for(QStringList::const_iterator it = s.searchedWords.ref().constBegin(), end = s.searchedWords.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.updateCount.isSet()) { - w.writeFieldBegin(QStringLiteral("updateCount"), ThriftFieldType::T_I32, 6); - w.writeI32(s.updateCount.ref()); - w.writeFieldEnd(); - } - if(s.searchContextBytes.isSet()) { - w.writeFieldBegin(QStringLiteral("searchContextBytes"), ThriftFieldType::T_STRING, 7); - w.writeBinary(s.searchContextBytes.ref()); - w.writeFieldEnd(); - } - if(s.debugInfo.isSet()) { - w.writeFieldBegin(QStringLiteral("debugInfo"), ThriftFieldType::T_STRING, 8); - w.writeString(s.debugInfo.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteList(ThriftBinaryBufferReader & r, NoteList & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool startIndex_isset = false; - bool totalNotes_isset = false; - bool notes_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - startIndex_isset = true; - qint32 v; - r.readI32(v); - s.startIndex = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I32) { - totalNotes_isset = true; - qint32 v; - r.readI32(v); - s.totalNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_LIST) { - notes_isset = true; - QList< Note > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NoteList.notes)")); - for(qint32 i = 0; i < size; i++) { - Note elem; - readNote(r, elem); - v.append(elem); - } - r.readListEnd(); - s.notes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_LIST) { - QStringList v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NoteList.stoppedWords)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.stoppedWords = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_LIST) { - QStringList v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NoteList.searchedWords)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.searchedWords = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.updateCount = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_STRING) { - QByteArray v; - r.readBinary(v); - s.searchContextBytes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.debugInfo = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!startIndex_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteList.startIndex has no value")); - if(!totalNotes_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteList.totalNotes has no value")); - if(!notes_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteList.notes has no value")); -} - -void writeNoteMetadata(ThriftBinaryBufferWriter & w, const NoteMetadata & s) { - w.writeStructBegin(QStringLiteral("NoteMetadata")); - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.guid); - w.writeFieldEnd(); - if(s.title.isSet()) { - w.writeFieldBegin(QStringLiteral("title"), ThriftFieldType::T_STRING, 2); - w.writeString(s.title.ref()); - w.writeFieldEnd(); - } - if(s.contentLength.isSet()) { - w.writeFieldBegin(QStringLiteral("contentLength"), ThriftFieldType::T_I32, 5); - w.writeI32(s.contentLength.ref()); - w.writeFieldEnd(); - } - if(s.created.isSet()) { - w.writeFieldBegin(QStringLiteral("created"), ThriftFieldType::T_I64, 6); - w.writeI64(s.created.ref()); - w.writeFieldEnd(); - } - if(s.updated.isSet()) { - w.writeFieldBegin(QStringLiteral("updated"), ThriftFieldType::T_I64, 7); - w.writeI64(s.updated.ref()); - w.writeFieldEnd(); - } - if(s.deleted.isSet()) { - w.writeFieldBegin(QStringLiteral("deleted"), ThriftFieldType::T_I64, 8); - w.writeI64(s.deleted.ref()); - w.writeFieldEnd(); - } - if(s.updateSequenceNum.isSet()) { - w.writeFieldBegin(QStringLiteral("updateSequenceNum"), ThriftFieldType::T_I32, 10); - w.writeI32(s.updateSequenceNum.ref()); - w.writeFieldEnd(); - } - if(s.notebookGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("notebookGuid"), ThriftFieldType::T_STRING, 11); - w.writeString(s.notebookGuid.ref()); - w.writeFieldEnd(); - } - if(s.tagGuids.isSet()) { - w.writeFieldBegin(QStringLiteral("tagGuids"), ThriftFieldType::T_LIST, 12); - w.writeListBegin(ThriftFieldType::T_STRING, s.tagGuids.ref().length()); - for(QList< Guid >::const_iterator it = s.tagGuids.ref().constBegin(), end = s.tagGuids.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.attributes.isSet()) { - w.writeFieldBegin(QStringLiteral("attributes"), ThriftFieldType::T_STRUCT, 14); - writeNoteAttributes(w, s.attributes.ref()); - w.writeFieldEnd(); - } - if(s.largestResourceMime.isSet()) { - w.writeFieldBegin(QStringLiteral("largestResourceMime"), ThriftFieldType::T_STRING, 20); - w.writeString(s.largestResourceMime.ref()); - w.writeFieldEnd(); - } - if(s.largestResourceSize.isSet()) { - w.writeFieldBegin(QStringLiteral("largestResourceSize"), ThriftFieldType::T_I32, 21); - w.writeI32(s.largestResourceSize.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteMetadata(ThriftBinaryBufferReader & r, NoteMetadata & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool guid_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - guid_isset = true; - Guid v; - r.readString(v); - s.guid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.title = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.contentLength = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.created = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.updated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.deleted = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.updateSequenceNum = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.notebookGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Guid > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NoteMetadata.tagGuids)")); - for(qint32 i = 0; i < size; i++) { - Guid elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.tagGuids = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 14) { - if (fieldType == ThriftFieldType::T_STRUCT) { - NoteAttributes v; - readNoteAttributes(r, v); - s.attributes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 20) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.largestResourceMime = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 21) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.largestResourceSize = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!guid_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteMetadata.guid has no value")); -} - -void writeNotesMetadataList(ThriftBinaryBufferWriter & w, const NotesMetadataList & s) { - w.writeStructBegin(QStringLiteral("NotesMetadataList")); - w.writeFieldBegin(QStringLiteral("startIndex"), ThriftFieldType::T_I32, 1); - w.writeI32(s.startIndex); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("totalNotes"), ThriftFieldType::T_I32, 2); - w.writeI32(s.totalNotes); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("notes"), ThriftFieldType::T_LIST, 3); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.notes.length()); - for(QList< NoteMetadata >::const_iterator it = s.notes.constBegin(), end = s.notes.constEnd(); it != end; ++it) { - writeNoteMetadata(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - if(s.stoppedWords.isSet()) { - w.writeFieldBegin(QStringLiteral("stoppedWords"), ThriftFieldType::T_LIST, 4); - w.writeListBegin(ThriftFieldType::T_STRING, s.stoppedWords.ref().length()); - for(QStringList::const_iterator it = s.stoppedWords.ref().constBegin(), end = s.stoppedWords.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.searchedWords.isSet()) { - w.writeFieldBegin(QStringLiteral("searchedWords"), ThriftFieldType::T_LIST, 5); - w.writeListBegin(ThriftFieldType::T_STRING, s.searchedWords.ref().length()); - for(QStringList::const_iterator it = s.searchedWords.ref().constBegin(), end = s.searchedWords.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.updateCount.isSet()) { - w.writeFieldBegin(QStringLiteral("updateCount"), ThriftFieldType::T_I32, 6); - w.writeI32(s.updateCount.ref()); - w.writeFieldEnd(); - } - if(s.searchContextBytes.isSet()) { - w.writeFieldBegin(QStringLiteral("searchContextBytes"), ThriftFieldType::T_STRING, 7); - w.writeBinary(s.searchContextBytes.ref()); - w.writeFieldEnd(); - } - if(s.debugInfo.isSet()) { - w.writeFieldBegin(QStringLiteral("debugInfo"), ThriftFieldType::T_STRING, 9); - w.writeString(s.debugInfo.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNotesMetadataList(ThriftBinaryBufferReader & r, NotesMetadataList & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool startIndex_isset = false; - bool totalNotes_isset = false; - bool notes_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - startIndex_isset = true; - qint32 v; - r.readI32(v); - s.startIndex = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I32) { - totalNotes_isset = true; - qint32 v; - r.readI32(v); - s.totalNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_LIST) { - notes_isset = true; - QList< NoteMetadata > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NotesMetadataList.notes)")); - for(qint32 i = 0; i < size; i++) { - NoteMetadata elem; - readNoteMetadata(r, elem); - v.append(elem); - } - r.readListEnd(); - s.notes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_LIST) { - QStringList v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NotesMetadataList.stoppedWords)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.stoppedWords = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_LIST) { - QStringList v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NotesMetadataList.searchedWords)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.searchedWords = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.updateCount = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_STRING) { - QByteArray v; - r.readBinary(v); - s.searchContextBytes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.debugInfo = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!startIndex_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NotesMetadataList.startIndex has no value")); - if(!totalNotes_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NotesMetadataList.totalNotes has no value")); - if(!notes_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NotesMetadataList.notes has no value")); -} - -void writeNotesMetadataResultSpec(ThriftBinaryBufferWriter & w, const NotesMetadataResultSpec & s) { - w.writeStructBegin(QStringLiteral("NotesMetadataResultSpec")); - if(s.includeTitle.isSet()) { - w.writeFieldBegin(QStringLiteral("includeTitle"), ThriftFieldType::T_BOOL, 2); - w.writeBool(s.includeTitle.ref()); - w.writeFieldEnd(); - } - if(s.includeContentLength.isSet()) { - w.writeFieldBegin(QStringLiteral("includeContentLength"), ThriftFieldType::T_BOOL, 5); - w.writeBool(s.includeContentLength.ref()); - w.writeFieldEnd(); - } - if(s.includeCreated.isSet()) { - w.writeFieldBegin(QStringLiteral("includeCreated"), ThriftFieldType::T_BOOL, 6); - w.writeBool(s.includeCreated.ref()); - w.writeFieldEnd(); - } - if(s.includeUpdated.isSet()) { - w.writeFieldBegin(QStringLiteral("includeUpdated"), ThriftFieldType::T_BOOL, 7); - w.writeBool(s.includeUpdated.ref()); - w.writeFieldEnd(); - } - if(s.includeDeleted.isSet()) { - w.writeFieldBegin(QStringLiteral("includeDeleted"), ThriftFieldType::T_BOOL, 8); - w.writeBool(s.includeDeleted.ref()); - w.writeFieldEnd(); - } - if(s.includeUpdateSequenceNum.isSet()) { - w.writeFieldBegin(QStringLiteral("includeUpdateSequenceNum"), ThriftFieldType::T_BOOL, 10); - w.writeBool(s.includeUpdateSequenceNum.ref()); - w.writeFieldEnd(); - } - if(s.includeNotebookGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("includeNotebookGuid"), ThriftFieldType::T_BOOL, 11); - w.writeBool(s.includeNotebookGuid.ref()); - w.writeFieldEnd(); - } - if(s.includeTagGuids.isSet()) { - w.writeFieldBegin(QStringLiteral("includeTagGuids"), ThriftFieldType::T_BOOL, 12); - w.writeBool(s.includeTagGuids.ref()); - w.writeFieldEnd(); - } - if(s.includeAttributes.isSet()) { - w.writeFieldBegin(QStringLiteral("includeAttributes"), ThriftFieldType::T_BOOL, 14); - w.writeBool(s.includeAttributes.ref()); - w.writeFieldEnd(); - } - if(s.includeLargestResourceMime.isSet()) { - w.writeFieldBegin(QStringLiteral("includeLargestResourceMime"), ThriftFieldType::T_BOOL, 20); - w.writeBool(s.includeLargestResourceMime.ref()); - w.writeFieldEnd(); - } - if(s.includeLargestResourceSize.isSet()) { - w.writeFieldBegin(QStringLiteral("includeLargestResourceSize"), ThriftFieldType::T_BOOL, 21); - w.writeBool(s.includeLargestResourceSize.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNotesMetadataResultSpec(ThriftBinaryBufferReader & r, NotesMetadataResultSpec & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeTitle = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeContentLength = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeCreated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeUpdated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeDeleted = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeUpdateSequenceNum = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeNotebookGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeTagGuids = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 14) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeAttributes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 20) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeLargestResourceMime = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 21) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeLargestResourceSize = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteCollectionCounts(ThriftBinaryBufferWriter & w, const NoteCollectionCounts & s) { - w.writeStructBegin(QStringLiteral("NoteCollectionCounts")); - if(s.notebookCounts.isSet()) { - w.writeFieldBegin(QStringLiteral("notebookCounts"), ThriftFieldType::T_MAP, 1); - w.writeMapBegin(ThriftFieldType::T_STRING, ThriftFieldType::T_I32, s.notebookCounts.ref().size()); - for(QMap< Guid, qint32 >::const_iterator it = s.notebookCounts.ref().constBegin(), end = s.notebookCounts.ref().constEnd(); it != end; ++it) { - w.writeString(it.key()); - w.writeI32(it.value()); - } - w.writeMapEnd(); - w.writeFieldEnd(); - } - if(s.tagCounts.isSet()) { - w.writeFieldBegin(QStringLiteral("tagCounts"), ThriftFieldType::T_MAP, 2); - w.writeMapBegin(ThriftFieldType::T_STRING, ThriftFieldType::T_I32, s.tagCounts.ref().size()); - for(QMap< Guid, qint32 >::const_iterator it = s.tagCounts.ref().constBegin(), end = s.tagCounts.ref().constEnd(); it != end; ++it) { - w.writeString(it.key()); - w.writeI32(it.value()); - } - w.writeMapEnd(); - w.writeFieldEnd(); - } - if(s.trashCount.isSet()) { - w.writeFieldBegin(QStringLiteral("trashCount"), ThriftFieldType::T_I32, 3); - w.writeI32(s.trashCount.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteCollectionCounts(ThriftBinaryBufferReader & r, NoteCollectionCounts & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_MAP) { - QMap< Guid, qint32 > v; - qint32 size; - ThriftFieldType::type keyType; - ThriftFieldType::type elemType; - r.readMapBegin(keyType, elemType, size); - if (keyType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map key type (NoteCollectionCounts.notebookCounts)")); - if (elemType != ThriftFieldType::T_I32) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map value type (NoteCollectionCounts.notebookCounts)")); - for(qint32 i = 0; i < size; i++) { - Guid key; - r.readString(key); - qint32 value; - r.readI32(value); - v[key] = value; - } - r.readMapEnd(); - s.notebookCounts = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_MAP) { - QMap< Guid, qint32 > v; - qint32 size; - ThriftFieldType::type keyType; - ThriftFieldType::type elemType; - r.readMapBegin(keyType, elemType, size); - if (keyType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map key type (NoteCollectionCounts.tagCounts)")); - if (elemType != ThriftFieldType::T_I32) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map value type (NoteCollectionCounts.tagCounts)")); - for(qint32 i = 0; i < size; i++) { - Guid key; - r.readString(key); - qint32 value; - r.readI32(value); - v[key] = value; - } - r.readMapEnd(); - s.tagCounts = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.trashCount = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteResultSpec(ThriftBinaryBufferWriter & w, const NoteResultSpec & s) { - w.writeStructBegin(QStringLiteral("NoteResultSpec")); - if(s.includeContent.isSet()) { - w.writeFieldBegin(QStringLiteral("includeContent"), ThriftFieldType::T_BOOL, 1); - w.writeBool(s.includeContent.ref()); - w.writeFieldEnd(); - } - if(s.includeResourcesData.isSet()) { - w.writeFieldBegin(QStringLiteral("includeResourcesData"), ThriftFieldType::T_BOOL, 2); - w.writeBool(s.includeResourcesData.ref()); - w.writeFieldEnd(); - } - if(s.includeResourcesRecognition.isSet()) { - w.writeFieldBegin(QStringLiteral("includeResourcesRecognition"), ThriftFieldType::T_BOOL, 3); - w.writeBool(s.includeResourcesRecognition.ref()); - w.writeFieldEnd(); - } - if(s.includeResourcesAlternateData.isSet()) { - w.writeFieldBegin(QStringLiteral("includeResourcesAlternateData"), ThriftFieldType::T_BOOL, 4); - w.writeBool(s.includeResourcesAlternateData.ref()); - w.writeFieldEnd(); - } - if(s.includeSharedNotes.isSet()) { - w.writeFieldBegin(QStringLiteral("includeSharedNotes"), ThriftFieldType::T_BOOL, 5); - w.writeBool(s.includeSharedNotes.ref()); - w.writeFieldEnd(); - } - if(s.includeNoteAppDataValues.isSet()) { - w.writeFieldBegin(QStringLiteral("includeNoteAppDataValues"), ThriftFieldType::T_BOOL, 6); - w.writeBool(s.includeNoteAppDataValues.ref()); - w.writeFieldEnd(); - } - if(s.includeResourceAppDataValues.isSet()) { - w.writeFieldBegin(QStringLiteral("includeResourceAppDataValues"), ThriftFieldType::T_BOOL, 7); - w.writeBool(s.includeResourceAppDataValues.ref()); - w.writeFieldEnd(); - } - if(s.includeAccountLimits.isSet()) { - w.writeFieldBegin(QStringLiteral("includeAccountLimits"), ThriftFieldType::T_BOOL, 8); - w.writeBool(s.includeAccountLimits.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteResultSpec(ThriftBinaryBufferReader & r, NoteResultSpec & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeContent = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeResourcesData = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeResourcesRecognition = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeResourcesAlternateData = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeSharedNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeNoteAppDataValues = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeResourceAppDataValues = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeAccountLimits = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteEmailParameters(ThriftBinaryBufferWriter & w, const NoteEmailParameters & s) { - w.writeStructBegin(QStringLiteral("NoteEmailParameters")); - if(s.guid.isSet()) { - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.guid.ref()); - w.writeFieldEnd(); - } - if(s.note.isSet()) { - w.writeFieldBegin(QStringLiteral("note"), ThriftFieldType::T_STRUCT, 2); - writeNote(w, s.note.ref()); - w.writeFieldEnd(); - } - if(s.toAddresses.isSet()) { - w.writeFieldBegin(QStringLiteral("toAddresses"), ThriftFieldType::T_LIST, 3); - w.writeListBegin(ThriftFieldType::T_STRING, s.toAddresses.ref().length()); - for(QStringList::const_iterator it = s.toAddresses.ref().constBegin(), end = s.toAddresses.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.ccAddresses.isSet()) { - w.writeFieldBegin(QStringLiteral("ccAddresses"), ThriftFieldType::T_LIST, 4); - w.writeListBegin(ThriftFieldType::T_STRING, s.ccAddresses.ref().length()); - for(QStringList::const_iterator it = s.ccAddresses.ref().constBegin(), end = s.ccAddresses.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.subject.isSet()) { - w.writeFieldBegin(QStringLiteral("subject"), ThriftFieldType::T_STRING, 5); - w.writeString(s.subject.ref()); - w.writeFieldEnd(); - } - if(s.message.isSet()) { - w.writeFieldBegin(QStringLiteral("message"), ThriftFieldType::T_STRING, 6); - w.writeString(s.message.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteEmailParameters(ThriftBinaryBufferReader & r, NoteEmailParameters & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.guid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - Note v; - readNote(r, v); - s.note = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_LIST) { - QStringList v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NoteEmailParameters.toAddresses)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.toAddresses = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_LIST) { - QStringList v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NoteEmailParameters.ccAddresses)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.ccAddresses = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.subject = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.message = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteVersionId(ThriftBinaryBufferWriter & w, const NoteVersionId & s) { - w.writeStructBegin(QStringLiteral("NoteVersionId")); - w.writeFieldBegin(QStringLiteral("updateSequenceNum"), ThriftFieldType::T_I32, 1); - w.writeI32(s.updateSequenceNum); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("updated"), ThriftFieldType::T_I64, 2); - w.writeI64(s.updated); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("saved"), ThriftFieldType::T_I64, 3); - w.writeI64(s.saved); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("title"), ThriftFieldType::T_STRING, 4); - w.writeString(s.title); - w.writeFieldEnd(); - if(s.lastEditorId.isSet()) { - w.writeFieldBegin(QStringLiteral("lastEditorId"), ThriftFieldType::T_I32, 5); - w.writeI32(s.lastEditorId.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteVersionId(ThriftBinaryBufferReader & r, NoteVersionId & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool updateSequenceNum_isset = false; - bool updated_isset = false; - bool saved_isset = false; - bool title_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - updateSequenceNum_isset = true; - qint32 v; - r.readI32(v); - s.updateSequenceNum = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I64) { - updated_isset = true; - qint64 v; - r.readI64(v); - s.updated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I64) { - saved_isset = true; - qint64 v; - r.readI64(v); - s.saved = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - title_isset = true; - QString v; - r.readString(v); - s.title = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.lastEditorId = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!updateSequenceNum_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteVersionId.updateSequenceNum has no value")); - if(!updated_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteVersionId.updated has no value")); - if(!saved_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteVersionId.saved has no value")); - if(!title_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("NoteVersionId.title has no value")); -} - -void writeRelatedQuery(ThriftBinaryBufferWriter & w, const RelatedQuery & s) { - w.writeStructBegin(QStringLiteral("RelatedQuery")); - if(s.noteGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("noteGuid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.noteGuid.ref()); - w.writeFieldEnd(); - } - if(s.plainText.isSet()) { - w.writeFieldBegin(QStringLiteral("plainText"), ThriftFieldType::T_STRING, 2); - w.writeString(s.plainText.ref()); - w.writeFieldEnd(); - } - if(s.filter.isSet()) { - w.writeFieldBegin(QStringLiteral("filter"), ThriftFieldType::T_STRUCT, 3); - writeNoteFilter(w, s.filter.ref()); - w.writeFieldEnd(); - } - if(s.referenceUri.isSet()) { - w.writeFieldBegin(QStringLiteral("referenceUri"), ThriftFieldType::T_STRING, 4); - w.writeString(s.referenceUri.ref()); - w.writeFieldEnd(); - } - if(s.context.isSet()) { - w.writeFieldBegin(QStringLiteral("context"), ThriftFieldType::T_STRING, 5); - w.writeString(s.context.ref()); - w.writeFieldEnd(); - } - if(s.cacheKey.isSet()) { - w.writeFieldBegin(QStringLiteral("cacheKey"), ThriftFieldType::T_STRING, 6); - w.writeString(s.cacheKey.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readRelatedQuery(ThriftBinaryBufferReader & r, RelatedQuery & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.noteGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.plainText = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - NoteFilter v; - readNoteFilter(r, v); - s.filter = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.referenceUri = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.context = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.cacheKey = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeRelatedResult(ThriftBinaryBufferWriter & w, const RelatedResult & s) { - w.writeStructBegin(QStringLiteral("RelatedResult")); - if(s.notes.isSet()) { - w.writeFieldBegin(QStringLiteral("notes"), ThriftFieldType::T_LIST, 1); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.notes.ref().length()); - for(QList< Note >::const_iterator it = s.notes.ref().constBegin(), end = s.notes.ref().constEnd(); it != end; ++it) { - writeNote(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.notebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("notebooks"), ThriftFieldType::T_LIST, 2); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.notebooks.ref().length()); - for(QList< Notebook >::const_iterator it = s.notebooks.ref().constBegin(), end = s.notebooks.ref().constEnd(); it != end; ++it) { - writeNotebook(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.tags.isSet()) { - w.writeFieldBegin(QStringLiteral("tags"), ThriftFieldType::T_LIST, 3); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.tags.ref().length()); - for(QList< Tag >::const_iterator it = s.tags.ref().constBegin(), end = s.tags.ref().constEnd(); it != end; ++it) { - writeTag(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.containingNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("containingNotebooks"), ThriftFieldType::T_LIST, 4); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.containingNotebooks.ref().length()); - for(QList< NotebookDescriptor >::const_iterator it = s.containingNotebooks.ref().constBegin(), end = s.containingNotebooks.ref().constEnd(); it != end; ++it) { - writeNotebookDescriptor(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.debugInfo.isSet()) { - w.writeFieldBegin(QStringLiteral("debugInfo"), ThriftFieldType::T_STRING, 5); - w.writeString(s.debugInfo.ref()); - w.writeFieldEnd(); - } - if(s.experts.isSet()) { - w.writeFieldBegin(QStringLiteral("experts"), ThriftFieldType::T_LIST, 6); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.experts.ref().length()); - for(QList< UserProfile >::const_iterator it = s.experts.ref().constBegin(), end = s.experts.ref().constEnd(); it != end; ++it) { - writeUserProfile(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.relatedContent.isSet()) { - w.writeFieldBegin(QStringLiteral("relatedContent"), ThriftFieldType::T_LIST, 7); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.relatedContent.ref().length()); - for(QList< RelatedContent >::const_iterator it = s.relatedContent.ref().constBegin(), end = s.relatedContent.ref().constEnd(); it != end; ++it) { - writeRelatedContent(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.cacheKey.isSet()) { - w.writeFieldBegin(QStringLiteral("cacheKey"), ThriftFieldType::T_STRING, 8); - w.writeString(s.cacheKey.ref()); - w.writeFieldEnd(); - } - if(s.cacheExpires.isSet()) { - w.writeFieldBegin(QStringLiteral("cacheExpires"), ThriftFieldType::T_I32, 9); - w.writeI32(s.cacheExpires.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readRelatedResult(ThriftBinaryBufferReader & r, RelatedResult & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Note > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (RelatedResult.notes)")); - for(qint32 i = 0; i < size; i++) { - Note elem; - readNote(r, elem); - v.append(elem); - } - r.readListEnd(); - s.notes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Notebook > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (RelatedResult.notebooks)")); - for(qint32 i = 0; i < size; i++) { - Notebook elem; - readNotebook(r, elem); - v.append(elem); - } - r.readListEnd(); - s.notebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Tag > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (RelatedResult.tags)")); - for(qint32 i = 0; i < size; i++) { - Tag elem; - readTag(r, elem); - v.append(elem); - } - r.readListEnd(); - s.tags = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< NotebookDescriptor > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (RelatedResult.containingNotebooks)")); - for(qint32 i = 0; i < size; i++) { - NotebookDescriptor elem; - readNotebookDescriptor(r, elem); - v.append(elem); - } - r.readListEnd(); - s.containingNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.debugInfo = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< UserProfile > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (RelatedResult.experts)")); - for(qint32 i = 0; i < size; i++) { - UserProfile elem; - readUserProfile(r, elem); - v.append(elem); - } - r.readListEnd(); - s.experts = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< RelatedContent > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (RelatedResult.relatedContent)")); - for(qint32 i = 0; i < size; i++) { - RelatedContent elem; - readRelatedContent(r, elem); - v.append(elem); - } - r.readListEnd(); - s.relatedContent = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.cacheKey = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.cacheExpires = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeRelatedResultSpec(ThriftBinaryBufferWriter & w, const RelatedResultSpec & s) { - w.writeStructBegin(QStringLiteral("RelatedResultSpec")); - if(s.maxNotes.isSet()) { - w.writeFieldBegin(QStringLiteral("maxNotes"), ThriftFieldType::T_I32, 1); - w.writeI32(s.maxNotes.ref()); - w.writeFieldEnd(); - } - if(s.maxNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("maxNotebooks"), ThriftFieldType::T_I32, 2); - w.writeI32(s.maxNotebooks.ref()); - w.writeFieldEnd(); - } - if(s.maxTags.isSet()) { - w.writeFieldBegin(QStringLiteral("maxTags"), ThriftFieldType::T_I32, 3); - w.writeI32(s.maxTags.ref()); - w.writeFieldEnd(); - } - if(s.writableNotebooksOnly.isSet()) { - w.writeFieldBegin(QStringLiteral("writableNotebooksOnly"), ThriftFieldType::T_BOOL, 4); - w.writeBool(s.writableNotebooksOnly.ref()); - w.writeFieldEnd(); - } - if(s.includeContainingNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("includeContainingNotebooks"), ThriftFieldType::T_BOOL, 5); - w.writeBool(s.includeContainingNotebooks.ref()); - w.writeFieldEnd(); - } - if(s.includeDebugInfo.isSet()) { - w.writeFieldBegin(QStringLiteral("includeDebugInfo"), ThriftFieldType::T_BOOL, 6); - w.writeBool(s.includeDebugInfo.ref()); - w.writeFieldEnd(); - } - if(s.maxExperts.isSet()) { - w.writeFieldBegin(QStringLiteral("maxExperts"), ThriftFieldType::T_I32, 7); - w.writeI32(s.maxExperts.ref()); - w.writeFieldEnd(); - } - if(s.maxRelatedContent.isSet()) { - w.writeFieldBegin(QStringLiteral("maxRelatedContent"), ThriftFieldType::T_I32, 8); - w.writeI32(s.maxRelatedContent.ref()); - w.writeFieldEnd(); - } - if(s.relatedContentTypes.isSet()) { - w.writeFieldBegin(QStringLiteral("relatedContentTypes"), ThriftFieldType::T_SET, 9); - w.writeSetBegin(ThriftFieldType::T_I32, s.relatedContentTypes.ref().count()); - for(QSet< RelatedContentType::type >::const_iterator it = s.relatedContentTypes.ref().constBegin(), end = s.relatedContentTypes.ref().constEnd(); it != end; ++it) { - w.writeI32(static_cast(*it)); - } - w.writeSetEnd(); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readRelatedResultSpec(ThriftBinaryBufferReader & r, RelatedResultSpec & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.maxNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.maxNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.maxTags = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.writableNotebooksOnly = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeContainingNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeDebugInfo = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.maxExperts = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.maxRelatedContent = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_SET) { - QSet< RelatedContentType::type > v; - qint32 size; - ThriftFieldType::type elemType; - r.readSetBegin(elemType, size); - v.reserve(size); - if (elemType != ThriftFieldType::T_I32) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect set type (RelatedResultSpec.relatedContentTypes)")); - for(qint32 i = 0; i < size; i++) { - RelatedContentType::type elem; - readEnumRelatedContentType(r, elem); - v.insert(elem); - } - r.readSetEnd(); - s.relatedContentTypes = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeUpdateNoteIfUsnMatchesResult(ThriftBinaryBufferWriter & w, const UpdateNoteIfUsnMatchesResult & s) { - w.writeStructBegin(QStringLiteral("UpdateNoteIfUsnMatchesResult")); - if(s.note.isSet()) { - w.writeFieldBegin(QStringLiteral("note"), ThriftFieldType::T_STRUCT, 1); - writeNote(w, s.note.ref()); - w.writeFieldEnd(); - } - if(s.updated.isSet()) { - w.writeFieldBegin(QStringLiteral("updated"), ThriftFieldType::T_BOOL, 2); - w.writeBool(s.updated.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readUpdateNoteIfUsnMatchesResult(ThriftBinaryBufferReader & r, UpdateNoteIfUsnMatchesResult & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - Note v; - readNote(r, v); - s.note = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.updated = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeShareRelationshipRestrictions(ThriftBinaryBufferWriter & w, const ShareRelationshipRestrictions & s) { - w.writeStructBegin(QStringLiteral("ShareRelationshipRestrictions")); - if(s.noSetReadOnly.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetReadOnly"), ThriftFieldType::T_BOOL, 1); - w.writeBool(s.noSetReadOnly.ref()); - w.writeFieldEnd(); - } - if(s.noSetReadPlusActivity.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetReadPlusActivity"), ThriftFieldType::T_BOOL, 2); - w.writeBool(s.noSetReadPlusActivity.ref()); - w.writeFieldEnd(); - } - if(s.noSetModify.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetModify"), ThriftFieldType::T_BOOL, 3); - w.writeBool(s.noSetModify.ref()); - w.writeFieldEnd(); - } - if(s.noSetFullAccess.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetFullAccess"), ThriftFieldType::T_BOOL, 4); - w.writeBool(s.noSetFullAccess.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readShareRelationshipRestrictions(ThriftBinaryBufferReader & r, ShareRelationshipRestrictions & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetReadOnly = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetReadPlusActivity = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetModify = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetFullAccess = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeInvitationShareRelationship(ThriftBinaryBufferWriter & w, const InvitationShareRelationship & s) { - w.writeStructBegin(QStringLiteral("InvitationShareRelationship")); - if(s.displayName.isSet()) { - w.writeFieldBegin(QStringLiteral("displayName"), ThriftFieldType::T_STRING, 1); - w.writeString(s.displayName.ref()); - w.writeFieldEnd(); - } - if(s.recipientUserIdentity.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientUserIdentity"), ThriftFieldType::T_STRUCT, 2); - writeUserIdentity(w, s.recipientUserIdentity.ref()); - w.writeFieldEnd(); - } - if(s.privilege.isSet()) { - w.writeFieldBegin(QStringLiteral("privilege"), ThriftFieldType::T_I32, 3); - w.writeI32(static_cast(s.privilege.ref())); - w.writeFieldEnd(); - } - if(s.sharerUserId.isSet()) { - w.writeFieldBegin(QStringLiteral("sharerUserId"), ThriftFieldType::T_I32, 5); - w.writeI32(s.sharerUserId.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readInvitationShareRelationship(ThriftBinaryBufferReader & r, InvitationShareRelationship & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.displayName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - UserIdentity v; - readUserIdentity(r, v); - s.recipientUserIdentity = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - ShareRelationshipPrivilegeLevel::type v; - readEnumShareRelationshipPrivilegeLevel(r, v); - s.privilege = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.sharerUserId = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeMemberShareRelationship(ThriftBinaryBufferWriter & w, const MemberShareRelationship & s) { - w.writeStructBegin(QStringLiteral("MemberShareRelationship")); - if(s.displayName.isSet()) { - w.writeFieldBegin(QStringLiteral("displayName"), ThriftFieldType::T_STRING, 1); - w.writeString(s.displayName.ref()); - w.writeFieldEnd(); - } - if(s.recipientUserId.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientUserId"), ThriftFieldType::T_I32, 2); - w.writeI32(s.recipientUserId.ref()); - w.writeFieldEnd(); - } - if(s.bestPrivilege.isSet()) { - w.writeFieldBegin(QStringLiteral("bestPrivilege"), ThriftFieldType::T_I32, 3); - w.writeI32(static_cast(s.bestPrivilege.ref())); - w.writeFieldEnd(); - } - if(s.individualPrivilege.isSet()) { - w.writeFieldBegin(QStringLiteral("individualPrivilege"), ThriftFieldType::T_I32, 4); - w.writeI32(static_cast(s.individualPrivilege.ref())); - w.writeFieldEnd(); - } - if(s.restrictions.isSet()) { - w.writeFieldBegin(QStringLiteral("restrictions"), ThriftFieldType::T_STRUCT, 5); - writeShareRelationshipRestrictions(w, s.restrictions.ref()); - w.writeFieldEnd(); - } - if(s.sharerUserId.isSet()) { - w.writeFieldBegin(QStringLiteral("sharerUserId"), ThriftFieldType::T_I32, 6); - w.writeI32(s.sharerUserId.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readMemberShareRelationship(ThriftBinaryBufferReader & r, MemberShareRelationship & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.displayName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.recipientUserId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - ShareRelationshipPrivilegeLevel::type v; - readEnumShareRelationshipPrivilegeLevel(r, v); - s.bestPrivilege = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_I32) { - ShareRelationshipPrivilegeLevel::type v; - readEnumShareRelationshipPrivilegeLevel(r, v); - s.individualPrivilege = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_STRUCT) { - ShareRelationshipRestrictions v; - readShareRelationshipRestrictions(r, v); - s.restrictions = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.sharerUserId = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeShareRelationships(ThriftBinaryBufferWriter & w, const ShareRelationships & s) { - w.writeStructBegin(QStringLiteral("ShareRelationships")); - if(s.invitations.isSet()) { - w.writeFieldBegin(QStringLiteral("invitations"), ThriftFieldType::T_LIST, 1); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.invitations.ref().length()); - for(QList< InvitationShareRelationship >::const_iterator it = s.invitations.ref().constBegin(), end = s.invitations.ref().constEnd(); it != end; ++it) { - writeInvitationShareRelationship(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.memberships.isSet()) { - w.writeFieldBegin(QStringLiteral("memberships"), ThriftFieldType::T_LIST, 2); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.memberships.ref().length()); - for(QList< MemberShareRelationship >::const_iterator it = s.memberships.ref().constBegin(), end = s.memberships.ref().constEnd(); it != end; ++it) { - writeMemberShareRelationship(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.invitationRestrictions.isSet()) { - w.writeFieldBegin(QStringLiteral("invitationRestrictions"), ThriftFieldType::T_STRUCT, 3); - writeShareRelationshipRestrictions(w, s.invitationRestrictions.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readShareRelationships(ThriftBinaryBufferReader & r, ShareRelationships & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< InvitationShareRelationship > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (ShareRelationships.invitations)")); - for(qint32 i = 0; i < size; i++) { - InvitationShareRelationship elem; - readInvitationShareRelationship(r, elem); - v.append(elem); - } - r.readListEnd(); - s.invitations = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< MemberShareRelationship > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (ShareRelationships.memberships)")); - for(qint32 i = 0; i < size; i++) { - MemberShareRelationship elem; - readMemberShareRelationship(r, elem); - v.append(elem); - } - r.readListEnd(); - s.memberships = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - ShareRelationshipRestrictions v; - readShareRelationshipRestrictions(r, v); - s.invitationRestrictions = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeManageNotebookSharesParameters(ThriftBinaryBufferWriter & w, const ManageNotebookSharesParameters & s) { - w.writeStructBegin(QStringLiteral("ManageNotebookSharesParameters")); - if(s.notebookGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("notebookGuid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.notebookGuid.ref()); - w.writeFieldEnd(); - } - if(s.inviteMessage.isSet()) { - w.writeFieldBegin(QStringLiteral("inviteMessage"), ThriftFieldType::T_STRING, 2); - w.writeString(s.inviteMessage.ref()); - w.writeFieldEnd(); - } - if(s.membershipsToUpdate.isSet()) { - w.writeFieldBegin(QStringLiteral("membershipsToUpdate"), ThriftFieldType::T_LIST, 3); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.membershipsToUpdate.ref().length()); - for(QList< MemberShareRelationship >::const_iterator it = s.membershipsToUpdate.ref().constBegin(), end = s.membershipsToUpdate.ref().constEnd(); it != end; ++it) { - writeMemberShareRelationship(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.invitationsToCreateOrUpdate.isSet()) { - w.writeFieldBegin(QStringLiteral("invitationsToCreateOrUpdate"), ThriftFieldType::T_LIST, 4); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.invitationsToCreateOrUpdate.ref().length()); - for(QList< InvitationShareRelationship >::const_iterator it = s.invitationsToCreateOrUpdate.ref().constBegin(), end = s.invitationsToCreateOrUpdate.ref().constEnd(); it != end; ++it) { - writeInvitationShareRelationship(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.unshares.isSet()) { - w.writeFieldBegin(QStringLiteral("unshares"), ThriftFieldType::T_LIST, 5); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.unshares.ref().length()); - for(QList< UserIdentity >::const_iterator it = s.unshares.ref().constBegin(), end = s.unshares.ref().constEnd(); it != end; ++it) { - writeUserIdentity(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readManageNotebookSharesParameters(ThriftBinaryBufferReader & r, ManageNotebookSharesParameters & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.notebookGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.inviteMessage = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< MemberShareRelationship > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (ManageNotebookSharesParameters.membershipsToUpdate)")); - for(qint32 i = 0; i < size; i++) { - MemberShareRelationship elem; - readMemberShareRelationship(r, elem); - v.append(elem); - } - r.readListEnd(); - s.membershipsToUpdate = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< InvitationShareRelationship > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (ManageNotebookSharesParameters.invitationsToCreateOrUpdate)")); - for(qint32 i = 0; i < size; i++) { - InvitationShareRelationship elem; - readInvitationShareRelationship(r, elem); - v.append(elem); - } - r.readListEnd(); - s.invitationsToCreateOrUpdate = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< UserIdentity > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (ManageNotebookSharesParameters.unshares)")); - for(qint32 i = 0; i < size; i++) { - UserIdentity elem; - readUserIdentity(r, elem); - v.append(elem); - } - r.readListEnd(); - s.unshares = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeManageNotebookSharesError(ThriftBinaryBufferWriter & w, const ManageNotebookSharesError & s) { - w.writeStructBegin(QStringLiteral("ManageNotebookSharesError")); - if(s.userIdentity.isSet()) { - w.writeFieldBegin(QStringLiteral("userIdentity"), ThriftFieldType::T_STRUCT, 1); - writeUserIdentity(w, s.userIdentity.ref()); - w.writeFieldEnd(); - } - if(s.userException.isSet()) { - w.writeFieldBegin(QStringLiteral("userException"), ThriftFieldType::T_STRUCT, 2); - writeEDAMUserException(w, s.userException.ref()); - w.writeFieldEnd(); - } - if(s.notFoundException.isSet()) { - w.writeFieldBegin(QStringLiteral("notFoundException"), ThriftFieldType::T_STRUCT, 3); - writeEDAMNotFoundException(w, s.notFoundException.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readManageNotebookSharesError(ThriftBinaryBufferReader & r, ManageNotebookSharesError & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRUCT) { - UserIdentity v; - readUserIdentity(r, v); - s.userIdentity = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException v; - readEDAMUserException(r, v); - s.userException = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException v; - readEDAMNotFoundException(r, v); - s.notFoundException = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeManageNotebookSharesResult(ThriftBinaryBufferWriter & w, const ManageNotebookSharesResult & s) { - w.writeStructBegin(QStringLiteral("ManageNotebookSharesResult")); - if(s.errors.isSet()) { - w.writeFieldBegin(QStringLiteral("errors"), ThriftFieldType::T_LIST, 1); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.errors.ref().length()); - for(QList< ManageNotebookSharesError >::const_iterator it = s.errors.ref().constBegin(), end = s.errors.ref().constEnd(); it != end; ++it) { - writeManageNotebookSharesError(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readManageNotebookSharesResult(ThriftBinaryBufferReader & r, ManageNotebookSharesResult & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< ManageNotebookSharesError > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (ManageNotebookSharesResult.errors)")); - for(qint32 i = 0; i < size; i++) { - ManageNotebookSharesError elem; - readManageNotebookSharesError(r, elem); - v.append(elem); - } - r.readListEnd(); - s.errors = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeSharedNoteTemplate(ThriftBinaryBufferWriter & w, const SharedNoteTemplate & s) { - w.writeStructBegin(QStringLiteral("SharedNoteTemplate")); - if(s.noteGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("noteGuid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.noteGuid.ref()); - w.writeFieldEnd(); - } - if(s.recipientThreadId.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientThreadId"), ThriftFieldType::T_I64, 4); - w.writeI64(s.recipientThreadId.ref()); - w.writeFieldEnd(); - } - if(s.recipientContacts.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientContacts"), ThriftFieldType::T_LIST, 2); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.recipientContacts.ref().length()); - for(QList< Contact >::const_iterator it = s.recipientContacts.ref().constBegin(), end = s.recipientContacts.ref().constEnd(); it != end; ++it) { - writeContact(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.privilege.isSet()) { - w.writeFieldBegin(QStringLiteral("privilege"), ThriftFieldType::T_I32, 3); - w.writeI32(static_cast(s.privilege.ref())); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readSharedNoteTemplate(ThriftBinaryBufferReader & r, SharedNoteTemplate & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.noteGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_I64) { - MessageThreadID v; - r.readI64(v); - s.recipientThreadId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Contact > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (SharedNoteTemplate.recipientContacts)")); - for(qint32 i = 0; i < size; i++) { - Contact elem; - readContact(r, elem); - v.append(elem); - } - r.readListEnd(); - s.recipientContacts = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - SharedNotePrivilegeLevel::type v; - readEnumSharedNotePrivilegeLevel(r, v); - s.privilege = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNotebookShareTemplate(ThriftBinaryBufferWriter & w, const NotebookShareTemplate & s) { - w.writeStructBegin(QStringLiteral("NotebookShareTemplate")); - if(s.notebookGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("notebookGuid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.notebookGuid.ref()); - w.writeFieldEnd(); - } - if(s.recipientThreadId.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientThreadId"), ThriftFieldType::T_I64, 4); - w.writeI64(s.recipientThreadId.ref()); - w.writeFieldEnd(); - } - if(s.recipientContacts.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientContacts"), ThriftFieldType::T_LIST, 2); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.recipientContacts.ref().length()); - for(QList< Contact >::const_iterator it = s.recipientContacts.ref().constBegin(), end = s.recipientContacts.ref().constEnd(); it != end; ++it) { - writeContact(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.privilege.isSet()) { - w.writeFieldBegin(QStringLiteral("privilege"), ThriftFieldType::T_I32, 3); - w.writeI32(static_cast(s.privilege.ref())); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNotebookShareTemplate(ThriftBinaryBufferReader & r, NotebookShareTemplate & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.notebookGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_I64) { - MessageThreadID v; - r.readI64(v); - s.recipientThreadId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Contact > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NotebookShareTemplate.recipientContacts)")); - for(qint32 i = 0; i < size; i++) { - Contact elem; - readContact(r, elem); - v.append(elem); - } - r.readListEnd(); - s.recipientContacts = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - SharedNotebookPrivilegeLevel::type v; - readEnumSharedNotebookPrivilegeLevel(r, v); - s.privilege = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeCreateOrUpdateNotebookSharesResult(ThriftBinaryBufferWriter & w, const CreateOrUpdateNotebookSharesResult & s) { - w.writeStructBegin(QStringLiteral("CreateOrUpdateNotebookSharesResult")); - if(s.updateSequenceNum.isSet()) { - w.writeFieldBegin(QStringLiteral("updateSequenceNum"), ThriftFieldType::T_I32, 1); - w.writeI32(s.updateSequenceNum.ref()); - w.writeFieldEnd(); - } - if(s.matchingShares.isSet()) { - w.writeFieldBegin(QStringLiteral("matchingShares"), ThriftFieldType::T_LIST, 2); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.matchingShares.ref().length()); - for(QList< SharedNotebook >::const_iterator it = s.matchingShares.ref().constBegin(), end = s.matchingShares.ref().constEnd(); it != end; ++it) { - writeSharedNotebook(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readCreateOrUpdateNotebookSharesResult(ThriftBinaryBufferReader & r, CreateOrUpdateNotebookSharesResult & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.updateSequenceNum = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< SharedNotebook > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (CreateOrUpdateNotebookSharesResult.matchingShares)")); - for(qint32 i = 0; i < size; i++) { - SharedNotebook elem; - readSharedNotebook(r, elem); - v.append(elem); - } - r.readListEnd(); - s.matchingShares = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteShareRelationshipRestrictions(ThriftBinaryBufferWriter & w, const NoteShareRelationshipRestrictions & s) { - w.writeStructBegin(QStringLiteral("NoteShareRelationshipRestrictions")); - if(s.noSetReadNote.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetReadNote"), ThriftFieldType::T_BOOL, 1); - w.writeBool(s.noSetReadNote.ref()); - w.writeFieldEnd(); - } - if(s.noSetModifyNote.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetModifyNote"), ThriftFieldType::T_BOOL, 2); - w.writeBool(s.noSetModifyNote.ref()); - w.writeFieldEnd(); - } - if(s.noSetFullAccess.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetFullAccess"), ThriftFieldType::T_BOOL, 3); - w.writeBool(s.noSetFullAccess.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteShareRelationshipRestrictions(ThriftBinaryBufferReader & r, NoteShareRelationshipRestrictions & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetReadNote = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetModifyNote = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetFullAccess = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteMemberShareRelationship(ThriftBinaryBufferWriter & w, const NoteMemberShareRelationship & s) { - w.writeStructBegin(QStringLiteral("NoteMemberShareRelationship")); - if(s.displayName.isSet()) { - w.writeFieldBegin(QStringLiteral("displayName"), ThriftFieldType::T_STRING, 1); - w.writeString(s.displayName.ref()); - w.writeFieldEnd(); - } - if(s.recipientUserId.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientUserId"), ThriftFieldType::T_I32, 2); - w.writeI32(s.recipientUserId.ref()); - w.writeFieldEnd(); - } - if(s.privilege.isSet()) { - w.writeFieldBegin(QStringLiteral("privilege"), ThriftFieldType::T_I32, 3); - w.writeI32(static_cast(s.privilege.ref())); - w.writeFieldEnd(); - } - if(s.restrictions.isSet()) { - w.writeFieldBegin(QStringLiteral("restrictions"), ThriftFieldType::T_STRUCT, 4); - writeNoteShareRelationshipRestrictions(w, s.restrictions.ref()); - w.writeFieldEnd(); - } - if(s.sharerUserId.isSet()) { - w.writeFieldBegin(QStringLiteral("sharerUserId"), ThriftFieldType::T_I32, 5); - w.writeI32(s.sharerUserId.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteMemberShareRelationship(ThriftBinaryBufferReader & r, NoteMemberShareRelationship & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.displayName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.recipientUserId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - SharedNotePrivilegeLevel::type v; - readEnumSharedNotePrivilegeLevel(r, v); - s.privilege = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRUCT) { - NoteShareRelationshipRestrictions v; - readNoteShareRelationshipRestrictions(r, v); - s.restrictions = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.sharerUserId = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteInvitationShareRelationship(ThriftBinaryBufferWriter & w, const NoteInvitationShareRelationship & s) { - w.writeStructBegin(QStringLiteral("NoteInvitationShareRelationship")); - if(s.displayName.isSet()) { - w.writeFieldBegin(QStringLiteral("displayName"), ThriftFieldType::T_STRING, 1); - w.writeString(s.displayName.ref()); - w.writeFieldEnd(); - } - if(s.recipientIdentityId.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientIdentityId"), ThriftFieldType::T_I64, 2); - w.writeI64(s.recipientIdentityId.ref()); - w.writeFieldEnd(); - } - if(s.privilege.isSet()) { - w.writeFieldBegin(QStringLiteral("privilege"), ThriftFieldType::T_I32, 3); - w.writeI32(static_cast(s.privilege.ref())); - w.writeFieldEnd(); - } - if(s.sharerUserId.isSet()) { - w.writeFieldBegin(QStringLiteral("sharerUserId"), ThriftFieldType::T_I32, 5); - w.writeI32(s.sharerUserId.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteInvitationShareRelationship(ThriftBinaryBufferReader & r, NoteInvitationShareRelationship & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.displayName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I64) { - IdentityID v; - r.readI64(v); - s.recipientIdentityId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - SharedNotePrivilegeLevel::type v; - readEnumSharedNotePrivilegeLevel(r, v); - s.privilege = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.sharerUserId = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteShareRelationships(ThriftBinaryBufferWriter & w, const NoteShareRelationships & s) { - w.writeStructBegin(QStringLiteral("NoteShareRelationships")); - if(s.invitations.isSet()) { - w.writeFieldBegin(QStringLiteral("invitations"), ThriftFieldType::T_LIST, 1); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.invitations.ref().length()); - for(QList< NoteInvitationShareRelationship >::const_iterator it = s.invitations.ref().constBegin(), end = s.invitations.ref().constEnd(); it != end; ++it) { - writeNoteInvitationShareRelationship(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.memberships.isSet()) { - w.writeFieldBegin(QStringLiteral("memberships"), ThriftFieldType::T_LIST, 2); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.memberships.ref().length()); - for(QList< NoteMemberShareRelationship >::const_iterator it = s.memberships.ref().constBegin(), end = s.memberships.ref().constEnd(); it != end; ++it) { - writeNoteMemberShareRelationship(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.invitationRestrictions.isSet()) { - w.writeFieldBegin(QStringLiteral("invitationRestrictions"), ThriftFieldType::T_STRUCT, 3); - writeNoteShareRelationshipRestrictions(w, s.invitationRestrictions.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteShareRelationships(ThriftBinaryBufferReader & r, NoteShareRelationships & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< NoteInvitationShareRelationship > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NoteShareRelationships.invitations)")); - for(qint32 i = 0; i < size; i++) { - NoteInvitationShareRelationship elem; - readNoteInvitationShareRelationship(r, elem); - v.append(elem); - } - r.readListEnd(); - s.invitations = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< NoteMemberShareRelationship > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (NoteShareRelationships.memberships)")); - for(qint32 i = 0; i < size; i++) { - NoteMemberShareRelationship elem; - readNoteMemberShareRelationship(r, elem); - v.append(elem); - } - r.readListEnd(); - s.memberships = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - NoteShareRelationshipRestrictions v; - readNoteShareRelationshipRestrictions(r, v); - s.invitationRestrictions = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeManageNoteSharesParameters(ThriftBinaryBufferWriter & w, const ManageNoteSharesParameters & s) { - w.writeStructBegin(QStringLiteral("ManageNoteSharesParameters")); - if(s.noteGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("noteGuid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.noteGuid.ref()); - w.writeFieldEnd(); - } - if(s.membershipsToUpdate.isSet()) { - w.writeFieldBegin(QStringLiteral("membershipsToUpdate"), ThriftFieldType::T_LIST, 2); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.membershipsToUpdate.ref().length()); - for(QList< NoteMemberShareRelationship >::const_iterator it = s.membershipsToUpdate.ref().constBegin(), end = s.membershipsToUpdate.ref().constEnd(); it != end; ++it) { - writeNoteMemberShareRelationship(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.invitationsToUpdate.isSet()) { - w.writeFieldBegin(QStringLiteral("invitationsToUpdate"), ThriftFieldType::T_LIST, 3); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.invitationsToUpdate.ref().length()); - for(QList< NoteInvitationShareRelationship >::const_iterator it = s.invitationsToUpdate.ref().constBegin(), end = s.invitationsToUpdate.ref().constEnd(); it != end; ++it) { - writeNoteInvitationShareRelationship(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.membershipsToUnshare.isSet()) { - w.writeFieldBegin(QStringLiteral("membershipsToUnshare"), ThriftFieldType::T_LIST, 4); - w.writeListBegin(ThriftFieldType::T_I32, s.membershipsToUnshare.ref().length()); - for(QList< UserID >::const_iterator it = s.membershipsToUnshare.ref().constBegin(), end = s.membershipsToUnshare.ref().constEnd(); it != end; ++it) { - w.writeI32(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.invitationsToUnshare.isSet()) { - w.writeFieldBegin(QStringLiteral("invitationsToUnshare"), ThriftFieldType::T_LIST, 5); - w.writeListBegin(ThriftFieldType::T_I64, s.invitationsToUnshare.ref().length()); - for(QList< IdentityID >::const_iterator it = s.invitationsToUnshare.ref().constBegin(), end = s.invitationsToUnshare.ref().constEnd(); it != end; ++it) { - w.writeI64(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readManageNoteSharesParameters(ThriftBinaryBufferReader & r, ManageNoteSharesParameters & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.noteGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< NoteMemberShareRelationship > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (ManageNoteSharesParameters.membershipsToUpdate)")); - for(qint32 i = 0; i < size; i++) { - NoteMemberShareRelationship elem; - readNoteMemberShareRelationship(r, elem); - v.append(elem); - } - r.readListEnd(); - s.membershipsToUpdate = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< NoteInvitationShareRelationship > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (ManageNoteSharesParameters.invitationsToUpdate)")); - for(qint32 i = 0; i < size; i++) { - NoteInvitationShareRelationship elem; - readNoteInvitationShareRelationship(r, elem); - v.append(elem); - } - r.readListEnd(); - s.invitationsToUpdate = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< UserID > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_I32) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (ManageNoteSharesParameters.membershipsToUnshare)")); - for(qint32 i = 0; i < size; i++) { - UserID elem; - r.readI32(elem); - v.append(elem); - } - r.readListEnd(); - s.membershipsToUnshare = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< IdentityID > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_I64) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (ManageNoteSharesParameters.invitationsToUnshare)")); - for(qint32 i = 0; i < size; i++) { - IdentityID elem; - r.readI64(elem); - v.append(elem); - } - r.readListEnd(); - s.invitationsToUnshare = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeManageNoteSharesError(ThriftBinaryBufferWriter & w, const ManageNoteSharesError & s) { - w.writeStructBegin(QStringLiteral("ManageNoteSharesError")); - if(s.identityID.isSet()) { - w.writeFieldBegin(QStringLiteral("identityID"), ThriftFieldType::T_I64, 1); - w.writeI64(s.identityID.ref()); - w.writeFieldEnd(); - } - if(s.userID.isSet()) { - w.writeFieldBegin(QStringLiteral("userID"), ThriftFieldType::T_I32, 2); - w.writeI32(s.userID.ref()); - w.writeFieldEnd(); - } - if(s.userException.isSet()) { - w.writeFieldBegin(QStringLiteral("userException"), ThriftFieldType::T_STRUCT, 3); - writeEDAMUserException(w, s.userException.ref()); - w.writeFieldEnd(); - } - if(s.notFoundException.isSet()) { - w.writeFieldBegin(QStringLiteral("notFoundException"), ThriftFieldType::T_STRUCT, 4); - writeEDAMNotFoundException(w, s.notFoundException.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readManageNoteSharesError(ThriftBinaryBufferReader & r, ManageNoteSharesError & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I64) { - IdentityID v; - r.readI64(v); - s.identityID = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.userID = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMUserException v; - readEDAMUserException(r, v); - s.userException = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRUCT) { - EDAMNotFoundException v; - readEDAMNotFoundException(r, v); - s.notFoundException = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeManageNoteSharesResult(ThriftBinaryBufferWriter & w, const ManageNoteSharesResult & s) { - w.writeStructBegin(QStringLiteral("ManageNoteSharesResult")); - if(s.errors.isSet()) { - w.writeFieldBegin(QStringLiteral("errors"), ThriftFieldType::T_LIST, 1); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.errors.ref().length()); - for(QList< ManageNoteSharesError >::const_iterator it = s.errors.ref().constBegin(), end = s.errors.ref().constEnd(); it != end; ++it) { - writeManageNoteSharesError(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readManageNoteSharesResult(ThriftBinaryBufferReader & r, ManageNoteSharesResult & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< ManageNoteSharesError > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (ManageNoteSharesResult.errors)")); - for(qint32 i = 0; i < size; i++) { - ManageNoteSharesError elem; - readManageNoteSharesError(r, elem); - v.append(elem); - } - r.readListEnd(); - s.errors = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeData(ThriftBinaryBufferWriter & w, const Data & s) { - w.writeStructBegin(QStringLiteral("Data")); - if(s.bodyHash.isSet()) { - w.writeFieldBegin(QStringLiteral("bodyHash"), ThriftFieldType::T_STRING, 1); - w.writeBinary(s.bodyHash.ref()); - w.writeFieldEnd(); - } - if(s.size.isSet()) { - w.writeFieldBegin(QStringLiteral("size"), ThriftFieldType::T_I32, 2); - w.writeI32(s.size.ref()); - w.writeFieldEnd(); - } - if(s.body.isSet()) { - w.writeFieldBegin(QStringLiteral("body"), ThriftFieldType::T_STRING, 3); - w.writeBinary(s.body.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readData(ThriftBinaryBufferReader & r, Data & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QByteArray v; - r.readBinary(v); - s.bodyHash = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.size = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - QByteArray v; - r.readBinary(v); - s.body = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeUserAttributes(ThriftBinaryBufferWriter & w, const UserAttributes & s) { - w.writeStructBegin(QStringLiteral("UserAttributes")); - if(s.defaultLocationName.isSet()) { - w.writeFieldBegin(QStringLiteral("defaultLocationName"), ThriftFieldType::T_STRING, 1); - w.writeString(s.defaultLocationName.ref()); - w.writeFieldEnd(); - } - if(s.defaultLatitude.isSet()) { - w.writeFieldBegin(QStringLiteral("defaultLatitude"), ThriftFieldType::T_DOUBLE, 2); - w.writeDouble(s.defaultLatitude.ref()); - w.writeFieldEnd(); - } - if(s.defaultLongitude.isSet()) { - w.writeFieldBegin(QStringLiteral("defaultLongitude"), ThriftFieldType::T_DOUBLE, 3); - w.writeDouble(s.defaultLongitude.ref()); - w.writeFieldEnd(); - } - if(s.preactivation.isSet()) { - w.writeFieldBegin(QStringLiteral("preactivation"), ThriftFieldType::T_BOOL, 4); - w.writeBool(s.preactivation.ref()); - w.writeFieldEnd(); - } - if(s.viewedPromotions.isSet()) { - w.writeFieldBegin(QStringLiteral("viewedPromotions"), ThriftFieldType::T_LIST, 5); - w.writeListBegin(ThriftFieldType::T_STRING, s.viewedPromotions.ref().length()); - for(QStringList::const_iterator it = s.viewedPromotions.ref().constBegin(), end = s.viewedPromotions.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.incomingEmailAddress.isSet()) { - w.writeFieldBegin(QStringLiteral("incomingEmailAddress"), ThriftFieldType::T_STRING, 6); - w.writeString(s.incomingEmailAddress.ref()); - w.writeFieldEnd(); - } - if(s.recentMailedAddresses.isSet()) { - w.writeFieldBegin(QStringLiteral("recentMailedAddresses"), ThriftFieldType::T_LIST, 7); - w.writeListBegin(ThriftFieldType::T_STRING, s.recentMailedAddresses.ref().length()); - for(QStringList::const_iterator it = s.recentMailedAddresses.ref().constBegin(), end = s.recentMailedAddresses.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.comments.isSet()) { - w.writeFieldBegin(QStringLiteral("comments"), ThriftFieldType::T_STRING, 9); - w.writeString(s.comments.ref()); - w.writeFieldEnd(); - } - if(s.dateAgreedToTermsOfService.isSet()) { - w.writeFieldBegin(QStringLiteral("dateAgreedToTermsOfService"), ThriftFieldType::T_I64, 11); - w.writeI64(s.dateAgreedToTermsOfService.ref()); - w.writeFieldEnd(); - } - if(s.maxReferrals.isSet()) { - w.writeFieldBegin(QStringLiteral("maxReferrals"), ThriftFieldType::T_I32, 12); - w.writeI32(s.maxReferrals.ref()); - w.writeFieldEnd(); - } - if(s.referralCount.isSet()) { - w.writeFieldBegin(QStringLiteral("referralCount"), ThriftFieldType::T_I32, 13); - w.writeI32(s.referralCount.ref()); - w.writeFieldEnd(); - } - if(s.refererCode.isSet()) { - w.writeFieldBegin(QStringLiteral("refererCode"), ThriftFieldType::T_STRING, 14); - w.writeString(s.refererCode.ref()); - w.writeFieldEnd(); - } - if(s.sentEmailDate.isSet()) { - w.writeFieldBegin(QStringLiteral("sentEmailDate"), ThriftFieldType::T_I64, 15); - w.writeI64(s.sentEmailDate.ref()); - w.writeFieldEnd(); - } - if(s.sentEmailCount.isSet()) { - w.writeFieldBegin(QStringLiteral("sentEmailCount"), ThriftFieldType::T_I32, 16); - w.writeI32(s.sentEmailCount.ref()); - w.writeFieldEnd(); - } - if(s.dailyEmailLimit.isSet()) { - w.writeFieldBegin(QStringLiteral("dailyEmailLimit"), ThriftFieldType::T_I32, 17); - w.writeI32(s.dailyEmailLimit.ref()); - w.writeFieldEnd(); - } - if(s.emailOptOutDate.isSet()) { - w.writeFieldBegin(QStringLiteral("emailOptOutDate"), ThriftFieldType::T_I64, 18); - w.writeI64(s.emailOptOutDate.ref()); - w.writeFieldEnd(); - } - if(s.partnerEmailOptInDate.isSet()) { - w.writeFieldBegin(QStringLiteral("partnerEmailOptInDate"), ThriftFieldType::T_I64, 19); - w.writeI64(s.partnerEmailOptInDate.ref()); - w.writeFieldEnd(); - } - if(s.preferredLanguage.isSet()) { - w.writeFieldBegin(QStringLiteral("preferredLanguage"), ThriftFieldType::T_STRING, 20); - w.writeString(s.preferredLanguage.ref()); - w.writeFieldEnd(); - } - if(s.preferredCountry.isSet()) { - w.writeFieldBegin(QStringLiteral("preferredCountry"), ThriftFieldType::T_STRING, 21); - w.writeString(s.preferredCountry.ref()); - w.writeFieldEnd(); - } - if(s.clipFullPage.isSet()) { - w.writeFieldBegin(QStringLiteral("clipFullPage"), ThriftFieldType::T_BOOL, 22); - w.writeBool(s.clipFullPage.ref()); - w.writeFieldEnd(); - } - if(s.twitterUserName.isSet()) { - w.writeFieldBegin(QStringLiteral("twitterUserName"), ThriftFieldType::T_STRING, 23); - w.writeString(s.twitterUserName.ref()); - w.writeFieldEnd(); - } - if(s.twitterId.isSet()) { - w.writeFieldBegin(QStringLiteral("twitterId"), ThriftFieldType::T_STRING, 24); - w.writeString(s.twitterId.ref()); - w.writeFieldEnd(); - } - if(s.groupName.isSet()) { - w.writeFieldBegin(QStringLiteral("groupName"), ThriftFieldType::T_STRING, 25); - w.writeString(s.groupName.ref()); - w.writeFieldEnd(); - } - if(s.recognitionLanguage.isSet()) { - w.writeFieldBegin(QStringLiteral("recognitionLanguage"), ThriftFieldType::T_STRING, 26); - w.writeString(s.recognitionLanguage.ref()); - w.writeFieldEnd(); - } - if(s.referralProof.isSet()) { - w.writeFieldBegin(QStringLiteral("referralProof"), ThriftFieldType::T_STRING, 28); - w.writeString(s.referralProof.ref()); - w.writeFieldEnd(); - } - if(s.educationalDiscount.isSet()) { - w.writeFieldBegin(QStringLiteral("educationalDiscount"), ThriftFieldType::T_BOOL, 29); - w.writeBool(s.educationalDiscount.ref()); - w.writeFieldEnd(); - } - if(s.businessAddress.isSet()) { - w.writeFieldBegin(QStringLiteral("businessAddress"), ThriftFieldType::T_STRING, 30); - w.writeString(s.businessAddress.ref()); - w.writeFieldEnd(); - } - if(s.hideSponsorBilling.isSet()) { - w.writeFieldBegin(QStringLiteral("hideSponsorBilling"), ThriftFieldType::T_BOOL, 31); - w.writeBool(s.hideSponsorBilling.ref()); - w.writeFieldEnd(); - } - if(s.useEmailAutoFiling.isSet()) { - w.writeFieldBegin(QStringLiteral("useEmailAutoFiling"), ThriftFieldType::T_BOOL, 33); - w.writeBool(s.useEmailAutoFiling.ref()); - w.writeFieldEnd(); - } - if(s.reminderEmailConfig.isSet()) { - w.writeFieldBegin(QStringLiteral("reminderEmailConfig"), ThriftFieldType::T_I32, 34); - w.writeI32(static_cast(s.reminderEmailConfig.ref())); - w.writeFieldEnd(); - } - if(s.emailAddressLastConfirmed.isSet()) { - w.writeFieldBegin(QStringLiteral("emailAddressLastConfirmed"), ThriftFieldType::T_I64, 35); - w.writeI64(s.emailAddressLastConfirmed.ref()); - w.writeFieldEnd(); - } - if(s.passwordUpdated.isSet()) { - w.writeFieldBegin(QStringLiteral("passwordUpdated"), ThriftFieldType::T_I64, 36); - w.writeI64(s.passwordUpdated.ref()); - w.writeFieldEnd(); - } - if(s.salesforcePushEnabled.isSet()) { - w.writeFieldBegin(QStringLiteral("salesforcePushEnabled"), ThriftFieldType::T_BOOL, 37); - w.writeBool(s.salesforcePushEnabled.ref()); - w.writeFieldEnd(); - } - if(s.shouldLogClientEvent.isSet()) { - w.writeFieldBegin(QStringLiteral("shouldLogClientEvent"), ThriftFieldType::T_BOOL, 38); - w.writeBool(s.shouldLogClientEvent.ref()); - w.writeFieldEnd(); - } - if(s.optOutMachineLearning.isSet()) { - w.writeFieldBegin(QStringLiteral("optOutMachineLearning"), ThriftFieldType::T_BOOL, 39); - w.writeBool(s.optOutMachineLearning.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readUserAttributes(ThriftBinaryBufferReader & r, UserAttributes & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.defaultLocationName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_DOUBLE) { - double v; - r.readDouble(v); - s.defaultLatitude = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_DOUBLE) { - double v; - r.readDouble(v); - s.defaultLongitude = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.preactivation = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_LIST) { - QStringList v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (UserAttributes.viewedPromotions)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.viewedPromotions = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.incomingEmailAddress = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_LIST) { - QStringList v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (UserAttributes.recentMailedAddresses)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.recentMailedAddresses = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.comments = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.dateAgreedToTermsOfService = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.maxReferrals = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.referralCount = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 14) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.refererCode = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 15) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.sentEmailDate = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 16) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.sentEmailCount = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 17) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.dailyEmailLimit = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 18) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.emailOptOutDate = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 19) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.partnerEmailOptInDate = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 20) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.preferredLanguage = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 21) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.preferredCountry = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 22) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.clipFullPage = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 23) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.twitterUserName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 24) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.twitterId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 25) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.groupName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 26) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.recognitionLanguage = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 28) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.referralProof = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 29) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.educationalDiscount = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 30) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.businessAddress = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 31) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.hideSponsorBilling = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 33) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.useEmailAutoFiling = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 34) { - if (fieldType == ThriftFieldType::T_I32) { - ReminderEmailConfig::type v; - readEnumReminderEmailConfig(r, v); - s.reminderEmailConfig = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 35) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.emailAddressLastConfirmed = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 36) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.passwordUpdated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 37) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.salesforcePushEnabled = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 38) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.shouldLogClientEvent = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 39) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.optOutMachineLearning = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeBusinessUserAttributes(ThriftBinaryBufferWriter & w, const BusinessUserAttributes & s) { - w.writeStructBegin(QStringLiteral("BusinessUserAttributes")); - if(s.title.isSet()) { - w.writeFieldBegin(QStringLiteral("title"), ThriftFieldType::T_STRING, 1); - w.writeString(s.title.ref()); - w.writeFieldEnd(); - } - if(s.location.isSet()) { - w.writeFieldBegin(QStringLiteral("location"), ThriftFieldType::T_STRING, 2); - w.writeString(s.location.ref()); - w.writeFieldEnd(); - } - if(s.department.isSet()) { - w.writeFieldBegin(QStringLiteral("department"), ThriftFieldType::T_STRING, 3); - w.writeString(s.department.ref()); - w.writeFieldEnd(); - } - if(s.mobilePhone.isSet()) { - w.writeFieldBegin(QStringLiteral("mobilePhone"), ThriftFieldType::T_STRING, 4); - w.writeString(s.mobilePhone.ref()); - w.writeFieldEnd(); - } - if(s.linkedInProfileUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("linkedInProfileUrl"), ThriftFieldType::T_STRING, 5); - w.writeString(s.linkedInProfileUrl.ref()); - w.writeFieldEnd(); - } - if(s.workPhone.isSet()) { - w.writeFieldBegin(QStringLiteral("workPhone"), ThriftFieldType::T_STRING, 6); - w.writeString(s.workPhone.ref()); - w.writeFieldEnd(); - } - if(s.companyStartDate.isSet()) { - w.writeFieldBegin(QStringLiteral("companyStartDate"), ThriftFieldType::T_I64, 7); - w.writeI64(s.companyStartDate.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readBusinessUserAttributes(ThriftBinaryBufferReader & r, BusinessUserAttributes & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.title = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.location = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.department = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.mobilePhone = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.linkedInProfileUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.workPhone = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.companyStartDate = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeAccounting(ThriftBinaryBufferWriter & w, const Accounting & s) { - w.writeStructBegin(QStringLiteral("Accounting")); - if(s.uploadLimitEnd.isSet()) { - w.writeFieldBegin(QStringLiteral("uploadLimitEnd"), ThriftFieldType::T_I64, 2); - w.writeI64(s.uploadLimitEnd.ref()); - w.writeFieldEnd(); - } - if(s.uploadLimitNextMonth.isSet()) { - w.writeFieldBegin(QStringLiteral("uploadLimitNextMonth"), ThriftFieldType::T_I64, 3); - w.writeI64(s.uploadLimitNextMonth.ref()); - w.writeFieldEnd(); - } - if(s.premiumServiceStatus.isSet()) { - w.writeFieldBegin(QStringLiteral("premiumServiceStatus"), ThriftFieldType::T_I32, 4); - w.writeI32(static_cast(s.premiumServiceStatus.ref())); - w.writeFieldEnd(); - } - if(s.premiumOrderNumber.isSet()) { - w.writeFieldBegin(QStringLiteral("premiumOrderNumber"), ThriftFieldType::T_STRING, 5); - w.writeString(s.premiumOrderNumber.ref()); - w.writeFieldEnd(); - } - if(s.premiumCommerceService.isSet()) { - w.writeFieldBegin(QStringLiteral("premiumCommerceService"), ThriftFieldType::T_STRING, 6); - w.writeString(s.premiumCommerceService.ref()); - w.writeFieldEnd(); - } - if(s.premiumServiceStart.isSet()) { - w.writeFieldBegin(QStringLiteral("premiumServiceStart"), ThriftFieldType::T_I64, 7); - w.writeI64(s.premiumServiceStart.ref()); - w.writeFieldEnd(); - } - if(s.premiumServiceSKU.isSet()) { - w.writeFieldBegin(QStringLiteral("premiumServiceSKU"), ThriftFieldType::T_STRING, 8); - w.writeString(s.premiumServiceSKU.ref()); - w.writeFieldEnd(); - } - if(s.lastSuccessfulCharge.isSet()) { - w.writeFieldBegin(QStringLiteral("lastSuccessfulCharge"), ThriftFieldType::T_I64, 9); - w.writeI64(s.lastSuccessfulCharge.ref()); - w.writeFieldEnd(); - } - if(s.lastFailedCharge.isSet()) { - w.writeFieldBegin(QStringLiteral("lastFailedCharge"), ThriftFieldType::T_I64, 10); - w.writeI64(s.lastFailedCharge.ref()); - w.writeFieldEnd(); - } - if(s.lastFailedChargeReason.isSet()) { - w.writeFieldBegin(QStringLiteral("lastFailedChargeReason"), ThriftFieldType::T_STRING, 11); - w.writeString(s.lastFailedChargeReason.ref()); - w.writeFieldEnd(); - } - if(s.nextPaymentDue.isSet()) { - w.writeFieldBegin(QStringLiteral("nextPaymentDue"), ThriftFieldType::T_I64, 12); - w.writeI64(s.nextPaymentDue.ref()); - w.writeFieldEnd(); - } - if(s.premiumLockUntil.isSet()) { - w.writeFieldBegin(QStringLiteral("premiumLockUntil"), ThriftFieldType::T_I64, 13); - w.writeI64(s.premiumLockUntil.ref()); - w.writeFieldEnd(); - } - if(s.updated.isSet()) { - w.writeFieldBegin(QStringLiteral("updated"), ThriftFieldType::T_I64, 14); - w.writeI64(s.updated.ref()); - w.writeFieldEnd(); - } - if(s.premiumSubscriptionNumber.isSet()) { - w.writeFieldBegin(QStringLiteral("premiumSubscriptionNumber"), ThriftFieldType::T_STRING, 16); - w.writeString(s.premiumSubscriptionNumber.ref()); - w.writeFieldEnd(); - } - if(s.lastRequestedCharge.isSet()) { - w.writeFieldBegin(QStringLiteral("lastRequestedCharge"), ThriftFieldType::T_I64, 17); - w.writeI64(s.lastRequestedCharge.ref()); - w.writeFieldEnd(); - } - if(s.currency.isSet()) { - w.writeFieldBegin(QStringLiteral("currency"), ThriftFieldType::T_STRING, 18); - w.writeString(s.currency.ref()); - w.writeFieldEnd(); - } - if(s.unitPrice.isSet()) { - w.writeFieldBegin(QStringLiteral("unitPrice"), ThriftFieldType::T_I32, 19); - w.writeI32(s.unitPrice.ref()); - w.writeFieldEnd(); - } - if(s.businessId.isSet()) { - w.writeFieldBegin(QStringLiteral("businessId"), ThriftFieldType::T_I32, 20); - w.writeI32(s.businessId.ref()); - w.writeFieldEnd(); - } - if(s.businessName.isSet()) { - w.writeFieldBegin(QStringLiteral("businessName"), ThriftFieldType::T_STRING, 21); - w.writeString(s.businessName.ref()); - w.writeFieldEnd(); - } - if(s.businessRole.isSet()) { - w.writeFieldBegin(QStringLiteral("businessRole"), ThriftFieldType::T_I32, 22); - w.writeI32(static_cast(s.businessRole.ref())); - w.writeFieldEnd(); - } - if(s.unitDiscount.isSet()) { - w.writeFieldBegin(QStringLiteral("unitDiscount"), ThriftFieldType::T_I32, 23); - w.writeI32(s.unitDiscount.ref()); - w.writeFieldEnd(); - } - if(s.nextChargeDate.isSet()) { - w.writeFieldBegin(QStringLiteral("nextChargeDate"), ThriftFieldType::T_I64, 24); - w.writeI64(s.nextChargeDate.ref()); - w.writeFieldEnd(); - } - if(s.availablePoints.isSet()) { - w.writeFieldBegin(QStringLiteral("availablePoints"), ThriftFieldType::T_I32, 25); - w.writeI32(s.availablePoints.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readAccounting(ThriftBinaryBufferReader & r, Accounting & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.uploadLimitEnd = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.uploadLimitNextMonth = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_I32) { - PremiumOrderStatus::type v; - readEnumPremiumOrderStatus(r, v); - s.premiumServiceStatus = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.premiumOrderNumber = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.premiumCommerceService = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.premiumServiceStart = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.premiumServiceSKU = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.lastSuccessfulCharge = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.lastFailedCharge = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.lastFailedChargeReason = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.nextPaymentDue = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.premiumLockUntil = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 14) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.updated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 16) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.premiumSubscriptionNumber = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 17) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.lastRequestedCharge = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 18) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.currency = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 19) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.unitPrice = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 20) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.businessId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 21) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.businessName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 22) { - if (fieldType == ThriftFieldType::T_I32) { - BusinessUserRole::type v; - readEnumBusinessUserRole(r, v); - s.businessRole = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 23) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.unitDiscount = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 24) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.nextChargeDate = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 25) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.availablePoints = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeBusinessUserInfo(ThriftBinaryBufferWriter & w, const BusinessUserInfo & s) { - w.writeStructBegin(QStringLiteral("BusinessUserInfo")); - if(s.businessId.isSet()) { - w.writeFieldBegin(QStringLiteral("businessId"), ThriftFieldType::T_I32, 1); - w.writeI32(s.businessId.ref()); - w.writeFieldEnd(); - } - if(s.businessName.isSet()) { - w.writeFieldBegin(QStringLiteral("businessName"), ThriftFieldType::T_STRING, 2); - w.writeString(s.businessName.ref()); - w.writeFieldEnd(); - } - if(s.role.isSet()) { - w.writeFieldBegin(QStringLiteral("role"), ThriftFieldType::T_I32, 3); - w.writeI32(static_cast(s.role.ref())); - w.writeFieldEnd(); - } - if(s.email.isSet()) { - w.writeFieldBegin(QStringLiteral("email"), ThriftFieldType::T_STRING, 4); - w.writeString(s.email.ref()); - w.writeFieldEnd(); - } - if(s.updated.isSet()) { - w.writeFieldBegin(QStringLiteral("updated"), ThriftFieldType::T_I64, 5); - w.writeI64(s.updated.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readBusinessUserInfo(ThriftBinaryBufferReader & r, BusinessUserInfo & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.businessId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.businessName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - BusinessUserRole::type v; - readEnumBusinessUserRole(r, v); - s.role = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.email = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.updated = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeAccountLimits(ThriftBinaryBufferWriter & w, const AccountLimits & s) { - w.writeStructBegin(QStringLiteral("AccountLimits")); - if(s.userMailLimitDaily.isSet()) { - w.writeFieldBegin(QStringLiteral("userMailLimitDaily"), ThriftFieldType::T_I32, 1); - w.writeI32(s.userMailLimitDaily.ref()); - w.writeFieldEnd(); - } - if(s.noteSizeMax.isSet()) { - w.writeFieldBegin(QStringLiteral("noteSizeMax"), ThriftFieldType::T_I64, 2); - w.writeI64(s.noteSizeMax.ref()); - w.writeFieldEnd(); - } - if(s.resourceSizeMax.isSet()) { - w.writeFieldBegin(QStringLiteral("resourceSizeMax"), ThriftFieldType::T_I64, 3); - w.writeI64(s.resourceSizeMax.ref()); - w.writeFieldEnd(); - } - if(s.userLinkedNotebookMax.isSet()) { - w.writeFieldBegin(QStringLiteral("userLinkedNotebookMax"), ThriftFieldType::T_I32, 4); - w.writeI32(s.userLinkedNotebookMax.ref()); - w.writeFieldEnd(); - } - if(s.uploadLimit.isSet()) { - w.writeFieldBegin(QStringLiteral("uploadLimit"), ThriftFieldType::T_I64, 5); - w.writeI64(s.uploadLimit.ref()); - w.writeFieldEnd(); - } - if(s.userNoteCountMax.isSet()) { - w.writeFieldBegin(QStringLiteral("userNoteCountMax"), ThriftFieldType::T_I32, 6); - w.writeI32(s.userNoteCountMax.ref()); - w.writeFieldEnd(); - } - if(s.userNotebookCountMax.isSet()) { - w.writeFieldBegin(QStringLiteral("userNotebookCountMax"), ThriftFieldType::T_I32, 7); - w.writeI32(s.userNotebookCountMax.ref()); - w.writeFieldEnd(); - } - if(s.userTagCountMax.isSet()) { - w.writeFieldBegin(QStringLiteral("userTagCountMax"), ThriftFieldType::T_I32, 8); - w.writeI32(s.userTagCountMax.ref()); - w.writeFieldEnd(); - } - if(s.noteTagCountMax.isSet()) { - w.writeFieldBegin(QStringLiteral("noteTagCountMax"), ThriftFieldType::T_I32, 9); - w.writeI32(s.noteTagCountMax.ref()); - w.writeFieldEnd(); - } - if(s.userSavedSearchesMax.isSet()) { - w.writeFieldBegin(QStringLiteral("userSavedSearchesMax"), ThriftFieldType::T_I32, 10); - w.writeI32(s.userSavedSearchesMax.ref()); - w.writeFieldEnd(); - } - if(s.noteResourceCountMax.isSet()) { - w.writeFieldBegin(QStringLiteral("noteResourceCountMax"), ThriftFieldType::T_I32, 11); - w.writeI32(s.noteResourceCountMax.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readAccountLimits(ThriftBinaryBufferReader & r, AccountLimits & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.userMailLimitDaily = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.noteSizeMax = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.resourceSizeMax = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.userLinkedNotebookMax = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.uploadLimit = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.userNoteCountMax = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.userNotebookCountMax = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.userTagCountMax = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.noteTagCountMax = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.userSavedSearchesMax = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.noteResourceCountMax = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeUser(ThriftBinaryBufferWriter & w, const User & s) { - w.writeStructBegin(QStringLiteral("User")); - if(s.id.isSet()) { - w.writeFieldBegin(QStringLiteral("id"), ThriftFieldType::T_I32, 1); - w.writeI32(s.id.ref()); - w.writeFieldEnd(); - } - if(s.username.isSet()) { - w.writeFieldBegin(QStringLiteral("username"), ThriftFieldType::T_STRING, 2); - w.writeString(s.username.ref()); - w.writeFieldEnd(); - } - if(s.email.isSet()) { - w.writeFieldBegin(QStringLiteral("email"), ThriftFieldType::T_STRING, 3); - w.writeString(s.email.ref()); - w.writeFieldEnd(); - } - if(s.name.isSet()) { - w.writeFieldBegin(QStringLiteral("name"), ThriftFieldType::T_STRING, 4); - w.writeString(s.name.ref()); - w.writeFieldEnd(); - } - if(s.timezone.isSet()) { - w.writeFieldBegin(QStringLiteral("timezone"), ThriftFieldType::T_STRING, 6); - w.writeString(s.timezone.ref()); - w.writeFieldEnd(); - } - if(s.privilege.isSet()) { - w.writeFieldBegin(QStringLiteral("privilege"), ThriftFieldType::T_I32, 7); - w.writeI32(static_cast(s.privilege.ref())); - w.writeFieldEnd(); - } - if(s.serviceLevel.isSet()) { - w.writeFieldBegin(QStringLiteral("serviceLevel"), ThriftFieldType::T_I32, 21); - w.writeI32(static_cast(s.serviceLevel.ref())); - w.writeFieldEnd(); - } - if(s.created.isSet()) { - w.writeFieldBegin(QStringLiteral("created"), ThriftFieldType::T_I64, 9); - w.writeI64(s.created.ref()); - w.writeFieldEnd(); - } - if(s.updated.isSet()) { - w.writeFieldBegin(QStringLiteral("updated"), ThriftFieldType::T_I64, 10); - w.writeI64(s.updated.ref()); - w.writeFieldEnd(); - } - if(s.deleted.isSet()) { - w.writeFieldBegin(QStringLiteral("deleted"), ThriftFieldType::T_I64, 11); - w.writeI64(s.deleted.ref()); - w.writeFieldEnd(); - } - if(s.active.isSet()) { - w.writeFieldBegin(QStringLiteral("active"), ThriftFieldType::T_BOOL, 13); - w.writeBool(s.active.ref()); - w.writeFieldEnd(); - } - if(s.shardId.isSet()) { - w.writeFieldBegin(QStringLiteral("shardId"), ThriftFieldType::T_STRING, 14); - w.writeString(s.shardId.ref()); - w.writeFieldEnd(); - } - if(s.attributes.isSet()) { - w.writeFieldBegin(QStringLiteral("attributes"), ThriftFieldType::T_STRUCT, 15); - writeUserAttributes(w, s.attributes.ref()); - w.writeFieldEnd(); - } - if(s.accounting.isSet()) { - w.writeFieldBegin(QStringLiteral("accounting"), ThriftFieldType::T_STRUCT, 16); - writeAccounting(w, s.accounting.ref()); - w.writeFieldEnd(); - } - if(s.businessUserInfo.isSet()) { - w.writeFieldBegin(QStringLiteral("businessUserInfo"), ThriftFieldType::T_STRUCT, 18); - writeBusinessUserInfo(w, s.businessUserInfo.ref()); - w.writeFieldEnd(); - } - if(s.photoUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("photoUrl"), ThriftFieldType::T_STRING, 19); - w.writeString(s.photoUrl.ref()); - w.writeFieldEnd(); - } - if(s.photoLastUpdated.isSet()) { - w.writeFieldBegin(QStringLiteral("photoLastUpdated"), ThriftFieldType::T_I64, 20); - w.writeI64(s.photoLastUpdated.ref()); - w.writeFieldEnd(); - } - if(s.accountLimits.isSet()) { - w.writeFieldBegin(QStringLiteral("accountLimits"), ThriftFieldType::T_STRUCT, 22); - writeAccountLimits(w, s.accountLimits.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readUser(ThriftBinaryBufferReader & r, User & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.id = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.username = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.email = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.name = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.timezone = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I32) { - PrivilegeLevel::type v; - readEnumPrivilegeLevel(r, v); - s.privilege = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 21) { - if (fieldType == ThriftFieldType::T_I32) { - ServiceLevel::type v; - readEnumServiceLevel(r, v); - s.serviceLevel = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.created = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.updated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.deleted = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.active = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 14) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.shardId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 15) { - if (fieldType == ThriftFieldType::T_STRUCT) { - UserAttributes v; - readUserAttributes(r, v); - s.attributes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 16) { - if (fieldType == ThriftFieldType::T_STRUCT) { - Accounting v; - readAccounting(r, v); - s.accounting = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 18) { - if (fieldType == ThriftFieldType::T_STRUCT) { - BusinessUserInfo v; - readBusinessUserInfo(r, v); - s.businessUserInfo = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 19) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.photoUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 20) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.photoLastUpdated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 22) { - if (fieldType == ThriftFieldType::T_STRUCT) { - AccountLimits v; - readAccountLimits(r, v); - s.accountLimits = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeContact(ThriftBinaryBufferWriter & w, const Contact & s) { - w.writeStructBegin(QStringLiteral("Contact")); - if(s.name.isSet()) { - w.writeFieldBegin(QStringLiteral("name"), ThriftFieldType::T_STRING, 1); - w.writeString(s.name.ref()); - w.writeFieldEnd(); - } - if(s.id.isSet()) { - w.writeFieldBegin(QStringLiteral("id"), ThriftFieldType::T_STRING, 2); - w.writeString(s.id.ref()); - w.writeFieldEnd(); - } - if(s.type.isSet()) { - w.writeFieldBegin(QStringLiteral("type"), ThriftFieldType::T_I32, 3); - w.writeI32(static_cast(s.type.ref())); - w.writeFieldEnd(); - } - if(s.photoUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("photoUrl"), ThriftFieldType::T_STRING, 4); - w.writeString(s.photoUrl.ref()); - w.writeFieldEnd(); - } - if(s.photoLastUpdated.isSet()) { - w.writeFieldBegin(QStringLiteral("photoLastUpdated"), ThriftFieldType::T_I64, 5); - w.writeI64(s.photoLastUpdated.ref()); - w.writeFieldEnd(); - } - if(s.messagingPermit.isSet()) { - w.writeFieldBegin(QStringLiteral("messagingPermit"), ThriftFieldType::T_STRING, 6); - w.writeBinary(s.messagingPermit.ref()); - w.writeFieldEnd(); - } - if(s.messagingPermitExpires.isSet()) { - w.writeFieldBegin(QStringLiteral("messagingPermitExpires"), ThriftFieldType::T_I64, 7); - w.writeI64(s.messagingPermitExpires.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readContact(ThriftBinaryBufferReader & r, Contact & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.name = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.id = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - ContactType::type v; - readEnumContactType(r, v); - s.type = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.photoUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.photoLastUpdated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QByteArray v; - r.readBinary(v); - s.messagingPermit = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.messagingPermitExpires = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeIdentity(ThriftBinaryBufferWriter & w, const Identity & s) { - w.writeStructBegin(QStringLiteral("Identity")); - w.writeFieldBegin(QStringLiteral("id"), ThriftFieldType::T_I64, 1); - w.writeI64(s.id); - w.writeFieldEnd(); - if(s.contact.isSet()) { - w.writeFieldBegin(QStringLiteral("contact"), ThriftFieldType::T_STRUCT, 2); - writeContact(w, s.contact.ref()); - w.writeFieldEnd(); - } - if(s.userId.isSet()) { - w.writeFieldBegin(QStringLiteral("userId"), ThriftFieldType::T_I32, 3); - w.writeI32(s.userId.ref()); - w.writeFieldEnd(); - } - if(s.deactivated.isSet()) { - w.writeFieldBegin(QStringLiteral("deactivated"), ThriftFieldType::T_BOOL, 4); - w.writeBool(s.deactivated.ref()); - w.writeFieldEnd(); - } - if(s.sameBusiness.isSet()) { - w.writeFieldBegin(QStringLiteral("sameBusiness"), ThriftFieldType::T_BOOL, 5); - w.writeBool(s.sameBusiness.ref()); - w.writeFieldEnd(); - } - if(s.blocked.isSet()) { - w.writeFieldBegin(QStringLiteral("blocked"), ThriftFieldType::T_BOOL, 6); - w.writeBool(s.blocked.ref()); - w.writeFieldEnd(); - } - if(s.userConnected.isSet()) { - w.writeFieldBegin(QStringLiteral("userConnected"), ThriftFieldType::T_BOOL, 7); - w.writeBool(s.userConnected.ref()); - w.writeFieldEnd(); - } - if(s.eventId.isSet()) { - w.writeFieldBegin(QStringLiteral("eventId"), ThriftFieldType::T_I64, 8); - w.writeI64(s.eventId.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readIdentity(ThriftBinaryBufferReader & r, Identity & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool id_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I64) { - id_isset = true; - IdentityID v; - r.readI64(v); - s.id = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - Contact v; - readContact(r, v); - s.contact = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.userId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.deactivated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.sameBusiness = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.blocked = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.userConnected = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_I64) { - MessageEventID v; - r.readI64(v); - s.eventId = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!id_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Identity.id has no value")); -} - -void writeTag(ThriftBinaryBufferWriter & w, const Tag & s) { - w.writeStructBegin(QStringLiteral("Tag")); - if(s.guid.isSet()) { - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.guid.ref()); - w.writeFieldEnd(); - } - if(s.name.isSet()) { - w.writeFieldBegin(QStringLiteral("name"), ThriftFieldType::T_STRING, 2); - w.writeString(s.name.ref()); - w.writeFieldEnd(); - } - if(s.parentGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("parentGuid"), ThriftFieldType::T_STRING, 3); - w.writeString(s.parentGuid.ref()); - w.writeFieldEnd(); - } - if(s.updateSequenceNum.isSet()) { - w.writeFieldBegin(QStringLiteral("updateSequenceNum"), ThriftFieldType::T_I32, 4); - w.writeI32(s.updateSequenceNum.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readTag(ThriftBinaryBufferReader & r, Tag & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.guid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.name = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.parentGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.updateSequenceNum = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeLazyMap(ThriftBinaryBufferWriter & w, const LazyMap & s) { - w.writeStructBegin(QStringLiteral("LazyMap")); - if(s.keysOnly.isSet()) { - w.writeFieldBegin(QStringLiteral("keysOnly"), ThriftFieldType::T_SET, 1); - w.writeSetBegin(ThriftFieldType::T_STRING, s.keysOnly.ref().count()); - for(QSet< QString >::const_iterator it = s.keysOnly.ref().constBegin(), end = s.keysOnly.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeSetEnd(); - w.writeFieldEnd(); - } - if(s.fullMap.isSet()) { - w.writeFieldBegin(QStringLiteral("fullMap"), ThriftFieldType::T_MAP, 2); - w.writeMapBegin(ThriftFieldType::T_STRING, ThriftFieldType::T_STRING, s.fullMap.ref().size()); - for(QMap< QString, QString >::const_iterator it = s.fullMap.ref().constBegin(), end = s.fullMap.ref().constEnd(); it != end; ++it) { - w.writeString(it.key()); - w.writeString(it.value()); - } - w.writeMapEnd(); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readLazyMap(ThriftBinaryBufferReader & r, LazyMap & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_SET) { - QSet< QString > v; - qint32 size; - ThriftFieldType::type elemType; - r.readSetBegin(elemType, size); - v.reserve(size); - if (elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect set type (LazyMap.keysOnly)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.insert(elem); - } - r.readSetEnd(); - s.keysOnly = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_MAP) { - QMap< QString, QString > v; - qint32 size; - ThriftFieldType::type keyType; - ThriftFieldType::type elemType; - r.readMapBegin(keyType, elemType, size); - if (keyType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map key type (LazyMap.fullMap)")); - if (elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map value type (LazyMap.fullMap)")); - for(qint32 i = 0; i < size; i++) { - QString key; - r.readString(key); - QString value; - r.readString(value); - v[key] = value; - } - r.readMapEnd(); - s.fullMap = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeResourceAttributes(ThriftBinaryBufferWriter & w, const ResourceAttributes & s) { - w.writeStructBegin(QStringLiteral("ResourceAttributes")); - if(s.sourceURL.isSet()) { - w.writeFieldBegin(QStringLiteral("sourceURL"), ThriftFieldType::T_STRING, 1); - w.writeString(s.sourceURL.ref()); - w.writeFieldEnd(); - } - if(s.timestamp.isSet()) { - w.writeFieldBegin(QStringLiteral("timestamp"), ThriftFieldType::T_I64, 2); - w.writeI64(s.timestamp.ref()); - w.writeFieldEnd(); - } - if(s.latitude.isSet()) { - w.writeFieldBegin(QStringLiteral("latitude"), ThriftFieldType::T_DOUBLE, 3); - w.writeDouble(s.latitude.ref()); - w.writeFieldEnd(); - } - if(s.longitude.isSet()) { - w.writeFieldBegin(QStringLiteral("longitude"), ThriftFieldType::T_DOUBLE, 4); - w.writeDouble(s.longitude.ref()); - w.writeFieldEnd(); - } - if(s.altitude.isSet()) { - w.writeFieldBegin(QStringLiteral("altitude"), ThriftFieldType::T_DOUBLE, 5); - w.writeDouble(s.altitude.ref()); - w.writeFieldEnd(); - } - if(s.cameraMake.isSet()) { - w.writeFieldBegin(QStringLiteral("cameraMake"), ThriftFieldType::T_STRING, 6); - w.writeString(s.cameraMake.ref()); - w.writeFieldEnd(); - } - if(s.cameraModel.isSet()) { - w.writeFieldBegin(QStringLiteral("cameraModel"), ThriftFieldType::T_STRING, 7); - w.writeString(s.cameraModel.ref()); - w.writeFieldEnd(); - } - if(s.clientWillIndex.isSet()) { - w.writeFieldBegin(QStringLiteral("clientWillIndex"), ThriftFieldType::T_BOOL, 8); - w.writeBool(s.clientWillIndex.ref()); - w.writeFieldEnd(); - } - if(s.recoType.isSet()) { - w.writeFieldBegin(QStringLiteral("recoType"), ThriftFieldType::T_STRING, 9); - w.writeString(s.recoType.ref()); - w.writeFieldEnd(); - } - if(s.fileName.isSet()) { - w.writeFieldBegin(QStringLiteral("fileName"), ThriftFieldType::T_STRING, 10); - w.writeString(s.fileName.ref()); - w.writeFieldEnd(); - } - if(s.attachment.isSet()) { - w.writeFieldBegin(QStringLiteral("attachment"), ThriftFieldType::T_BOOL, 11); - w.writeBool(s.attachment.ref()); - w.writeFieldEnd(); - } - if(s.applicationData.isSet()) { - w.writeFieldBegin(QStringLiteral("applicationData"), ThriftFieldType::T_STRUCT, 12); - writeLazyMap(w, s.applicationData.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readResourceAttributes(ThriftBinaryBufferReader & r, ResourceAttributes & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.sourceURL = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.timestamp = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_DOUBLE) { - double v; - r.readDouble(v); - s.latitude = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_DOUBLE) { - double v; - r.readDouble(v); - s.longitude = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_DOUBLE) { - double v; - r.readDouble(v); - s.altitude = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.cameraMake = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.cameraModel = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.clientWillIndex = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.recoType = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.fileName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.attachment = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_STRUCT) { - LazyMap v; - readLazyMap(r, v); - s.applicationData = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeResource(ThriftBinaryBufferWriter & w, const Resource & s) { - w.writeStructBegin(QStringLiteral("Resource")); - if(s.guid.isSet()) { - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.guid.ref()); - w.writeFieldEnd(); - } - if(s.noteGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("noteGuid"), ThriftFieldType::T_STRING, 2); - w.writeString(s.noteGuid.ref()); - w.writeFieldEnd(); - } - if(s.data.isSet()) { - w.writeFieldBegin(QStringLiteral("data"), ThriftFieldType::T_STRUCT, 3); - writeData(w, s.data.ref()); - w.writeFieldEnd(); - } - if(s.mime.isSet()) { - w.writeFieldBegin(QStringLiteral("mime"), ThriftFieldType::T_STRING, 4); - w.writeString(s.mime.ref()); - w.writeFieldEnd(); - } - if(s.width.isSet()) { - w.writeFieldBegin(QStringLiteral("width"), ThriftFieldType::T_I16, 5); - w.writeI16(s.width.ref()); - w.writeFieldEnd(); - } - if(s.height.isSet()) { - w.writeFieldBegin(QStringLiteral("height"), ThriftFieldType::T_I16, 6); - w.writeI16(s.height.ref()); - w.writeFieldEnd(); - } - if(s.duration.isSet()) { - w.writeFieldBegin(QStringLiteral("duration"), ThriftFieldType::T_I16, 7); - w.writeI16(s.duration.ref()); - w.writeFieldEnd(); - } - if(s.active.isSet()) { - w.writeFieldBegin(QStringLiteral("active"), ThriftFieldType::T_BOOL, 8); - w.writeBool(s.active.ref()); - w.writeFieldEnd(); - } - if(s.recognition.isSet()) { - w.writeFieldBegin(QStringLiteral("recognition"), ThriftFieldType::T_STRUCT, 9); - writeData(w, s.recognition.ref()); - w.writeFieldEnd(); - } - if(s.attributes.isSet()) { - w.writeFieldBegin(QStringLiteral("attributes"), ThriftFieldType::T_STRUCT, 11); - writeResourceAttributes(w, s.attributes.ref()); - w.writeFieldEnd(); - } - if(s.updateSequenceNum.isSet()) { - w.writeFieldBegin(QStringLiteral("updateSequenceNum"), ThriftFieldType::T_I32, 12); - w.writeI32(s.updateSequenceNum.ref()); - w.writeFieldEnd(); - } - if(s.alternateData.isSet()) { - w.writeFieldBegin(QStringLiteral("alternateData"), ThriftFieldType::T_STRUCT, 13); - writeData(w, s.alternateData.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readResource(ThriftBinaryBufferReader & r, Resource & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.guid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.noteGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRUCT) { - Data v; - readData(r, v); - s.data = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.mime = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I16) { - qint16 v; - r.readI16(v); - s.width = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_I16) { - qint16 v; - r.readI16(v); - s.height = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I16) { - qint16 v; - r.readI16(v); - s.duration = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.active = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_STRUCT) { - Data v; - readData(r, v); - s.recognition = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_STRUCT) { - ResourceAttributes v; - readResourceAttributes(r, v); - s.attributes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.updateSequenceNum = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_STRUCT) { - Data v; - readData(r, v); - s.alternateData = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteAttributes(ThriftBinaryBufferWriter & w, const NoteAttributes & s) { - w.writeStructBegin(QStringLiteral("NoteAttributes")); - if(s.subjectDate.isSet()) { - w.writeFieldBegin(QStringLiteral("subjectDate"), ThriftFieldType::T_I64, 1); - w.writeI64(s.subjectDate.ref()); - w.writeFieldEnd(); - } - if(s.latitude.isSet()) { - w.writeFieldBegin(QStringLiteral("latitude"), ThriftFieldType::T_DOUBLE, 10); - w.writeDouble(s.latitude.ref()); - w.writeFieldEnd(); - } - if(s.longitude.isSet()) { - w.writeFieldBegin(QStringLiteral("longitude"), ThriftFieldType::T_DOUBLE, 11); - w.writeDouble(s.longitude.ref()); - w.writeFieldEnd(); - } - if(s.altitude.isSet()) { - w.writeFieldBegin(QStringLiteral("altitude"), ThriftFieldType::T_DOUBLE, 12); - w.writeDouble(s.altitude.ref()); - w.writeFieldEnd(); - } - if(s.author.isSet()) { - w.writeFieldBegin(QStringLiteral("author"), ThriftFieldType::T_STRING, 13); - w.writeString(s.author.ref()); - w.writeFieldEnd(); - } - if(s.source.isSet()) { - w.writeFieldBegin(QStringLiteral("source"), ThriftFieldType::T_STRING, 14); - w.writeString(s.source.ref()); - w.writeFieldEnd(); - } - if(s.sourceURL.isSet()) { - w.writeFieldBegin(QStringLiteral("sourceURL"), ThriftFieldType::T_STRING, 15); - w.writeString(s.sourceURL.ref()); - w.writeFieldEnd(); - } - if(s.sourceApplication.isSet()) { - w.writeFieldBegin(QStringLiteral("sourceApplication"), ThriftFieldType::T_STRING, 16); - w.writeString(s.sourceApplication.ref()); - w.writeFieldEnd(); - } - if(s.shareDate.isSet()) { - w.writeFieldBegin(QStringLiteral("shareDate"), ThriftFieldType::T_I64, 17); - w.writeI64(s.shareDate.ref()); - w.writeFieldEnd(); - } - if(s.reminderOrder.isSet()) { - w.writeFieldBegin(QStringLiteral("reminderOrder"), ThriftFieldType::T_I64, 18); - w.writeI64(s.reminderOrder.ref()); - w.writeFieldEnd(); - } - if(s.reminderDoneTime.isSet()) { - w.writeFieldBegin(QStringLiteral("reminderDoneTime"), ThriftFieldType::T_I64, 19); - w.writeI64(s.reminderDoneTime.ref()); - w.writeFieldEnd(); - } - if(s.reminderTime.isSet()) { - w.writeFieldBegin(QStringLiteral("reminderTime"), ThriftFieldType::T_I64, 20); - w.writeI64(s.reminderTime.ref()); - w.writeFieldEnd(); - } - if(s.placeName.isSet()) { - w.writeFieldBegin(QStringLiteral("placeName"), ThriftFieldType::T_STRING, 21); - w.writeString(s.placeName.ref()); - w.writeFieldEnd(); - } - if(s.contentClass.isSet()) { - w.writeFieldBegin(QStringLiteral("contentClass"), ThriftFieldType::T_STRING, 22); - w.writeString(s.contentClass.ref()); - w.writeFieldEnd(); - } - if(s.applicationData.isSet()) { - w.writeFieldBegin(QStringLiteral("applicationData"), ThriftFieldType::T_STRUCT, 23); - writeLazyMap(w, s.applicationData.ref()); - w.writeFieldEnd(); - } - if(s.lastEditedBy.isSet()) { - w.writeFieldBegin(QStringLiteral("lastEditedBy"), ThriftFieldType::T_STRING, 24); - w.writeString(s.lastEditedBy.ref()); - w.writeFieldEnd(); - } - if(s.classifications.isSet()) { - w.writeFieldBegin(QStringLiteral("classifications"), ThriftFieldType::T_MAP, 26); - w.writeMapBegin(ThriftFieldType::T_STRING, ThriftFieldType::T_STRING, s.classifications.ref().size()); - for(QMap< QString, QString >::const_iterator it = s.classifications.ref().constBegin(), end = s.classifications.ref().constEnd(); it != end; ++it) { - w.writeString(it.key()); - w.writeString(it.value()); - } - w.writeMapEnd(); - w.writeFieldEnd(); - } - if(s.creatorId.isSet()) { - w.writeFieldBegin(QStringLiteral("creatorId"), ThriftFieldType::T_I32, 27); - w.writeI32(s.creatorId.ref()); - w.writeFieldEnd(); - } - if(s.lastEditorId.isSet()) { - w.writeFieldBegin(QStringLiteral("lastEditorId"), ThriftFieldType::T_I32, 28); - w.writeI32(s.lastEditorId.ref()); - w.writeFieldEnd(); - } - if(s.sharedWithBusiness.isSet()) { - w.writeFieldBegin(QStringLiteral("sharedWithBusiness"), ThriftFieldType::T_BOOL, 29); - w.writeBool(s.sharedWithBusiness.ref()); - w.writeFieldEnd(); - } - if(s.conflictSourceNoteGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("conflictSourceNoteGuid"), ThriftFieldType::T_STRING, 30); - w.writeString(s.conflictSourceNoteGuid.ref()); - w.writeFieldEnd(); - } - if(s.noteTitleQuality.isSet()) { - w.writeFieldBegin(QStringLiteral("noteTitleQuality"), ThriftFieldType::T_I32, 31); - w.writeI32(s.noteTitleQuality.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteAttributes(ThriftBinaryBufferReader & r, NoteAttributes & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.subjectDate = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_DOUBLE) { - double v; - r.readDouble(v); - s.latitude = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_DOUBLE) { - double v; - r.readDouble(v); - s.longitude = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_DOUBLE) { - double v; - r.readDouble(v); - s.altitude = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.author = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 14) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.source = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 15) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.sourceURL = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 16) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.sourceApplication = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 17) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.shareDate = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 18) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.reminderOrder = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 19) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.reminderDoneTime = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 20) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.reminderTime = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 21) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.placeName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 22) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.contentClass = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 23) { - if (fieldType == ThriftFieldType::T_STRUCT) { - LazyMap v; - readLazyMap(r, v); - s.applicationData = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 24) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.lastEditedBy = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 26) { - if (fieldType == ThriftFieldType::T_MAP) { - QMap< QString, QString > v; - qint32 size; - ThriftFieldType::type keyType; - ThriftFieldType::type elemType; - r.readMapBegin(keyType, elemType, size); - if (keyType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map key type (NoteAttributes.classifications)")); - if (elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect map value type (NoteAttributes.classifications)")); - for(qint32 i = 0; i < size; i++) { - QString key; - r.readString(key); - QString value; - r.readString(value); - v[key] = value; - } - r.readMapEnd(); - s.classifications = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 27) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.creatorId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 28) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.lastEditorId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 29) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.sharedWithBusiness = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 30) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.conflictSourceNoteGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 31) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.noteTitleQuality = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeSharedNote(ThriftBinaryBufferWriter & w, const SharedNote & s) { - w.writeStructBegin(QStringLiteral("SharedNote")); - if(s.sharerUserID.isSet()) { - w.writeFieldBegin(QStringLiteral("sharerUserID"), ThriftFieldType::T_I32, 1); - w.writeI32(s.sharerUserID.ref()); - w.writeFieldEnd(); - } - if(s.recipientIdentity.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientIdentity"), ThriftFieldType::T_STRUCT, 2); - writeIdentity(w, s.recipientIdentity.ref()); - w.writeFieldEnd(); - } - if(s.privilege.isSet()) { - w.writeFieldBegin(QStringLiteral("privilege"), ThriftFieldType::T_I32, 3); - w.writeI32(static_cast(s.privilege.ref())); - w.writeFieldEnd(); - } - if(s.serviceCreated.isSet()) { - w.writeFieldBegin(QStringLiteral("serviceCreated"), ThriftFieldType::T_I64, 4); - w.writeI64(s.serviceCreated.ref()); - w.writeFieldEnd(); - } - if(s.serviceUpdated.isSet()) { - w.writeFieldBegin(QStringLiteral("serviceUpdated"), ThriftFieldType::T_I64, 5); - w.writeI64(s.serviceUpdated.ref()); - w.writeFieldEnd(); - } - if(s.serviceAssigned.isSet()) { - w.writeFieldBegin(QStringLiteral("serviceAssigned"), ThriftFieldType::T_I64, 6); - w.writeI64(s.serviceAssigned.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readSharedNote(ThriftBinaryBufferReader & r, SharedNote & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.sharerUserID = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - Identity v; - readIdentity(r, v); - s.recipientIdentity = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - SharedNotePrivilegeLevel::type v; - readEnumSharedNotePrivilegeLevel(r, v); - s.privilege = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.serviceCreated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.serviceUpdated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.serviceAssigned = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteRestrictions(ThriftBinaryBufferWriter & w, const NoteRestrictions & s) { - w.writeStructBegin(QStringLiteral("NoteRestrictions")); - if(s.noUpdateTitle.isSet()) { - w.writeFieldBegin(QStringLiteral("noUpdateTitle"), ThriftFieldType::T_BOOL, 1); - w.writeBool(s.noUpdateTitle.ref()); - w.writeFieldEnd(); - } - if(s.noUpdateContent.isSet()) { - w.writeFieldBegin(QStringLiteral("noUpdateContent"), ThriftFieldType::T_BOOL, 2); - w.writeBool(s.noUpdateContent.ref()); - w.writeFieldEnd(); - } - if(s.noEmail.isSet()) { - w.writeFieldBegin(QStringLiteral("noEmail"), ThriftFieldType::T_BOOL, 3); - w.writeBool(s.noEmail.ref()); - w.writeFieldEnd(); - } - if(s.noShare.isSet()) { - w.writeFieldBegin(QStringLiteral("noShare"), ThriftFieldType::T_BOOL, 4); - w.writeBool(s.noShare.ref()); - w.writeFieldEnd(); - } - if(s.noSharePublicly.isSet()) { - w.writeFieldBegin(QStringLiteral("noSharePublicly"), ThriftFieldType::T_BOOL, 5); - w.writeBool(s.noSharePublicly.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteRestrictions(ThriftBinaryBufferReader & r, NoteRestrictions & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noUpdateTitle = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noUpdateContent = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noEmail = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noShare = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSharePublicly = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNoteLimits(ThriftBinaryBufferWriter & w, const NoteLimits & s) { - w.writeStructBegin(QStringLiteral("NoteLimits")); - if(s.noteResourceCountMax.isSet()) { - w.writeFieldBegin(QStringLiteral("noteResourceCountMax"), ThriftFieldType::T_I32, 1); - w.writeI32(s.noteResourceCountMax.ref()); - w.writeFieldEnd(); - } - if(s.uploadLimit.isSet()) { - w.writeFieldBegin(QStringLiteral("uploadLimit"), ThriftFieldType::T_I64, 2); - w.writeI64(s.uploadLimit.ref()); - w.writeFieldEnd(); - } - if(s.resourceSizeMax.isSet()) { - w.writeFieldBegin(QStringLiteral("resourceSizeMax"), ThriftFieldType::T_I64, 3); - w.writeI64(s.resourceSizeMax.ref()); - w.writeFieldEnd(); - } - if(s.noteSizeMax.isSet()) { - w.writeFieldBegin(QStringLiteral("noteSizeMax"), ThriftFieldType::T_I64, 4); - w.writeI64(s.noteSizeMax.ref()); - w.writeFieldEnd(); - } - if(s.uploaded.isSet()) { - w.writeFieldBegin(QStringLiteral("uploaded"), ThriftFieldType::T_I64, 5); - w.writeI64(s.uploaded.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNoteLimits(ThriftBinaryBufferReader & r, NoteLimits & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.noteResourceCountMax = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.uploadLimit = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.resourceSizeMax = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.noteSizeMax = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.uploaded = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNote(ThriftBinaryBufferWriter & w, const Note & s) { - w.writeStructBegin(QStringLiteral("Note")); - if(s.guid.isSet()) { - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.guid.ref()); - w.writeFieldEnd(); - } - if(s.title.isSet()) { - w.writeFieldBegin(QStringLiteral("title"), ThriftFieldType::T_STRING, 2); - w.writeString(s.title.ref()); - w.writeFieldEnd(); - } - if(s.content.isSet()) { - w.writeFieldBegin(QStringLiteral("content"), ThriftFieldType::T_STRING, 3); - w.writeString(s.content.ref()); - w.writeFieldEnd(); - } - if(s.contentHash.isSet()) { - w.writeFieldBegin(QStringLiteral("contentHash"), ThriftFieldType::T_STRING, 4); - w.writeBinary(s.contentHash.ref()); - w.writeFieldEnd(); - } - if(s.contentLength.isSet()) { - w.writeFieldBegin(QStringLiteral("contentLength"), ThriftFieldType::T_I32, 5); - w.writeI32(s.contentLength.ref()); - w.writeFieldEnd(); - } - if(s.created.isSet()) { - w.writeFieldBegin(QStringLiteral("created"), ThriftFieldType::T_I64, 6); - w.writeI64(s.created.ref()); - w.writeFieldEnd(); - } - if(s.updated.isSet()) { - w.writeFieldBegin(QStringLiteral("updated"), ThriftFieldType::T_I64, 7); - w.writeI64(s.updated.ref()); - w.writeFieldEnd(); - } - if(s.deleted.isSet()) { - w.writeFieldBegin(QStringLiteral("deleted"), ThriftFieldType::T_I64, 8); - w.writeI64(s.deleted.ref()); - w.writeFieldEnd(); - } - if(s.active.isSet()) { - w.writeFieldBegin(QStringLiteral("active"), ThriftFieldType::T_BOOL, 9); - w.writeBool(s.active.ref()); - w.writeFieldEnd(); - } - if(s.updateSequenceNum.isSet()) { - w.writeFieldBegin(QStringLiteral("updateSequenceNum"), ThriftFieldType::T_I32, 10); - w.writeI32(s.updateSequenceNum.ref()); - w.writeFieldEnd(); - } - if(s.notebookGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("notebookGuid"), ThriftFieldType::T_STRING, 11); - w.writeString(s.notebookGuid.ref()); - w.writeFieldEnd(); - } - if(s.tagGuids.isSet()) { - w.writeFieldBegin(QStringLiteral("tagGuids"), ThriftFieldType::T_LIST, 12); - w.writeListBegin(ThriftFieldType::T_STRING, s.tagGuids.ref().length()); - for(QList< Guid >::const_iterator it = s.tagGuids.ref().constBegin(), end = s.tagGuids.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.resources.isSet()) { - w.writeFieldBegin(QStringLiteral("resources"), ThriftFieldType::T_LIST, 13); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.resources.ref().length()); - for(QList< Resource >::const_iterator it = s.resources.ref().constBegin(), end = s.resources.ref().constEnd(); it != end; ++it) { - writeResource(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.attributes.isSet()) { - w.writeFieldBegin(QStringLiteral("attributes"), ThriftFieldType::T_STRUCT, 14); - writeNoteAttributes(w, s.attributes.ref()); - w.writeFieldEnd(); - } - if(s.tagNames.isSet()) { - w.writeFieldBegin(QStringLiteral("tagNames"), ThriftFieldType::T_LIST, 15); - w.writeListBegin(ThriftFieldType::T_STRING, s.tagNames.ref().length()); - for(QStringList::const_iterator it = s.tagNames.ref().constBegin(), end = s.tagNames.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.sharedNotes.isSet()) { - w.writeFieldBegin(QStringLiteral("sharedNotes"), ThriftFieldType::T_LIST, 16); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.sharedNotes.ref().length()); - for(QList< SharedNote >::const_iterator it = s.sharedNotes.ref().constBegin(), end = s.sharedNotes.ref().constEnd(); it != end; ++it) { - writeSharedNote(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.restrictions.isSet()) { - w.writeFieldBegin(QStringLiteral("restrictions"), ThriftFieldType::T_STRUCT, 17); - writeNoteRestrictions(w, s.restrictions.ref()); - w.writeFieldEnd(); - } - if(s.limits.isSet()) { - w.writeFieldBegin(QStringLiteral("limits"), ThriftFieldType::T_STRUCT, 18); - writeNoteLimits(w, s.limits.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNote(ThriftBinaryBufferReader & r, Note & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.guid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.title = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.content = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QByteArray v; - r.readBinary(v); - s.contentHash = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.contentLength = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.created = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.updated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.deleted = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.active = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.updateSequenceNum = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.notebookGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Guid > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (Note.tagGuids)")); - for(qint32 i = 0; i < size; i++) { - Guid elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.tagGuids = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< Resource > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (Note.resources)")); - for(qint32 i = 0; i < size; i++) { - Resource elem; - readResource(r, elem); - v.append(elem); - } - r.readListEnd(); - s.resources = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 14) { - if (fieldType == ThriftFieldType::T_STRUCT) { - NoteAttributes v; - readNoteAttributes(r, v); - s.attributes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 15) { - if (fieldType == ThriftFieldType::T_LIST) { - QStringList v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (Note.tagNames)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.tagNames = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 16) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< SharedNote > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (Note.sharedNotes)")); - for(qint32 i = 0; i < size; i++) { - SharedNote elem; - readSharedNote(r, elem); - v.append(elem); - } - r.readListEnd(); - s.sharedNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 17) { - if (fieldType == ThriftFieldType::T_STRUCT) { - NoteRestrictions v; - readNoteRestrictions(r, v); - s.restrictions = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 18) { - if (fieldType == ThriftFieldType::T_STRUCT) { - NoteLimits v; - readNoteLimits(r, v); - s.limits = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writePublishing(ThriftBinaryBufferWriter & w, const Publishing & s) { - w.writeStructBegin(QStringLiteral("Publishing")); - if(s.uri.isSet()) { - w.writeFieldBegin(QStringLiteral("uri"), ThriftFieldType::T_STRING, 1); - w.writeString(s.uri.ref()); - w.writeFieldEnd(); - } - if(s.order.isSet()) { - w.writeFieldBegin(QStringLiteral("order"), ThriftFieldType::T_I32, 2); - w.writeI32(static_cast(s.order.ref())); - w.writeFieldEnd(); - } - if(s.ascending.isSet()) { - w.writeFieldBegin(QStringLiteral("ascending"), ThriftFieldType::T_BOOL, 3); - w.writeBool(s.ascending.ref()); - w.writeFieldEnd(); - } - if(s.publicDescription.isSet()) { - w.writeFieldBegin(QStringLiteral("publicDescription"), ThriftFieldType::T_STRING, 4); - w.writeString(s.publicDescription.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readPublishing(ThriftBinaryBufferReader & r, Publishing & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.uri = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I32) { - NoteSortOrder::type v; - readEnumNoteSortOrder(r, v); - s.order = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.ascending = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.publicDescription = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeBusinessNotebook(ThriftBinaryBufferWriter & w, const BusinessNotebook & s) { - w.writeStructBegin(QStringLiteral("BusinessNotebook")); - if(s.notebookDescription.isSet()) { - w.writeFieldBegin(QStringLiteral("notebookDescription"), ThriftFieldType::T_STRING, 1); - w.writeString(s.notebookDescription.ref()); - w.writeFieldEnd(); - } - if(s.privilege.isSet()) { - w.writeFieldBegin(QStringLiteral("privilege"), ThriftFieldType::T_I32, 2); - w.writeI32(static_cast(s.privilege.ref())); - w.writeFieldEnd(); - } - if(s.recommended.isSet()) { - w.writeFieldBegin(QStringLiteral("recommended"), ThriftFieldType::T_BOOL, 3); - w.writeBool(s.recommended.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readBusinessNotebook(ThriftBinaryBufferReader & r, BusinessNotebook & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.notebookDescription = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I32) { - SharedNotebookPrivilegeLevel::type v; - readEnumSharedNotebookPrivilegeLevel(r, v); - s.privilege = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.recommended = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeSavedSearchScope(ThriftBinaryBufferWriter & w, const SavedSearchScope & s) { - w.writeStructBegin(QStringLiteral("SavedSearchScope")); - if(s.includeAccount.isSet()) { - w.writeFieldBegin(QStringLiteral("includeAccount"), ThriftFieldType::T_BOOL, 1); - w.writeBool(s.includeAccount.ref()); - w.writeFieldEnd(); - } - if(s.includePersonalLinkedNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("includePersonalLinkedNotebooks"), ThriftFieldType::T_BOOL, 2); - w.writeBool(s.includePersonalLinkedNotebooks.ref()); - w.writeFieldEnd(); - } - if(s.includeBusinessLinkedNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("includeBusinessLinkedNotebooks"), ThriftFieldType::T_BOOL, 3); - w.writeBool(s.includeBusinessLinkedNotebooks.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readSavedSearchScope(ThriftBinaryBufferReader & r, SavedSearchScope & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeAccount = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includePersonalLinkedNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.includeBusinessLinkedNotebooks = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeSavedSearch(ThriftBinaryBufferWriter & w, const SavedSearch & s) { - w.writeStructBegin(QStringLiteral("SavedSearch")); - if(s.guid.isSet()) { - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.guid.ref()); - w.writeFieldEnd(); - } - if(s.name.isSet()) { - w.writeFieldBegin(QStringLiteral("name"), ThriftFieldType::T_STRING, 2); - w.writeString(s.name.ref()); - w.writeFieldEnd(); - } - if(s.query.isSet()) { - w.writeFieldBegin(QStringLiteral("query"), ThriftFieldType::T_STRING, 3); - w.writeString(s.query.ref()); - w.writeFieldEnd(); - } - if(s.format.isSet()) { - w.writeFieldBegin(QStringLiteral("format"), ThriftFieldType::T_I32, 4); - w.writeI32(static_cast(s.format.ref())); - w.writeFieldEnd(); - } - if(s.updateSequenceNum.isSet()) { - w.writeFieldBegin(QStringLiteral("updateSequenceNum"), ThriftFieldType::T_I32, 5); - w.writeI32(s.updateSequenceNum.ref()); - w.writeFieldEnd(); - } - if(s.scope.isSet()) { - w.writeFieldBegin(QStringLiteral("scope"), ThriftFieldType::T_STRUCT, 6); - writeSavedSearchScope(w, s.scope.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readSavedSearch(ThriftBinaryBufferReader & r, SavedSearch & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.guid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.name = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.query = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_I32) { - QueryFormat::type v; - readEnumQueryFormat(r, v); - s.format = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.updateSequenceNum = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRUCT) { - SavedSearchScope v; - readSavedSearchScope(r, v); - s.scope = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeSharedNotebookRecipientSettings(ThriftBinaryBufferWriter & w, const SharedNotebookRecipientSettings & s) { - w.writeStructBegin(QStringLiteral("SharedNotebookRecipientSettings")); - if(s.reminderNotifyEmail.isSet()) { - w.writeFieldBegin(QStringLiteral("reminderNotifyEmail"), ThriftFieldType::T_BOOL, 1); - w.writeBool(s.reminderNotifyEmail.ref()); - w.writeFieldEnd(); - } - if(s.reminderNotifyInApp.isSet()) { - w.writeFieldBegin(QStringLiteral("reminderNotifyInApp"), ThriftFieldType::T_BOOL, 2); - w.writeBool(s.reminderNotifyInApp.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readSharedNotebookRecipientSettings(ThriftBinaryBufferReader & r, SharedNotebookRecipientSettings & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.reminderNotifyEmail = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.reminderNotifyInApp = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNotebookRecipientSettings(ThriftBinaryBufferWriter & w, const NotebookRecipientSettings & s) { - w.writeStructBegin(QStringLiteral("NotebookRecipientSettings")); - if(s.reminderNotifyEmail.isSet()) { - w.writeFieldBegin(QStringLiteral("reminderNotifyEmail"), ThriftFieldType::T_BOOL, 1); - w.writeBool(s.reminderNotifyEmail.ref()); - w.writeFieldEnd(); - } - if(s.reminderNotifyInApp.isSet()) { - w.writeFieldBegin(QStringLiteral("reminderNotifyInApp"), ThriftFieldType::T_BOOL, 2); - w.writeBool(s.reminderNotifyInApp.ref()); - w.writeFieldEnd(); - } - if(s.inMyList.isSet()) { - w.writeFieldBegin(QStringLiteral("inMyList"), ThriftFieldType::T_BOOL, 3); - w.writeBool(s.inMyList.ref()); - w.writeFieldEnd(); - } - if(s.stack.isSet()) { - w.writeFieldBegin(QStringLiteral("stack"), ThriftFieldType::T_STRING, 4); - w.writeString(s.stack.ref()); - w.writeFieldEnd(); - } - if(s.recipientStatus.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientStatus"), ThriftFieldType::T_I32, 5); - w.writeI32(static_cast(s.recipientStatus.ref())); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNotebookRecipientSettings(ThriftBinaryBufferReader & r, NotebookRecipientSettings & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.reminderNotifyEmail = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.reminderNotifyInApp = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.inMyList = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.stack = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I32) { - RecipientStatus::type v; - readEnumRecipientStatus(r, v); - s.recipientStatus = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeSharedNotebook(ThriftBinaryBufferWriter & w, const SharedNotebook & s) { - w.writeStructBegin(QStringLiteral("SharedNotebook")); - if(s.id.isSet()) { - w.writeFieldBegin(QStringLiteral("id"), ThriftFieldType::T_I64, 1); - w.writeI64(s.id.ref()); - w.writeFieldEnd(); - } - if(s.userId.isSet()) { - w.writeFieldBegin(QStringLiteral("userId"), ThriftFieldType::T_I32, 2); - w.writeI32(s.userId.ref()); - w.writeFieldEnd(); - } - if(s.notebookGuid.isSet()) { - w.writeFieldBegin(QStringLiteral("notebookGuid"), ThriftFieldType::T_STRING, 3); - w.writeString(s.notebookGuid.ref()); - w.writeFieldEnd(); - } - if(s.email.isSet()) { - w.writeFieldBegin(QStringLiteral("email"), ThriftFieldType::T_STRING, 4); - w.writeString(s.email.ref()); - w.writeFieldEnd(); - } - if(s.recipientIdentityId.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientIdentityId"), ThriftFieldType::T_I64, 18); - w.writeI64(s.recipientIdentityId.ref()); - w.writeFieldEnd(); - } - if(s.notebookModifiable.isSet()) { - w.writeFieldBegin(QStringLiteral("notebookModifiable"), ThriftFieldType::T_BOOL, 5); - w.writeBool(s.notebookModifiable.ref()); - w.writeFieldEnd(); - } - if(s.serviceCreated.isSet()) { - w.writeFieldBegin(QStringLiteral("serviceCreated"), ThriftFieldType::T_I64, 7); - w.writeI64(s.serviceCreated.ref()); - w.writeFieldEnd(); - } - if(s.serviceUpdated.isSet()) { - w.writeFieldBegin(QStringLiteral("serviceUpdated"), ThriftFieldType::T_I64, 10); - w.writeI64(s.serviceUpdated.ref()); - w.writeFieldEnd(); - } - if(s.globalId.isSet()) { - w.writeFieldBegin(QStringLiteral("globalId"), ThriftFieldType::T_STRING, 8); - w.writeString(s.globalId.ref()); - w.writeFieldEnd(); - } - if(s.username.isSet()) { - w.writeFieldBegin(QStringLiteral("username"), ThriftFieldType::T_STRING, 9); - w.writeString(s.username.ref()); - w.writeFieldEnd(); - } - if(s.privilege.isSet()) { - w.writeFieldBegin(QStringLiteral("privilege"), ThriftFieldType::T_I32, 11); - w.writeI32(static_cast(s.privilege.ref())); - w.writeFieldEnd(); - } - if(s.recipientSettings.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientSettings"), ThriftFieldType::T_STRUCT, 13); - writeSharedNotebookRecipientSettings(w, s.recipientSettings.ref()); - w.writeFieldEnd(); - } - if(s.sharerUserId.isSet()) { - w.writeFieldBegin(QStringLiteral("sharerUserId"), ThriftFieldType::T_I32, 14); - w.writeI32(s.sharerUserId.ref()); - w.writeFieldEnd(); - } - if(s.recipientUsername.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientUsername"), ThriftFieldType::T_STRING, 15); - w.writeString(s.recipientUsername.ref()); - w.writeFieldEnd(); - } - if(s.recipientUserId.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientUserId"), ThriftFieldType::T_I32, 17); - w.writeI32(s.recipientUserId.ref()); - w.writeFieldEnd(); - } - if(s.serviceAssigned.isSet()) { - w.writeFieldBegin(QStringLiteral("serviceAssigned"), ThriftFieldType::T_I64, 16); - w.writeI64(s.serviceAssigned.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readSharedNotebook(ThriftBinaryBufferReader & r, SharedNotebook & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.id = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.userId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.notebookGuid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.email = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 18) { - if (fieldType == ThriftFieldType::T_I64) { - IdentityID v; - r.readI64(v); - s.recipientIdentityId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.notebookModifiable = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.serviceCreated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.serviceUpdated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.globalId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.username = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_I32) { - SharedNotebookPrivilegeLevel::type v; - readEnumSharedNotebookPrivilegeLevel(r, v); - s.privilege = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_STRUCT) { - SharedNotebookRecipientSettings v; - readSharedNotebookRecipientSettings(r, v); - s.recipientSettings = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 14) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.sharerUserId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 15) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.recipientUsername = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 17) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.recipientUserId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 16) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.serviceAssigned = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeCanMoveToContainerRestrictions(ThriftBinaryBufferWriter & w, const CanMoveToContainerRestrictions & s) { - w.writeStructBegin(QStringLiteral("CanMoveToContainerRestrictions")); - if(s.canMoveToContainer.isSet()) { - w.writeFieldBegin(QStringLiteral("canMoveToContainer"), ThriftFieldType::T_I32, 1); - w.writeI32(static_cast(s.canMoveToContainer.ref())); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readCanMoveToContainerRestrictions(ThriftBinaryBufferReader & r, CanMoveToContainerRestrictions & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - CanMoveToContainerStatus::type v; - readEnumCanMoveToContainerStatus(r, v); - s.canMoveToContainer = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNotebookRestrictions(ThriftBinaryBufferWriter & w, const NotebookRestrictions & s) { - w.writeStructBegin(QStringLiteral("NotebookRestrictions")); - if(s.noReadNotes.isSet()) { - w.writeFieldBegin(QStringLiteral("noReadNotes"), ThriftFieldType::T_BOOL, 1); - w.writeBool(s.noReadNotes.ref()); - w.writeFieldEnd(); - } - if(s.noCreateNotes.isSet()) { - w.writeFieldBegin(QStringLiteral("noCreateNotes"), ThriftFieldType::T_BOOL, 2); - w.writeBool(s.noCreateNotes.ref()); - w.writeFieldEnd(); - } - if(s.noUpdateNotes.isSet()) { - w.writeFieldBegin(QStringLiteral("noUpdateNotes"), ThriftFieldType::T_BOOL, 3); - w.writeBool(s.noUpdateNotes.ref()); - w.writeFieldEnd(); - } - if(s.noExpungeNotes.isSet()) { - w.writeFieldBegin(QStringLiteral("noExpungeNotes"), ThriftFieldType::T_BOOL, 4); - w.writeBool(s.noExpungeNotes.ref()); - w.writeFieldEnd(); - } - if(s.noShareNotes.isSet()) { - w.writeFieldBegin(QStringLiteral("noShareNotes"), ThriftFieldType::T_BOOL, 5); - w.writeBool(s.noShareNotes.ref()); - w.writeFieldEnd(); - } - if(s.noEmailNotes.isSet()) { - w.writeFieldBegin(QStringLiteral("noEmailNotes"), ThriftFieldType::T_BOOL, 6); - w.writeBool(s.noEmailNotes.ref()); - w.writeFieldEnd(); - } - if(s.noSendMessageToRecipients.isSet()) { - w.writeFieldBegin(QStringLiteral("noSendMessageToRecipients"), ThriftFieldType::T_BOOL, 7); - w.writeBool(s.noSendMessageToRecipients.ref()); - w.writeFieldEnd(); - } - if(s.noUpdateNotebook.isSet()) { - w.writeFieldBegin(QStringLiteral("noUpdateNotebook"), ThriftFieldType::T_BOOL, 8); - w.writeBool(s.noUpdateNotebook.ref()); - w.writeFieldEnd(); - } - if(s.noExpungeNotebook.isSet()) { - w.writeFieldBegin(QStringLiteral("noExpungeNotebook"), ThriftFieldType::T_BOOL, 9); - w.writeBool(s.noExpungeNotebook.ref()); - w.writeFieldEnd(); - } - if(s.noSetDefaultNotebook.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetDefaultNotebook"), ThriftFieldType::T_BOOL, 10); - w.writeBool(s.noSetDefaultNotebook.ref()); - w.writeFieldEnd(); - } - if(s.noSetNotebookStack.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetNotebookStack"), ThriftFieldType::T_BOOL, 11); - w.writeBool(s.noSetNotebookStack.ref()); - w.writeFieldEnd(); - } - if(s.noPublishToPublic.isSet()) { - w.writeFieldBegin(QStringLiteral("noPublishToPublic"), ThriftFieldType::T_BOOL, 12); - w.writeBool(s.noPublishToPublic.ref()); - w.writeFieldEnd(); - } - if(s.noPublishToBusinessLibrary.isSet()) { - w.writeFieldBegin(QStringLiteral("noPublishToBusinessLibrary"), ThriftFieldType::T_BOOL, 13); - w.writeBool(s.noPublishToBusinessLibrary.ref()); - w.writeFieldEnd(); - } - if(s.noCreateTags.isSet()) { - w.writeFieldBegin(QStringLiteral("noCreateTags"), ThriftFieldType::T_BOOL, 14); - w.writeBool(s.noCreateTags.ref()); - w.writeFieldEnd(); - } - if(s.noUpdateTags.isSet()) { - w.writeFieldBegin(QStringLiteral("noUpdateTags"), ThriftFieldType::T_BOOL, 15); - w.writeBool(s.noUpdateTags.ref()); - w.writeFieldEnd(); - } - if(s.noExpungeTags.isSet()) { - w.writeFieldBegin(QStringLiteral("noExpungeTags"), ThriftFieldType::T_BOOL, 16); - w.writeBool(s.noExpungeTags.ref()); - w.writeFieldEnd(); - } - if(s.noSetParentTag.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetParentTag"), ThriftFieldType::T_BOOL, 17); - w.writeBool(s.noSetParentTag.ref()); - w.writeFieldEnd(); - } - if(s.noCreateSharedNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("noCreateSharedNotebooks"), ThriftFieldType::T_BOOL, 18); - w.writeBool(s.noCreateSharedNotebooks.ref()); - w.writeFieldEnd(); - } - if(s.updateWhichSharedNotebookRestrictions.isSet()) { - w.writeFieldBegin(QStringLiteral("updateWhichSharedNotebookRestrictions"), ThriftFieldType::T_I32, 19); - w.writeI32(static_cast(s.updateWhichSharedNotebookRestrictions.ref())); - w.writeFieldEnd(); - } - if(s.expungeWhichSharedNotebookRestrictions.isSet()) { - w.writeFieldBegin(QStringLiteral("expungeWhichSharedNotebookRestrictions"), ThriftFieldType::T_I32, 20); - w.writeI32(static_cast(s.expungeWhichSharedNotebookRestrictions.ref())); - w.writeFieldEnd(); - } - if(s.noShareNotesWithBusiness.isSet()) { - w.writeFieldBegin(QStringLiteral("noShareNotesWithBusiness"), ThriftFieldType::T_BOOL, 21); - w.writeBool(s.noShareNotesWithBusiness.ref()); - w.writeFieldEnd(); - } - if(s.noRenameNotebook.isSet()) { - w.writeFieldBegin(QStringLiteral("noRenameNotebook"), ThriftFieldType::T_BOOL, 22); - w.writeBool(s.noRenameNotebook.ref()); - w.writeFieldEnd(); - } - if(s.noSetInMyList.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetInMyList"), ThriftFieldType::T_BOOL, 23); - w.writeBool(s.noSetInMyList.ref()); - w.writeFieldEnd(); - } - if(s.noChangeContact.isSet()) { - w.writeFieldBegin(QStringLiteral("noChangeContact"), ThriftFieldType::T_BOOL, 24); - w.writeBool(s.noChangeContact.ref()); - w.writeFieldEnd(); - } - if(s.canMoveToContainerRestrictions.isSet()) { - w.writeFieldBegin(QStringLiteral("canMoveToContainerRestrictions"), ThriftFieldType::T_STRUCT, 26); - writeCanMoveToContainerRestrictions(w, s.canMoveToContainerRestrictions.ref()); - w.writeFieldEnd(); - } - if(s.noSetReminderNotifyEmail.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetReminderNotifyEmail"), ThriftFieldType::T_BOOL, 27); - w.writeBool(s.noSetReminderNotifyEmail.ref()); - w.writeFieldEnd(); - } - if(s.noSetReminderNotifyInApp.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetReminderNotifyInApp"), ThriftFieldType::T_BOOL, 28); - w.writeBool(s.noSetReminderNotifyInApp.ref()); - w.writeFieldEnd(); - } - if(s.noSetRecipientSettingsStack.isSet()) { - w.writeFieldBegin(QStringLiteral("noSetRecipientSettingsStack"), ThriftFieldType::T_BOOL, 29); - w.writeBool(s.noSetRecipientSettingsStack.ref()); - w.writeFieldEnd(); - } - if(s.noCanMoveNote.isSet()) { - w.writeFieldBegin(QStringLiteral("noCanMoveNote"), ThriftFieldType::T_BOOL, 30); - w.writeBool(s.noCanMoveNote.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNotebookRestrictions(ThriftBinaryBufferReader & r, NotebookRestrictions & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noReadNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noCreateNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noUpdateNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noExpungeNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noShareNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noEmailNotes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSendMessageToRecipients = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noUpdateNotebook = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noExpungeNotebook = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetDefaultNotebook = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetNotebookStack = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noPublishToPublic = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noPublishToBusinessLibrary = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 14) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noCreateTags = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 15) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noUpdateTags = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 16) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noExpungeTags = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 17) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetParentTag = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 18) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noCreateSharedNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 19) { - if (fieldType == ThriftFieldType::T_I32) { - SharedNotebookInstanceRestrictions::type v; - readEnumSharedNotebookInstanceRestrictions(r, v); - s.updateWhichSharedNotebookRestrictions = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 20) { - if (fieldType == ThriftFieldType::T_I32) { - SharedNotebookInstanceRestrictions::type v; - readEnumSharedNotebookInstanceRestrictions(r, v); - s.expungeWhichSharedNotebookRestrictions = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 21) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noShareNotesWithBusiness = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 22) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noRenameNotebook = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 23) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetInMyList = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 24) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noChangeContact = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 26) { - if (fieldType == ThriftFieldType::T_STRUCT) { - CanMoveToContainerRestrictions v; - readCanMoveToContainerRestrictions(r, v); - s.canMoveToContainerRestrictions = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 27) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetReminderNotifyEmail = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 28) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetReminderNotifyInApp = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 29) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noSetRecipientSettingsStack = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 30) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.noCanMoveNote = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNotebook(ThriftBinaryBufferWriter & w, const Notebook & s) { - w.writeStructBegin(QStringLiteral("Notebook")); - if(s.guid.isSet()) { - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.guid.ref()); - w.writeFieldEnd(); - } - if(s.name.isSet()) { - w.writeFieldBegin(QStringLiteral("name"), ThriftFieldType::T_STRING, 2); - w.writeString(s.name.ref()); - w.writeFieldEnd(); - } - if(s.updateSequenceNum.isSet()) { - w.writeFieldBegin(QStringLiteral("updateSequenceNum"), ThriftFieldType::T_I32, 5); - w.writeI32(s.updateSequenceNum.ref()); - w.writeFieldEnd(); - } - if(s.defaultNotebook.isSet()) { - w.writeFieldBegin(QStringLiteral("defaultNotebook"), ThriftFieldType::T_BOOL, 6); - w.writeBool(s.defaultNotebook.ref()); - w.writeFieldEnd(); - } - if(s.serviceCreated.isSet()) { - w.writeFieldBegin(QStringLiteral("serviceCreated"), ThriftFieldType::T_I64, 7); - w.writeI64(s.serviceCreated.ref()); - w.writeFieldEnd(); - } - if(s.serviceUpdated.isSet()) { - w.writeFieldBegin(QStringLiteral("serviceUpdated"), ThriftFieldType::T_I64, 8); - w.writeI64(s.serviceUpdated.ref()); - w.writeFieldEnd(); - } - if(s.publishing.isSet()) { - w.writeFieldBegin(QStringLiteral("publishing"), ThriftFieldType::T_STRUCT, 10); - writePublishing(w, s.publishing.ref()); - w.writeFieldEnd(); - } - if(s.published.isSet()) { - w.writeFieldBegin(QStringLiteral("published"), ThriftFieldType::T_BOOL, 11); - w.writeBool(s.published.ref()); - w.writeFieldEnd(); - } - if(s.stack.isSet()) { - w.writeFieldBegin(QStringLiteral("stack"), ThriftFieldType::T_STRING, 12); - w.writeString(s.stack.ref()); - w.writeFieldEnd(); - } - if(s.sharedNotebookIds.isSet()) { - w.writeFieldBegin(QStringLiteral("sharedNotebookIds"), ThriftFieldType::T_LIST, 13); - w.writeListBegin(ThriftFieldType::T_I64, s.sharedNotebookIds.ref().length()); - for(QList< qint64 >::const_iterator it = s.sharedNotebookIds.ref().constBegin(), end = s.sharedNotebookIds.ref().constEnd(); it != end; ++it) { - w.writeI64(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.sharedNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("sharedNotebooks"), ThriftFieldType::T_LIST, 14); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.sharedNotebooks.ref().length()); - for(QList< SharedNotebook >::const_iterator it = s.sharedNotebooks.ref().constBegin(), end = s.sharedNotebooks.ref().constEnd(); it != end; ++it) { - writeSharedNotebook(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.businessNotebook.isSet()) { - w.writeFieldBegin(QStringLiteral("businessNotebook"), ThriftFieldType::T_STRUCT, 15); - writeBusinessNotebook(w, s.businessNotebook.ref()); - w.writeFieldEnd(); - } - if(s.contact.isSet()) { - w.writeFieldBegin(QStringLiteral("contact"), ThriftFieldType::T_STRUCT, 16); - writeUser(w, s.contact.ref()); - w.writeFieldEnd(); - } - if(s.restrictions.isSet()) { - w.writeFieldBegin(QStringLiteral("restrictions"), ThriftFieldType::T_STRUCT, 17); - writeNotebookRestrictions(w, s.restrictions.ref()); - w.writeFieldEnd(); - } - if(s.recipientSettings.isSet()) { - w.writeFieldBegin(QStringLiteral("recipientSettings"), ThriftFieldType::T_STRUCT, 18); - writeNotebookRecipientSettings(w, s.recipientSettings.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNotebook(ThriftBinaryBufferReader & r, Notebook & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.guid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.name = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.updateSequenceNum = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.defaultNotebook = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.serviceCreated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.serviceUpdated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_STRUCT) { - Publishing v; - readPublishing(r, v); - s.publishing = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.published = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.stack = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< qint64 > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_I64) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (Notebook.sharedNotebookIds)")); - for(qint32 i = 0; i < size; i++) { - qint64 elem; - r.readI64(elem); - v.append(elem); - } - r.readListEnd(); - s.sharedNotebookIds = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 14) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< SharedNotebook > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (Notebook.sharedNotebooks)")); - for(qint32 i = 0; i < size; i++) { - SharedNotebook elem; - readSharedNotebook(r, elem); - v.append(elem); - } - r.readListEnd(); - s.sharedNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 15) { - if (fieldType == ThriftFieldType::T_STRUCT) { - BusinessNotebook v; - readBusinessNotebook(r, v); - s.businessNotebook = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 16) { - if (fieldType == ThriftFieldType::T_STRUCT) { - User v; - readUser(r, v); - s.contact = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 17) { - if (fieldType == ThriftFieldType::T_STRUCT) { - NotebookRestrictions v; - readNotebookRestrictions(r, v); - s.restrictions = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 18) { - if (fieldType == ThriftFieldType::T_STRUCT) { - NotebookRecipientSettings v; - readNotebookRecipientSettings(r, v); - s.recipientSettings = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeLinkedNotebook(ThriftBinaryBufferWriter & w, const LinkedNotebook & s) { - w.writeStructBegin(QStringLiteral("LinkedNotebook")); - if(s.shareName.isSet()) { - w.writeFieldBegin(QStringLiteral("shareName"), ThriftFieldType::T_STRING, 2); - w.writeString(s.shareName.ref()); - w.writeFieldEnd(); - } - if(s.username.isSet()) { - w.writeFieldBegin(QStringLiteral("username"), ThriftFieldType::T_STRING, 3); - w.writeString(s.username.ref()); - w.writeFieldEnd(); - } - if(s.shardId.isSet()) { - w.writeFieldBegin(QStringLiteral("shardId"), ThriftFieldType::T_STRING, 4); - w.writeString(s.shardId.ref()); - w.writeFieldEnd(); - } - if(s.sharedNotebookGlobalId.isSet()) { - w.writeFieldBegin(QStringLiteral("sharedNotebookGlobalId"), ThriftFieldType::T_STRING, 5); - w.writeString(s.sharedNotebookGlobalId.ref()); - w.writeFieldEnd(); - } - if(s.uri.isSet()) { - w.writeFieldBegin(QStringLiteral("uri"), ThriftFieldType::T_STRING, 6); - w.writeString(s.uri.ref()); - w.writeFieldEnd(); - } - if(s.guid.isSet()) { - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 7); - w.writeString(s.guid.ref()); - w.writeFieldEnd(); - } - if(s.updateSequenceNum.isSet()) { - w.writeFieldBegin(QStringLiteral("updateSequenceNum"), ThriftFieldType::T_I32, 8); - w.writeI32(s.updateSequenceNum.ref()); - w.writeFieldEnd(); - } - if(s.noteStoreUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("noteStoreUrl"), ThriftFieldType::T_STRING, 9); - w.writeString(s.noteStoreUrl.ref()); - w.writeFieldEnd(); - } - if(s.webApiUrlPrefix.isSet()) { - w.writeFieldBegin(QStringLiteral("webApiUrlPrefix"), ThriftFieldType::T_STRING, 10); - w.writeString(s.webApiUrlPrefix.ref()); - w.writeFieldEnd(); - } - if(s.stack.isSet()) { - w.writeFieldBegin(QStringLiteral("stack"), ThriftFieldType::T_STRING, 11); - w.writeString(s.stack.ref()); - w.writeFieldEnd(); - } - if(s.businessId.isSet()) { - w.writeFieldBegin(QStringLiteral("businessId"), ThriftFieldType::T_I32, 12); - w.writeI32(s.businessId.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readLinkedNotebook(ThriftBinaryBufferReader & r, LinkedNotebook & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.shareName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.username = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.shardId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.sharedNotebookGlobalId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.uri = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.guid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.updateSequenceNum = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.noteStoreUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.webApiUrlPrefix = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.stack = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.businessId = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeNotebookDescriptor(ThriftBinaryBufferWriter & w, const NotebookDescriptor & s) { - w.writeStructBegin(QStringLiteral("NotebookDescriptor")); - if(s.guid.isSet()) { - w.writeFieldBegin(QStringLiteral("guid"), ThriftFieldType::T_STRING, 1); - w.writeString(s.guid.ref()); - w.writeFieldEnd(); - } - if(s.notebookDisplayName.isSet()) { - w.writeFieldBegin(QStringLiteral("notebookDisplayName"), ThriftFieldType::T_STRING, 2); - w.writeString(s.notebookDisplayName.ref()); - w.writeFieldEnd(); - } - if(s.contactName.isSet()) { - w.writeFieldBegin(QStringLiteral("contactName"), ThriftFieldType::T_STRING, 3); - w.writeString(s.contactName.ref()); - w.writeFieldEnd(); - } - if(s.hasSharedNotebook.isSet()) { - w.writeFieldBegin(QStringLiteral("hasSharedNotebook"), ThriftFieldType::T_BOOL, 4); - w.writeBool(s.hasSharedNotebook.ref()); - w.writeFieldEnd(); - } - if(s.joinedUserCount.isSet()) { - w.writeFieldBegin(QStringLiteral("joinedUserCount"), ThriftFieldType::T_I32, 5); - w.writeI32(s.joinedUserCount.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readNotebookDescriptor(ThriftBinaryBufferReader & r, NotebookDescriptor & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - Guid v; - r.readString(v); - s.guid = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.notebookDisplayName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.contactName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.hasSharedNotebook = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.joinedUserCount = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeUserProfile(ThriftBinaryBufferWriter & w, const UserProfile & s) { - w.writeStructBegin(QStringLiteral("UserProfile")); - if(s.id.isSet()) { - w.writeFieldBegin(QStringLiteral("id"), ThriftFieldType::T_I32, 1); - w.writeI32(s.id.ref()); - w.writeFieldEnd(); - } - if(s.name.isSet()) { - w.writeFieldBegin(QStringLiteral("name"), ThriftFieldType::T_STRING, 2); - w.writeString(s.name.ref()); - w.writeFieldEnd(); - } - if(s.email.isSet()) { - w.writeFieldBegin(QStringLiteral("email"), ThriftFieldType::T_STRING, 3); - w.writeString(s.email.ref()); - w.writeFieldEnd(); - } - if(s.username.isSet()) { - w.writeFieldBegin(QStringLiteral("username"), ThriftFieldType::T_STRING, 4); - w.writeString(s.username.ref()); - w.writeFieldEnd(); - } - if(s.attributes.isSet()) { - w.writeFieldBegin(QStringLiteral("attributes"), ThriftFieldType::T_STRUCT, 5); - writeBusinessUserAttributes(w, s.attributes.ref()); - w.writeFieldEnd(); - } - if(s.joined.isSet()) { - w.writeFieldBegin(QStringLiteral("joined"), ThriftFieldType::T_I64, 6); - w.writeI64(s.joined.ref()); - w.writeFieldEnd(); - } - if(s.photoLastUpdated.isSet()) { - w.writeFieldBegin(QStringLiteral("photoLastUpdated"), ThriftFieldType::T_I64, 7); - w.writeI64(s.photoLastUpdated.ref()); - w.writeFieldEnd(); - } - if(s.photoUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("photoUrl"), ThriftFieldType::T_STRING, 8); - w.writeString(s.photoUrl.ref()); - w.writeFieldEnd(); - } - if(s.role.isSet()) { - w.writeFieldBegin(QStringLiteral("role"), ThriftFieldType::T_I32, 9); - w.writeI32(static_cast(s.role.ref())); - w.writeFieldEnd(); - } - if(s.status.isSet()) { - w.writeFieldBegin(QStringLiteral("status"), ThriftFieldType::T_I32, 10); - w.writeI32(static_cast(s.status.ref())); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readUserProfile(ThriftBinaryBufferReader & r, UserProfile & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.id = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.name = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.email = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.username = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_STRUCT) { - BusinessUserAttributes v; - readBusinessUserAttributes(r, v); - s.attributes = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.joined = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.photoLastUpdated = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.photoUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_I32) { - BusinessUserRole::type v; - readEnumBusinessUserRole(r, v); - s.role = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_I32) { - BusinessUserStatus::type v; - readEnumBusinessUserStatus(r, v); - s.status = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeRelatedContentImage(ThriftBinaryBufferWriter & w, const RelatedContentImage & s) { - w.writeStructBegin(QStringLiteral("RelatedContentImage")); - if(s.url.isSet()) { - w.writeFieldBegin(QStringLiteral("url"), ThriftFieldType::T_STRING, 1); - w.writeString(s.url.ref()); - w.writeFieldEnd(); - } - if(s.width.isSet()) { - w.writeFieldBegin(QStringLiteral("width"), ThriftFieldType::T_I32, 2); - w.writeI32(s.width.ref()); - w.writeFieldEnd(); - } - if(s.height.isSet()) { - w.writeFieldBegin(QStringLiteral("height"), ThriftFieldType::T_I32, 3); - w.writeI32(s.height.ref()); - w.writeFieldEnd(); - } - if(s.pixelRatio.isSet()) { - w.writeFieldBegin(QStringLiteral("pixelRatio"), ThriftFieldType::T_DOUBLE, 4); - w.writeDouble(s.pixelRatio.ref()); - w.writeFieldEnd(); - } - if(s.fileSize.isSet()) { - w.writeFieldBegin(QStringLiteral("fileSize"), ThriftFieldType::T_I32, 5); - w.writeI32(s.fileSize.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readRelatedContentImage(ThriftBinaryBufferReader & r, RelatedContentImage & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.url = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.width = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.height = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_DOUBLE) { - double v; - r.readDouble(v); - s.pixelRatio = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.fileSize = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeRelatedContent(ThriftBinaryBufferWriter & w, const RelatedContent & s) { - w.writeStructBegin(QStringLiteral("RelatedContent")); - if(s.contentId.isSet()) { - w.writeFieldBegin(QStringLiteral("contentId"), ThriftFieldType::T_STRING, 1); - w.writeString(s.contentId.ref()); - w.writeFieldEnd(); - } - if(s.title.isSet()) { - w.writeFieldBegin(QStringLiteral("title"), ThriftFieldType::T_STRING, 2); - w.writeString(s.title.ref()); - w.writeFieldEnd(); - } - if(s.url.isSet()) { - w.writeFieldBegin(QStringLiteral("url"), ThriftFieldType::T_STRING, 3); - w.writeString(s.url.ref()); - w.writeFieldEnd(); - } - if(s.sourceId.isSet()) { - w.writeFieldBegin(QStringLiteral("sourceId"), ThriftFieldType::T_STRING, 4); - w.writeString(s.sourceId.ref()); - w.writeFieldEnd(); - } - if(s.sourceUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("sourceUrl"), ThriftFieldType::T_STRING, 5); - w.writeString(s.sourceUrl.ref()); - w.writeFieldEnd(); - } - if(s.sourceFaviconUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("sourceFaviconUrl"), ThriftFieldType::T_STRING, 6); - w.writeString(s.sourceFaviconUrl.ref()); - w.writeFieldEnd(); - } - if(s.sourceName.isSet()) { - w.writeFieldBegin(QStringLiteral("sourceName"), ThriftFieldType::T_STRING, 7); - w.writeString(s.sourceName.ref()); - w.writeFieldEnd(); - } - if(s.date.isSet()) { - w.writeFieldBegin(QStringLiteral("date"), ThriftFieldType::T_I64, 8); - w.writeI64(s.date.ref()); - w.writeFieldEnd(); - } - if(s.teaser.isSet()) { - w.writeFieldBegin(QStringLiteral("teaser"), ThriftFieldType::T_STRING, 9); - w.writeString(s.teaser.ref()); - w.writeFieldEnd(); - } - if(s.thumbnails.isSet()) { - w.writeFieldBegin(QStringLiteral("thumbnails"), ThriftFieldType::T_LIST, 10); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.thumbnails.ref().length()); - for(QList< RelatedContentImage >::const_iterator it = s.thumbnails.ref().constBegin(), end = s.thumbnails.ref().constEnd(); it != end; ++it) { - writeRelatedContentImage(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - if(s.contentType.isSet()) { - w.writeFieldBegin(QStringLiteral("contentType"), ThriftFieldType::T_I32, 11); - w.writeI32(static_cast(s.contentType.ref())); - w.writeFieldEnd(); - } - if(s.accessType.isSet()) { - w.writeFieldBegin(QStringLiteral("accessType"), ThriftFieldType::T_I32, 12); - w.writeI32(static_cast(s.accessType.ref())); - w.writeFieldEnd(); - } - if(s.visibleUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("visibleUrl"), ThriftFieldType::T_STRING, 13); - w.writeString(s.visibleUrl.ref()); - w.writeFieldEnd(); - } - if(s.clipUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("clipUrl"), ThriftFieldType::T_STRING, 14); - w.writeString(s.clipUrl.ref()); - w.writeFieldEnd(); - } - if(s.contact.isSet()) { - w.writeFieldBegin(QStringLiteral("contact"), ThriftFieldType::T_STRUCT, 15); - writeContact(w, s.contact.ref()); - w.writeFieldEnd(); - } - if(s.authors.isSet()) { - w.writeFieldBegin(QStringLiteral("authors"), ThriftFieldType::T_LIST, 16); - w.writeListBegin(ThriftFieldType::T_STRING, s.authors.ref().length()); - for(QStringList::const_iterator it = s.authors.ref().constBegin(), end = s.authors.ref().constEnd(); it != end; ++it) { - w.writeString(*it); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readRelatedContent(ThriftBinaryBufferReader & r, RelatedContent & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.contentId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.title = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.url = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.sourceId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.sourceUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.sourceFaviconUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.sourceName = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.date = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.teaser = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< RelatedContentImage > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (RelatedContent.thumbnails)")); - for(qint32 i = 0; i < size; i++) { - RelatedContentImage elem; - readRelatedContentImage(r, elem); - v.append(elem); - } - r.readListEnd(); - s.thumbnails = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_I32) { - RelatedContentType::type v; - readEnumRelatedContentType(r, v); - s.contentType = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_I32) { - RelatedContentAccess::type v; - readEnumRelatedContentAccess(r, v); - s.accessType = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.visibleUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 14) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.clipUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 15) { - if (fieldType == ThriftFieldType::T_STRUCT) { - Contact v; - readContact(r, v); - s.contact = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 16) { - if (fieldType == ThriftFieldType::T_LIST) { - QStringList v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRING) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (RelatedContent.authors)")); - for(qint32 i = 0; i < size; i++) { - QString elem; - r.readString(elem); - v.append(elem); - } - r.readListEnd(); - s.authors = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeBusinessInvitation(ThriftBinaryBufferWriter & w, const BusinessInvitation & s) { - w.writeStructBegin(QStringLiteral("BusinessInvitation")); - if(s.businessId.isSet()) { - w.writeFieldBegin(QStringLiteral("businessId"), ThriftFieldType::T_I32, 1); - w.writeI32(s.businessId.ref()); - w.writeFieldEnd(); - } - if(s.email.isSet()) { - w.writeFieldBegin(QStringLiteral("email"), ThriftFieldType::T_STRING, 2); - w.writeString(s.email.ref()); - w.writeFieldEnd(); - } - if(s.role.isSet()) { - w.writeFieldBegin(QStringLiteral("role"), ThriftFieldType::T_I32, 3); - w.writeI32(static_cast(s.role.ref())); - w.writeFieldEnd(); - } - if(s.status.isSet()) { - w.writeFieldBegin(QStringLiteral("status"), ThriftFieldType::T_I32, 4); - w.writeI32(static_cast(s.status.ref())); - w.writeFieldEnd(); - } - if(s.requesterId.isSet()) { - w.writeFieldBegin(QStringLiteral("requesterId"), ThriftFieldType::T_I32, 5); - w.writeI32(s.requesterId.ref()); - w.writeFieldEnd(); - } - if(s.fromWorkChat.isSet()) { - w.writeFieldBegin(QStringLiteral("fromWorkChat"), ThriftFieldType::T_BOOL, 6); - w.writeBool(s.fromWorkChat.ref()); - w.writeFieldEnd(); - } - if(s.created.isSet()) { - w.writeFieldBegin(QStringLiteral("created"), ThriftFieldType::T_I64, 7); - w.writeI64(s.created.ref()); - w.writeFieldEnd(); - } - if(s.mostRecentReminder.isSet()) { - w.writeFieldBegin(QStringLiteral("mostRecentReminder"), ThriftFieldType::T_I64, 8); - w.writeI64(s.mostRecentReminder.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readBusinessInvitation(ThriftBinaryBufferReader & r, BusinessInvitation & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.businessId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.email = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - BusinessUserRole::type v; - readEnumBusinessUserRole(r, v); - s.role = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_I32) { - BusinessInvitationStatus::type v; - readEnumBusinessInvitationStatus(r, v); - s.status = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_I32) { - UserID v; - r.readI32(v); - s.requesterId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.fromWorkChat = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.created = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.mostRecentReminder = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeUserIdentity(ThriftBinaryBufferWriter & w, const UserIdentity & s) { - w.writeStructBegin(QStringLiteral("UserIdentity")); - if(s.type.isSet()) { - w.writeFieldBegin(QStringLiteral("type"), ThriftFieldType::T_I32, 1); - w.writeI32(static_cast(s.type.ref())); - w.writeFieldEnd(); - } - if(s.stringIdentifier.isSet()) { - w.writeFieldBegin(QStringLiteral("stringIdentifier"), ThriftFieldType::T_STRING, 2); - w.writeString(s.stringIdentifier.ref()); - w.writeFieldEnd(); - } - if(s.longIdentifier.isSet()) { - w.writeFieldBegin(QStringLiteral("longIdentifier"), ThriftFieldType::T_I64, 3); - w.writeI64(s.longIdentifier.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readUserIdentity(ThriftBinaryBufferReader & r, UserIdentity & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - UserIdentityType::type v; - readEnumUserIdentityType(r, v); - s.type = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.stringIdentifier = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I64) { - qint64 v; - r.readI64(v); - s.longIdentifier = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writePublicUserInfo(ThriftBinaryBufferWriter & w, const PublicUserInfo & s) { - w.writeStructBegin(QStringLiteral("PublicUserInfo")); - w.writeFieldBegin(QStringLiteral("userId"), ThriftFieldType::T_I32, 1); - w.writeI32(s.userId); - w.writeFieldEnd(); - if(s.serviceLevel.isSet()) { - w.writeFieldBegin(QStringLiteral("serviceLevel"), ThriftFieldType::T_I32, 7); - w.writeI32(static_cast(s.serviceLevel.ref())); - w.writeFieldEnd(); - } - if(s.username.isSet()) { - w.writeFieldBegin(QStringLiteral("username"), ThriftFieldType::T_STRING, 4); - w.writeString(s.username.ref()); - w.writeFieldEnd(); - } - if(s.noteStoreUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("noteStoreUrl"), ThriftFieldType::T_STRING, 5); - w.writeString(s.noteStoreUrl.ref()); - w.writeFieldEnd(); - } - if(s.webApiUrlPrefix.isSet()) { - w.writeFieldBegin(QStringLiteral("webApiUrlPrefix"), ThriftFieldType::T_STRING, 6); - w.writeString(s.webApiUrlPrefix.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readPublicUserInfo(ThriftBinaryBufferReader & r, PublicUserInfo & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool userId_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - userId_isset = true; - UserID v; - r.readI32(v); - s.userId = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_I32) { - ServiceLevel::type v; - readEnumServiceLevel(r, v); - s.serviceLevel = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.username = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.noteStoreUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.webApiUrlPrefix = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!userId_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("PublicUserInfo.userId has no value")); -} - -void writeUserUrls(ThriftBinaryBufferWriter & w, const UserUrls & s) { - w.writeStructBegin(QStringLiteral("UserUrls")); - if(s.noteStoreUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("noteStoreUrl"), ThriftFieldType::T_STRING, 1); - w.writeString(s.noteStoreUrl.ref()); - w.writeFieldEnd(); - } - if(s.webApiUrlPrefix.isSet()) { - w.writeFieldBegin(QStringLiteral("webApiUrlPrefix"), ThriftFieldType::T_STRING, 2); - w.writeString(s.webApiUrlPrefix.ref()); - w.writeFieldEnd(); - } - if(s.userStoreUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("userStoreUrl"), ThriftFieldType::T_STRING, 3); - w.writeString(s.userStoreUrl.ref()); - w.writeFieldEnd(); - } - if(s.utilityUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("utilityUrl"), ThriftFieldType::T_STRING, 4); - w.writeString(s.utilityUrl.ref()); - w.writeFieldEnd(); - } - if(s.messageStoreUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("messageStoreUrl"), ThriftFieldType::T_STRING, 5); - w.writeString(s.messageStoreUrl.ref()); - w.writeFieldEnd(); - } - if(s.userWebSocketUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("userWebSocketUrl"), ThriftFieldType::T_STRING, 6); - w.writeString(s.userWebSocketUrl.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readUserUrls(ThriftBinaryBufferReader & r, UserUrls & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.noteStoreUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.webApiUrlPrefix = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.userStoreUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.utilityUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.messageStoreUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.userWebSocketUrl = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -void writeAuthenticationResult(ThriftBinaryBufferWriter & w, const AuthenticationResult & s) { - w.writeStructBegin(QStringLiteral("AuthenticationResult")); - w.writeFieldBegin(QStringLiteral("currentTime"), ThriftFieldType::T_I64, 1); - w.writeI64(s.currentTime); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("authenticationToken"), ThriftFieldType::T_STRING, 2); - w.writeString(s.authenticationToken); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("expiration"), ThriftFieldType::T_I64, 3); - w.writeI64(s.expiration); - w.writeFieldEnd(); - if(s.user.isSet()) { - w.writeFieldBegin(QStringLiteral("user"), ThriftFieldType::T_STRUCT, 4); - writeUser(w, s.user.ref()); - w.writeFieldEnd(); - } - if(s.publicUserInfo.isSet()) { - w.writeFieldBegin(QStringLiteral("publicUserInfo"), ThriftFieldType::T_STRUCT, 5); - writePublicUserInfo(w, s.publicUserInfo.ref()); - w.writeFieldEnd(); - } - if(s.noteStoreUrl.isSet()) { - w.writeFieldBegin(QStringLiteral("noteStoreUrl"), ThriftFieldType::T_STRING, 6); - w.writeString(s.noteStoreUrl.ref()); - w.writeFieldEnd(); - } - if(s.webApiUrlPrefix.isSet()) { - w.writeFieldBegin(QStringLiteral("webApiUrlPrefix"), ThriftFieldType::T_STRING, 7); - w.writeString(s.webApiUrlPrefix.ref()); - w.writeFieldEnd(); - } - if(s.secondFactorRequired.isSet()) { - w.writeFieldBegin(QStringLiteral("secondFactorRequired"), ThriftFieldType::T_BOOL, 8); - w.writeBool(s.secondFactorRequired.ref()); - w.writeFieldEnd(); - } - if(s.secondFactorDeliveryHint.isSet()) { - w.writeFieldBegin(QStringLiteral("secondFactorDeliveryHint"), ThriftFieldType::T_STRING, 9); - w.writeString(s.secondFactorDeliveryHint.ref()); - w.writeFieldEnd(); - } - if(s.urls.isSet()) { - w.writeFieldBegin(QStringLiteral("urls"), ThriftFieldType::T_STRUCT, 10); - writeUserUrls(w, s.urls.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readAuthenticationResult(ThriftBinaryBufferReader & r, AuthenticationResult & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool currentTime_isset = false; - bool authenticationToken_isset = false; - bool expiration_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I64) { - currentTime_isset = true; - qint64 v; - r.readI64(v); - s.currentTime = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - authenticationToken_isset = true; - QString v; - r.readString(v); - s.authenticationToken = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I64) { - expiration_isset = true; - qint64 v; - r.readI64(v); - s.expiration = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRUCT) { - User v; - readUser(r, v); - s.user = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_STRUCT) { - PublicUserInfo v; - readPublicUserInfo(r, v); - s.publicUserInfo = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.noteStoreUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.webApiUrlPrefix = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.secondFactorRequired = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.secondFactorDeliveryHint = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_STRUCT) { - UserUrls v; - readUserUrls(r, v); - s.urls = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!currentTime_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("AuthenticationResult.currentTime has no value")); - if(!authenticationToken_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("AuthenticationResult.authenticationToken has no value")); - if(!expiration_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("AuthenticationResult.expiration has no value")); -} - -void writeBootstrapSettings(ThriftBinaryBufferWriter & w, const BootstrapSettings & s) { - w.writeStructBegin(QStringLiteral("BootstrapSettings")); - w.writeFieldBegin(QStringLiteral("serviceHost"), ThriftFieldType::T_STRING, 1); - w.writeString(s.serviceHost); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("marketingUrl"), ThriftFieldType::T_STRING, 2); - w.writeString(s.marketingUrl); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("supportUrl"), ThriftFieldType::T_STRING, 3); - w.writeString(s.supportUrl); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("accountEmailDomain"), ThriftFieldType::T_STRING, 4); - w.writeString(s.accountEmailDomain); - w.writeFieldEnd(); - if(s.enableFacebookSharing.isSet()) { - w.writeFieldBegin(QStringLiteral("enableFacebookSharing"), ThriftFieldType::T_BOOL, 5); - w.writeBool(s.enableFacebookSharing.ref()); - w.writeFieldEnd(); - } - if(s.enableGiftSubscriptions.isSet()) { - w.writeFieldBegin(QStringLiteral("enableGiftSubscriptions"), ThriftFieldType::T_BOOL, 6); - w.writeBool(s.enableGiftSubscriptions.ref()); - w.writeFieldEnd(); - } - if(s.enableSupportTickets.isSet()) { - w.writeFieldBegin(QStringLiteral("enableSupportTickets"), ThriftFieldType::T_BOOL, 7); - w.writeBool(s.enableSupportTickets.ref()); - w.writeFieldEnd(); - } - if(s.enableSharedNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("enableSharedNotebooks"), ThriftFieldType::T_BOOL, 8); - w.writeBool(s.enableSharedNotebooks.ref()); - w.writeFieldEnd(); - } - if(s.enableSingleNoteSharing.isSet()) { - w.writeFieldBegin(QStringLiteral("enableSingleNoteSharing"), ThriftFieldType::T_BOOL, 9); - w.writeBool(s.enableSingleNoteSharing.ref()); - w.writeFieldEnd(); - } - if(s.enableSponsoredAccounts.isSet()) { - w.writeFieldBegin(QStringLiteral("enableSponsoredAccounts"), ThriftFieldType::T_BOOL, 10); - w.writeBool(s.enableSponsoredAccounts.ref()); - w.writeFieldEnd(); - } - if(s.enableTwitterSharing.isSet()) { - w.writeFieldBegin(QStringLiteral("enableTwitterSharing"), ThriftFieldType::T_BOOL, 11); - w.writeBool(s.enableTwitterSharing.ref()); - w.writeFieldEnd(); - } - if(s.enableLinkedInSharing.isSet()) { - w.writeFieldBegin(QStringLiteral("enableLinkedInSharing"), ThriftFieldType::T_BOOL, 12); - w.writeBool(s.enableLinkedInSharing.ref()); - w.writeFieldEnd(); - } - if(s.enablePublicNotebooks.isSet()) { - w.writeFieldBegin(QStringLiteral("enablePublicNotebooks"), ThriftFieldType::T_BOOL, 13); - w.writeBool(s.enablePublicNotebooks.ref()); - w.writeFieldEnd(); - } - if(s.enableGoogle.isSet()) { - w.writeFieldBegin(QStringLiteral("enableGoogle"), ThriftFieldType::T_BOOL, 16); - w.writeBool(s.enableGoogle.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readBootstrapSettings(ThriftBinaryBufferReader & r, BootstrapSettings & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool serviceHost_isset = false; - bool marketingUrl_isset = false; - bool supportUrl_isset = false; - bool accountEmailDomain_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - serviceHost_isset = true; - QString v; - r.readString(v); - s.serviceHost = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - marketingUrl_isset = true; - QString v; - r.readString(v); - s.marketingUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_STRING) { - supportUrl_isset = true; - QString v; - r.readString(v); - s.supportUrl = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 4) { - if (fieldType == ThriftFieldType::T_STRING) { - accountEmailDomain_isset = true; - QString v; - r.readString(v); - s.accountEmailDomain = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 5) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.enableFacebookSharing = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 6) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.enableGiftSubscriptions = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 7) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.enableSupportTickets = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 8) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.enableSharedNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 9) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.enableSingleNoteSharing = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 10) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.enableSponsoredAccounts = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 11) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.enableTwitterSharing = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 12) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.enableLinkedInSharing = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 13) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.enablePublicNotebooks = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 16) { - if (fieldType == ThriftFieldType::T_BOOL) { - bool v; - r.readBool(v); - s.enableGoogle = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!serviceHost_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapSettings.serviceHost has no value")); - if(!marketingUrl_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapSettings.marketingUrl has no value")); - if(!supportUrl_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapSettings.supportUrl has no value")); - if(!accountEmailDomain_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapSettings.accountEmailDomain has no value")); -} - -void writeBootstrapProfile(ThriftBinaryBufferWriter & w, const BootstrapProfile & s) { - w.writeStructBegin(QStringLiteral("BootstrapProfile")); - w.writeFieldBegin(QStringLiteral("name"), ThriftFieldType::T_STRING, 1); - w.writeString(s.name); - w.writeFieldEnd(); - w.writeFieldBegin(QStringLiteral("settings"), ThriftFieldType::T_STRUCT, 2); - writeBootstrapSettings(w, s.settings); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readBootstrapProfile(ThriftBinaryBufferReader & r, BootstrapProfile & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool name_isset = false; - bool settings_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - name_isset = true; - QString v; - r.readString(v); - s.name = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRUCT) { - settings_isset = true; - BootstrapSettings v; - readBootstrapSettings(r, v); - s.settings = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!name_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapProfile.name has no value")); - if(!settings_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapProfile.settings has no value")); -} - -void writeBootstrapInfo(ThriftBinaryBufferWriter & w, const BootstrapInfo & s) { - w.writeStructBegin(QStringLiteral("BootstrapInfo")); - w.writeFieldBegin(QStringLiteral("profiles"), ThriftFieldType::T_LIST, 1); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.profiles.length()); - for(QList< BootstrapProfile >::const_iterator it = s.profiles.constBegin(), end = s.profiles.constEnd(); it != end; ++it) { - writeBootstrapProfile(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readBootstrapInfo(ThriftBinaryBufferReader & r, BootstrapInfo & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool profiles_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_LIST) { - profiles_isset = true; - QList< BootstrapProfile > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (BootstrapInfo.profiles)")); - for(qint32 i = 0; i < size; i++) { - BootstrapProfile elem; - readBootstrapProfile(r, elem); - v.append(elem); - } - r.readListEnd(); - s.profiles = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!profiles_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("BootstrapInfo.profiles has no value")); -} - -EDAMUserException::EDAMUserException() {} -EDAMUserException::~EDAMUserException() throw() {} -EDAMUserException::EDAMUserException(const EDAMUserException& other) : EvernoteException(other) -{ - errorCode = other.errorCode; - parameter = other.parameter; -} -void writeEDAMUserException(ThriftBinaryBufferWriter & w, const EDAMUserException & s) { - w.writeStructBegin(QStringLiteral("EDAMUserException")); - w.writeFieldBegin(QStringLiteral("errorCode"), ThriftFieldType::T_I32, 1); - w.writeI32(static_cast(s.errorCode)); - w.writeFieldEnd(); - if(s.parameter.isSet()) { - w.writeFieldBegin(QStringLiteral("parameter"), ThriftFieldType::T_STRING, 2); - w.writeString(s.parameter.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readEDAMUserException(ThriftBinaryBufferReader & r, EDAMUserException & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool errorCode_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - errorCode_isset = true; - EDAMErrorCode::type v; - readEnumEDAMErrorCode(r, v); - s.errorCode = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.parameter = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!errorCode_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("EDAMUserException.errorCode has no value")); -} - -EDAMSystemException::EDAMSystemException() {} -EDAMSystemException::~EDAMSystemException() throw() {} -EDAMSystemException::EDAMSystemException(const EDAMSystemException& other) : EvernoteException(other) -{ - errorCode = other.errorCode; - message = other.message; - rateLimitDuration = other.rateLimitDuration; -} -void writeEDAMSystemException(ThriftBinaryBufferWriter & w, const EDAMSystemException & s) { - w.writeStructBegin(QStringLiteral("EDAMSystemException")); - w.writeFieldBegin(QStringLiteral("errorCode"), ThriftFieldType::T_I32, 1); - w.writeI32(static_cast(s.errorCode)); - w.writeFieldEnd(); - if(s.message.isSet()) { - w.writeFieldBegin(QStringLiteral("message"), ThriftFieldType::T_STRING, 2); - w.writeString(s.message.ref()); - w.writeFieldEnd(); - } - if(s.rateLimitDuration.isSet()) { - w.writeFieldBegin(QStringLiteral("rateLimitDuration"), ThriftFieldType::T_I32, 3); - w.writeI32(s.rateLimitDuration.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readEDAMSystemException(ThriftBinaryBufferReader & r, EDAMSystemException & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool errorCode_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_I32) { - errorCode_isset = true; - EDAMErrorCode::type v; - readEnumEDAMErrorCode(r, v); - s.errorCode = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.message = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_I32) { - qint32 v; - r.readI32(v); - s.rateLimitDuration = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!errorCode_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("EDAMSystemException.errorCode has no value")); -} - -EDAMNotFoundException::EDAMNotFoundException() {} -EDAMNotFoundException::~EDAMNotFoundException() throw() {} -EDAMNotFoundException::EDAMNotFoundException(const EDAMNotFoundException& other) : EvernoteException(other) -{ - identifier = other.identifier; - key = other.key; -} -void writeEDAMNotFoundException(ThriftBinaryBufferWriter & w, const EDAMNotFoundException & s) { - w.writeStructBegin(QStringLiteral("EDAMNotFoundException")); - if(s.identifier.isSet()) { - w.writeFieldBegin(QStringLiteral("identifier"), ThriftFieldType::T_STRING, 1); - w.writeString(s.identifier.ref()); - w.writeFieldEnd(); - } - if(s.key.isSet()) { - w.writeFieldBegin(QStringLiteral("key"), ThriftFieldType::T_STRING, 2); - w.writeString(s.key.ref()); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readEDAMNotFoundException(ThriftBinaryBufferReader & r, EDAMNotFoundException & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.identifier = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.key = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); -} - -EDAMInvalidContactsException::EDAMInvalidContactsException() {} -EDAMInvalidContactsException::~EDAMInvalidContactsException() throw() {} -EDAMInvalidContactsException::EDAMInvalidContactsException(const EDAMInvalidContactsException& other) : EvernoteException(other) -{ - contacts = other.contacts; - parameter = other.parameter; - reasons = other.reasons; -} -void writeEDAMInvalidContactsException(ThriftBinaryBufferWriter & w, const EDAMInvalidContactsException & s) { - w.writeStructBegin(QStringLiteral("EDAMInvalidContactsException")); - w.writeFieldBegin(QStringLiteral("contacts"), ThriftFieldType::T_LIST, 1); - w.writeListBegin(ThriftFieldType::T_STRUCT, s.contacts.length()); - for(QList< Contact >::const_iterator it = s.contacts.constBegin(), end = s.contacts.constEnd(); it != end; ++it) { - writeContact(w, *it); - } - w.writeListEnd(); - w.writeFieldEnd(); - if(s.parameter.isSet()) { - w.writeFieldBegin(QStringLiteral("parameter"), ThriftFieldType::T_STRING, 2); - w.writeString(s.parameter.ref()); - w.writeFieldEnd(); - } - if(s.reasons.isSet()) { - w.writeFieldBegin(QStringLiteral("reasons"), ThriftFieldType::T_LIST, 3); - w.writeListBegin(ThriftFieldType::T_I32, s.reasons.ref().length()); - for(QList< EDAMInvalidContactReason::type >::const_iterator it = s.reasons.ref().constBegin(), end = s.reasons.ref().constEnd(); it != end; ++it) { - w.writeI32(static_cast(*it)); - } - w.writeListEnd(); - w.writeFieldEnd(); - } - w.writeFieldStop(); - w.writeStructEnd(); -} - -void readEDAMInvalidContactsException(ThriftBinaryBufferReader & r, EDAMInvalidContactsException & s) { - QString fname; - ThriftFieldType::type fieldType; - qint16 fieldId; - bool contacts_isset = false; - r.readStructBegin(fname); - while(true) - { - r.readFieldBegin(fname, fieldType, fieldId); - if (fieldType == ThriftFieldType::T_STOP) break; - if (fieldId == 1) { - if (fieldType == ThriftFieldType::T_LIST) { - contacts_isset = true; - QList< Contact > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_STRUCT) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (EDAMInvalidContactsException.contacts)")); - for(qint32 i = 0; i < size; i++) { - Contact elem; - readContact(r, elem); - v.append(elem); - } - r.readListEnd(); - s.contacts = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 2) { - if (fieldType == ThriftFieldType::T_STRING) { - QString v; - r.readString(v); - s.parameter = v; - } else { - r.skip(fieldType); - } - } else - if (fieldId == 3) { - if (fieldType == ThriftFieldType::T_LIST) { - QList< EDAMInvalidContactReason::type > v; - qint32 size; - ThriftFieldType::type elemType; - r.readListBegin(elemType, size); - v.reserve(size); - if(elemType != ThriftFieldType::T_I32) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("Incorrect list type (EDAMInvalidContactsException.reasons)")); - for(qint32 i = 0; i < size; i++) { - EDAMInvalidContactReason::type elem; - readEnumEDAMInvalidContactReason(r, elem); - v.append(elem); - } - r.readListEnd(); - s.reasons = v; - } else { - r.skip(fieldType); - } - } else - { - r.skip(fieldType); - } - r.readFieldEnd(); - } - r.readStructEnd(); - if(!contacts_isset) throw ThriftException(ThriftException::Type::INVALID_DATA, QStringLiteral("EDAMInvalidContactsException.contacts has no value")); -} - - -/** @endcond */ - - - -} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/generated/types_impl.h b/src/qevercloud/QEverCloud/src/generated/types_impl.h deleted file mode 100644 index 14477a4e..00000000 --- a/src/qevercloud/QEverCloud/src/generated/types_impl.h +++ /dev/null @@ -1,215 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - * - * This file was generated from Evernote Thrift API - */ - - -#ifndef QEVERCLOUD_GENERATED_TYPES_IMPL_H -#define QEVERCLOUD_GENERATED_TYPES_IMPL_H - -#include -#include -#include "../impl.h" -#include -#include -#include -#include -#include -#include -#include -#include - -namespace qevercloud { - -/** @cond HIDDEN_SYMBOLS */ - -void writeSyncState(ThriftBinaryBufferWriter & w, const SyncState & s); -void readSyncState(ThriftBinaryBufferReader & r, SyncState & s); -void writeSyncChunk(ThriftBinaryBufferWriter & w, const SyncChunk & s); -void readSyncChunk(ThriftBinaryBufferReader & r, SyncChunk & s); -void writeSyncChunkFilter(ThriftBinaryBufferWriter & w, const SyncChunkFilter & s); -void readSyncChunkFilter(ThriftBinaryBufferReader & r, SyncChunkFilter & s); -void writeNoteFilter(ThriftBinaryBufferWriter & w, const NoteFilter & s); -void readNoteFilter(ThriftBinaryBufferReader & r, NoteFilter & s); -void writeNoteList(ThriftBinaryBufferWriter & w, const NoteList & s); -void readNoteList(ThriftBinaryBufferReader & r, NoteList & s); -void writeNoteMetadata(ThriftBinaryBufferWriter & w, const NoteMetadata & s); -void readNoteMetadata(ThriftBinaryBufferReader & r, NoteMetadata & s); -void writeNotesMetadataList(ThriftBinaryBufferWriter & w, const NotesMetadataList & s); -void readNotesMetadataList(ThriftBinaryBufferReader & r, NotesMetadataList & s); -void writeNotesMetadataResultSpec(ThriftBinaryBufferWriter & w, const NotesMetadataResultSpec & s); -void readNotesMetadataResultSpec(ThriftBinaryBufferReader & r, NotesMetadataResultSpec & s); -void writeNoteCollectionCounts(ThriftBinaryBufferWriter & w, const NoteCollectionCounts & s); -void readNoteCollectionCounts(ThriftBinaryBufferReader & r, NoteCollectionCounts & s); -void writeNoteResultSpec(ThriftBinaryBufferWriter & w, const NoteResultSpec & s); -void readNoteResultSpec(ThriftBinaryBufferReader & r, NoteResultSpec & s); -void writeNoteEmailParameters(ThriftBinaryBufferWriter & w, const NoteEmailParameters & s); -void readNoteEmailParameters(ThriftBinaryBufferReader & r, NoteEmailParameters & s); -void writeNoteVersionId(ThriftBinaryBufferWriter & w, const NoteVersionId & s); -void readNoteVersionId(ThriftBinaryBufferReader & r, NoteVersionId & s); -void writeRelatedQuery(ThriftBinaryBufferWriter & w, const RelatedQuery & s); -void readRelatedQuery(ThriftBinaryBufferReader & r, RelatedQuery & s); -void writeRelatedResult(ThriftBinaryBufferWriter & w, const RelatedResult & s); -void readRelatedResult(ThriftBinaryBufferReader & r, RelatedResult & s); -void writeRelatedResultSpec(ThriftBinaryBufferWriter & w, const RelatedResultSpec & s); -void readRelatedResultSpec(ThriftBinaryBufferReader & r, RelatedResultSpec & s); -void writeUpdateNoteIfUsnMatchesResult(ThriftBinaryBufferWriter & w, const UpdateNoteIfUsnMatchesResult & s); -void readUpdateNoteIfUsnMatchesResult(ThriftBinaryBufferReader & r, UpdateNoteIfUsnMatchesResult & s); -void writeShareRelationshipRestrictions(ThriftBinaryBufferWriter & w, const ShareRelationshipRestrictions & s); -void readShareRelationshipRestrictions(ThriftBinaryBufferReader & r, ShareRelationshipRestrictions & s); -void writeInvitationShareRelationship(ThriftBinaryBufferWriter & w, const InvitationShareRelationship & s); -void readInvitationShareRelationship(ThriftBinaryBufferReader & r, InvitationShareRelationship & s); -void writeMemberShareRelationship(ThriftBinaryBufferWriter & w, const MemberShareRelationship & s); -void readMemberShareRelationship(ThriftBinaryBufferReader & r, MemberShareRelationship & s); -void writeShareRelationships(ThriftBinaryBufferWriter & w, const ShareRelationships & s); -void readShareRelationships(ThriftBinaryBufferReader & r, ShareRelationships & s); -void writeManageNotebookSharesParameters(ThriftBinaryBufferWriter & w, const ManageNotebookSharesParameters & s); -void readManageNotebookSharesParameters(ThriftBinaryBufferReader & r, ManageNotebookSharesParameters & s); -void writeManageNotebookSharesError(ThriftBinaryBufferWriter & w, const ManageNotebookSharesError & s); -void readManageNotebookSharesError(ThriftBinaryBufferReader & r, ManageNotebookSharesError & s); -void writeManageNotebookSharesResult(ThriftBinaryBufferWriter & w, const ManageNotebookSharesResult & s); -void readManageNotebookSharesResult(ThriftBinaryBufferReader & r, ManageNotebookSharesResult & s); -void writeSharedNoteTemplate(ThriftBinaryBufferWriter & w, const SharedNoteTemplate & s); -void readSharedNoteTemplate(ThriftBinaryBufferReader & r, SharedNoteTemplate & s); -void writeNotebookShareTemplate(ThriftBinaryBufferWriter & w, const NotebookShareTemplate & s); -void readNotebookShareTemplate(ThriftBinaryBufferReader & r, NotebookShareTemplate & s); -void writeCreateOrUpdateNotebookSharesResult(ThriftBinaryBufferWriter & w, const CreateOrUpdateNotebookSharesResult & s); -void readCreateOrUpdateNotebookSharesResult(ThriftBinaryBufferReader & r, CreateOrUpdateNotebookSharesResult & s); -void writeNoteShareRelationshipRestrictions(ThriftBinaryBufferWriter & w, const NoteShareRelationshipRestrictions & s); -void readNoteShareRelationshipRestrictions(ThriftBinaryBufferReader & r, NoteShareRelationshipRestrictions & s); -void writeNoteMemberShareRelationship(ThriftBinaryBufferWriter & w, const NoteMemberShareRelationship & s); -void readNoteMemberShareRelationship(ThriftBinaryBufferReader & r, NoteMemberShareRelationship & s); -void writeNoteInvitationShareRelationship(ThriftBinaryBufferWriter & w, const NoteInvitationShareRelationship & s); -void readNoteInvitationShareRelationship(ThriftBinaryBufferReader & r, NoteInvitationShareRelationship & s); -void writeNoteShareRelationships(ThriftBinaryBufferWriter & w, const NoteShareRelationships & s); -void readNoteShareRelationships(ThriftBinaryBufferReader & r, NoteShareRelationships & s); -void writeManageNoteSharesParameters(ThriftBinaryBufferWriter & w, const ManageNoteSharesParameters & s); -void readManageNoteSharesParameters(ThriftBinaryBufferReader & r, ManageNoteSharesParameters & s); -void writeManageNoteSharesError(ThriftBinaryBufferWriter & w, const ManageNoteSharesError & s); -void readManageNoteSharesError(ThriftBinaryBufferReader & r, ManageNoteSharesError & s); -void writeManageNoteSharesResult(ThriftBinaryBufferWriter & w, const ManageNoteSharesResult & s); -void readManageNoteSharesResult(ThriftBinaryBufferReader & r, ManageNoteSharesResult & s); -void writeData(ThriftBinaryBufferWriter & w, const Data & s); -void readData(ThriftBinaryBufferReader & r, Data & s); -void writeUserAttributes(ThriftBinaryBufferWriter & w, const UserAttributes & s); -void readUserAttributes(ThriftBinaryBufferReader & r, UserAttributes & s); -void writeBusinessUserAttributes(ThriftBinaryBufferWriter & w, const BusinessUserAttributes & s); -void readBusinessUserAttributes(ThriftBinaryBufferReader & r, BusinessUserAttributes & s); -void writeAccounting(ThriftBinaryBufferWriter & w, const Accounting & s); -void readAccounting(ThriftBinaryBufferReader & r, Accounting & s); -void writeBusinessUserInfo(ThriftBinaryBufferWriter & w, const BusinessUserInfo & s); -void readBusinessUserInfo(ThriftBinaryBufferReader & r, BusinessUserInfo & s); -void writeAccountLimits(ThriftBinaryBufferWriter & w, const AccountLimits & s); -void readAccountLimits(ThriftBinaryBufferReader & r, AccountLimits & s); -void writeUser(ThriftBinaryBufferWriter & w, const User & s); -void readUser(ThriftBinaryBufferReader & r, User & s); -void writeContact(ThriftBinaryBufferWriter & w, const Contact & s); -void readContact(ThriftBinaryBufferReader & r, Contact & s); -void writeIdentity(ThriftBinaryBufferWriter & w, const Identity & s); -void readIdentity(ThriftBinaryBufferReader & r, Identity & s); -void writeTag(ThriftBinaryBufferWriter & w, const Tag & s); -void readTag(ThriftBinaryBufferReader & r, Tag & s); -void writeLazyMap(ThriftBinaryBufferWriter & w, const LazyMap & s); -void readLazyMap(ThriftBinaryBufferReader & r, LazyMap & s); -void writeResourceAttributes(ThriftBinaryBufferWriter & w, const ResourceAttributes & s); -void readResourceAttributes(ThriftBinaryBufferReader & r, ResourceAttributes & s); -void writeResource(ThriftBinaryBufferWriter & w, const Resource & s); -void readResource(ThriftBinaryBufferReader & r, Resource & s); -void writeNoteAttributes(ThriftBinaryBufferWriter & w, const NoteAttributes & s); -void readNoteAttributes(ThriftBinaryBufferReader & r, NoteAttributes & s); -void writeSharedNote(ThriftBinaryBufferWriter & w, const SharedNote & s); -void readSharedNote(ThriftBinaryBufferReader & r, SharedNote & s); -void writeNoteRestrictions(ThriftBinaryBufferWriter & w, const NoteRestrictions & s); -void readNoteRestrictions(ThriftBinaryBufferReader & r, NoteRestrictions & s); -void writeNoteLimits(ThriftBinaryBufferWriter & w, const NoteLimits & s); -void readNoteLimits(ThriftBinaryBufferReader & r, NoteLimits & s); -void writeNote(ThriftBinaryBufferWriter & w, const Note & s); -void readNote(ThriftBinaryBufferReader & r, Note & s); -void writePublishing(ThriftBinaryBufferWriter & w, const Publishing & s); -void readPublishing(ThriftBinaryBufferReader & r, Publishing & s); -void writeBusinessNotebook(ThriftBinaryBufferWriter & w, const BusinessNotebook & s); -void readBusinessNotebook(ThriftBinaryBufferReader & r, BusinessNotebook & s); -void writeSavedSearchScope(ThriftBinaryBufferWriter & w, const SavedSearchScope & s); -void readSavedSearchScope(ThriftBinaryBufferReader & r, SavedSearchScope & s); -void writeSavedSearch(ThriftBinaryBufferWriter & w, const SavedSearch & s); -void readSavedSearch(ThriftBinaryBufferReader & r, SavedSearch & s); -void writeSharedNotebookRecipientSettings(ThriftBinaryBufferWriter & w, const SharedNotebookRecipientSettings & s); -void readSharedNotebookRecipientSettings(ThriftBinaryBufferReader & r, SharedNotebookRecipientSettings & s); -void writeNotebookRecipientSettings(ThriftBinaryBufferWriter & w, const NotebookRecipientSettings & s); -void readNotebookRecipientSettings(ThriftBinaryBufferReader & r, NotebookRecipientSettings & s); -void writeSharedNotebook(ThriftBinaryBufferWriter & w, const SharedNotebook & s); -void readSharedNotebook(ThriftBinaryBufferReader & r, SharedNotebook & s); -void writeCanMoveToContainerRestrictions(ThriftBinaryBufferWriter & w, const CanMoveToContainerRestrictions & s); -void readCanMoveToContainerRestrictions(ThriftBinaryBufferReader & r, CanMoveToContainerRestrictions & s); -void writeNotebookRestrictions(ThriftBinaryBufferWriter & w, const NotebookRestrictions & s); -void readNotebookRestrictions(ThriftBinaryBufferReader & r, NotebookRestrictions & s); -void writeNotebook(ThriftBinaryBufferWriter & w, const Notebook & s); -void readNotebook(ThriftBinaryBufferReader & r, Notebook & s); -void writeLinkedNotebook(ThriftBinaryBufferWriter & w, const LinkedNotebook & s); -void readLinkedNotebook(ThriftBinaryBufferReader & r, LinkedNotebook & s); -void writeNotebookDescriptor(ThriftBinaryBufferWriter & w, const NotebookDescriptor & s); -void readNotebookDescriptor(ThriftBinaryBufferReader & r, NotebookDescriptor & s); -void writeUserProfile(ThriftBinaryBufferWriter & w, const UserProfile & s); -void readUserProfile(ThriftBinaryBufferReader & r, UserProfile & s); -void writeRelatedContentImage(ThriftBinaryBufferWriter & w, const RelatedContentImage & s); -void readRelatedContentImage(ThriftBinaryBufferReader & r, RelatedContentImage & s); -void writeRelatedContent(ThriftBinaryBufferWriter & w, const RelatedContent & s); -void readRelatedContent(ThriftBinaryBufferReader & r, RelatedContent & s); -void writeBusinessInvitation(ThriftBinaryBufferWriter & w, const BusinessInvitation & s); -void readBusinessInvitation(ThriftBinaryBufferReader & r, BusinessInvitation & s); -void writeUserIdentity(ThriftBinaryBufferWriter & w, const UserIdentity & s); -void readUserIdentity(ThriftBinaryBufferReader & r, UserIdentity & s); -void writePublicUserInfo(ThriftBinaryBufferWriter & w, const PublicUserInfo & s); -void readPublicUserInfo(ThriftBinaryBufferReader & r, PublicUserInfo & s); -void writeUserUrls(ThriftBinaryBufferWriter & w, const UserUrls & s); -void readUserUrls(ThriftBinaryBufferReader & r, UserUrls & s); -void writeAuthenticationResult(ThriftBinaryBufferWriter & w, const AuthenticationResult & s); -void readAuthenticationResult(ThriftBinaryBufferReader & r, AuthenticationResult & s); -void writeBootstrapSettings(ThriftBinaryBufferWriter & w, const BootstrapSettings & s); -void readBootstrapSettings(ThriftBinaryBufferReader & r, BootstrapSettings & s); -void writeBootstrapProfile(ThriftBinaryBufferWriter & w, const BootstrapProfile & s); -void readBootstrapProfile(ThriftBinaryBufferReader & r, BootstrapProfile & s); -void writeBootstrapInfo(ThriftBinaryBufferWriter & w, const BootstrapInfo & s); -void readBootstrapInfo(ThriftBinaryBufferReader & r, BootstrapInfo & s); -void writeEDAMUserException(ThriftBinaryBufferWriter & w, const EDAMUserException & s); -void readEDAMUserException(ThriftBinaryBufferReader & r, EDAMUserException & s); -void writeEDAMSystemException(ThriftBinaryBufferWriter & w, const EDAMSystemException & s); -void readEDAMSystemException(ThriftBinaryBufferReader & r, EDAMSystemException & s); -void writeEDAMNotFoundException(ThriftBinaryBufferWriter & w, const EDAMNotFoundException & s); -void readEDAMNotFoundException(ThriftBinaryBufferReader & r, EDAMNotFoundException & s); -void writeEDAMInvalidContactsException(ThriftBinaryBufferWriter & w, const EDAMInvalidContactsException & s); -void readEDAMInvalidContactsException(ThriftBinaryBufferReader & r, EDAMInvalidContactsException & s); - -void readEnumEDAMErrorCode(ThriftBinaryBufferReader & r, EDAMErrorCode::type & e); -void readEnumEDAMInvalidContactReason(ThriftBinaryBufferReader & r, EDAMInvalidContactReason::type & e); -void readEnumShareRelationshipPrivilegeLevel(ThriftBinaryBufferReader & r, ShareRelationshipPrivilegeLevel::type & e); -void readEnumPrivilegeLevel(ThriftBinaryBufferReader & r, PrivilegeLevel::type & e); -void readEnumServiceLevel(ThriftBinaryBufferReader & r, ServiceLevel::type & e); -void readEnumQueryFormat(ThriftBinaryBufferReader & r, QueryFormat::type & e); -void readEnumNoteSortOrder(ThriftBinaryBufferReader & r, NoteSortOrder::type & e); -void readEnumPremiumOrderStatus(ThriftBinaryBufferReader & r, PremiumOrderStatus::type & e); -void readEnumSharedNotebookPrivilegeLevel(ThriftBinaryBufferReader & r, SharedNotebookPrivilegeLevel::type & e); -void readEnumSharedNotePrivilegeLevel(ThriftBinaryBufferReader & r, SharedNotePrivilegeLevel::type & e); -void readEnumSponsoredGroupRole(ThriftBinaryBufferReader & r, SponsoredGroupRole::type & e); -void readEnumBusinessUserRole(ThriftBinaryBufferReader & r, BusinessUserRole::type & e); -void readEnumBusinessUserStatus(ThriftBinaryBufferReader & r, BusinessUserStatus::type & e); -void readEnumSharedNotebookInstanceRestrictions(ThriftBinaryBufferReader & r, SharedNotebookInstanceRestrictions::type & e); -void readEnumReminderEmailConfig(ThriftBinaryBufferReader & r, ReminderEmailConfig::type & e); -void readEnumBusinessInvitationStatus(ThriftBinaryBufferReader & r, BusinessInvitationStatus::type & e); -void readEnumContactType(ThriftBinaryBufferReader & r, ContactType::type & e); -void readEnumEntityType(ThriftBinaryBufferReader & r, EntityType::type & e); -void readEnumRecipientStatus(ThriftBinaryBufferReader & r, RecipientStatus::type & e); -void readEnumCanMoveToContainerStatus(ThriftBinaryBufferReader & r, CanMoveToContainerStatus::type & e); -void readEnumRelatedContentType(ThriftBinaryBufferReader & r, RelatedContentType::type & e); -void readEnumRelatedContentAccess(ThriftBinaryBufferReader & r, RelatedContentAccess::type & e); -void readEnumUserIdentityType(ThriftBinaryBufferReader & r, UserIdentityType::type & e); - -/** @endcond */ -} // namespace qevercloud - -#endif // QEVERCLOUD_GENERATED_TYPES_IMPL_H diff --git a/src/qevercloud/QEverCloud/src/globals.cpp b/src/qevercloud/QEverCloud/src/globals.cpp deleted file mode 100644 index 924c73fb..00000000 --- a/src/qevercloud/QEverCloud/src/globals.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - */ - -#include -#include -#include -#include - -namespace qevercloud { - -QNetworkAccessManager * evernoteNetworkAccessManager() -{ - static QSharedPointer pNetworkAccessManager; - static QMutex networkAccessManagerMutex; - QMutexLocker mutexLocker(&networkAccessManagerMutex); - if (pNetworkAccessManager.isNull()) { - pNetworkAccessManager = QSharedPointer(new QNetworkAccessManager); - } - return pNetworkAccessManager.data(); -} - -static int qevercloudConnectionTimeout = 180000; - -int connectionTimeout() -{ - return qevercloudConnectionTimeout; -} - -void setConnectionTimeout(int timeout) -{ - qevercloudConnectionTimeout = timeout; -} - -int libraryVersion() -{ - return 4*10000 + 0*100 + 0; -} - -} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/http.cpp b/src/qevercloud/QEverCloud/src/http.cpp deleted file mode 100644 index e38b0fb8..00000000 --- a/src/qevercloud/QEverCloud/src/http.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - */ - -#include -#include -#include -#include "http.h" -#include -#include -#include -#include - -// TEMP!! nixnote addition to allow logger calls -#include "src/logger/qslog.h" -//////////////////////////////////////////////// - -/** @cond HIDDEN_SYMBOLS */ - -namespace qevercloud { - -ReplyFetcher::ReplyFetcher(QObject * parent) : - QObject(parent), - m_success(false), - m_httpStatusCode(0) -{ - m_ticker = new QTimer(this); - QObject::connect(m_ticker, QEC_SIGNAL(QTimer,timeout), this, QEC_SLOT(ReplyFetcher,checkForTimeout)); -} - -void ReplyFetcher::start(QNetworkAccessManager * nam, QUrl url) -{ - QNetworkRequest request; - request.setUrl(url); - start(nam, request); -} - -void ReplyFetcher::start(QNetworkAccessManager * nam, QNetworkRequest request, QByteArray postData) -{ - m_httpStatusCode= 0; - m_errorText.clear(); - m_receivedData.clear(); - m_success = true; // not in finished() signal handler, it might not be called according to the docs - // besides, I've added timeout feature - - m_lastNetworkTime = QDateTime::currentMSecsSinceEpoch(); - m_ticker->start(1000); - - if (postData.isNull()) { - m_reply = QSharedPointer(nam->get(request), &QObject::deleteLater); - } - else { - m_reply = QSharedPointer(nam->post(request, postData), &QObject::deleteLater); - } - - QObject::connect(m_reply.data(), QEC_SIGNAL(QNetworkReply,finished), this, QEC_SLOT(ReplyFetcher,onFinished)); - QObject::connect(m_reply.data(), SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError(QNetworkReply::NetworkError))); - QObject::connect(m_reply.data(), QEC_SIGNAL(QNetworkReply,sslErrors,QList), this, QEC_SLOT(ReplyFetcher,onSslErrors,QList)); - QObject::connect(m_reply.data(), QEC_SIGNAL(QNetworkReply,downloadProgress,qint64,qint64), this, QEC_SLOT(ReplyFetcher,onDownloadProgress,qint64,qint64)); -} - -void ReplyFetcher::onDownloadProgress(qint64, qint64) -{ - m_lastNetworkTime = QDateTime::currentMSecsSinceEpoch(); -} - -void ReplyFetcher::checkForTimeout() -{ - const int timeout = connectionTimeout(); - if (timeout < 0) { - return; - } - - if ((QDateTime::currentMSecsSinceEpoch() - m_lastNetworkTime) > timeout) { - setError(QStringLiteral("Request timeout.")); - } -} - -void ReplyFetcher::onFinished() -{ - QLOG_DEBUG() << "QEverCloud.http.ReplyFetcher.onFinished m_success=" << m_success; - m_ticker->stop(); - - if (!m_success) { - return; - } - - m_receivedData = m_reply->readAll(); - m_httpStatusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - QLOG_DEBUG() << "QEverCloud.http.ReplyFetcher.onFinished m_httpStatusCode=" << m_httpStatusCode - << " datalen=" << m_receivedData.size(); - - QObject::disconnect(m_reply.data()); - emit replyFetched(this); -} - -void ReplyFetcher::onError(QNetworkReply::NetworkError error) -{ - auto errorText = m_reply->errorString(); - QLOG_DEBUG() << "QEverCloud.http.ReplyFetcher.onError: code=" << error - << " (" << ((int) error) << ") " - << ", text=" << errorText - << ", m_success=" << m_success; - - // // applied patch from https://github.com/d1vanov/QEverCloud/commit/012425c98e52406fc5f3aa69750eba84b931a5a3 - // // Workaround for Evernote server problems - // if ((error == QNetworkReply::UnknownContentError) && - // errorText.endsWith(QStringLiteral("server replied: OK"))) { - // // ignore this, it's actually ok - // QLOG_WARN() << "QEverCloud.http.ReplyFetcher.onError: error is ignored " - // << "(it's actually ok)"; - // return; - // } - setError(errorText); -} - -void ReplyFetcher::onSslErrors(QList errors) -{ - QString errorText = QStringLiteral("SSL Errors:\n"); - - for(int i = 0, numErrors = errors.size(); i < numErrors; ++i) { - const QSslError & error = errors[i]; - errorText += error.errorString().append(QStringLiteral("\n")); - } - - setError(errorText); -} - -void ReplyFetcher::setError(QString errorText) -{ - m_success = false; - m_ticker->stop(); - m_errorText = errorText; - QObject::disconnect(m_reply.data()); - emit replyFetched(this); -} - -QByteArray simpleDownload(QNetworkAccessManager* nam, QNetworkRequest request, - QByteArray postData, int * httpStatusCode) -{ - ReplyFetcher * fetcher = new ReplyFetcher; - QEventLoop loop; - QObject::connect(fetcher, SIGNAL(replyFetched(QObject * )), &loop, SLOT(quit())); - - ReplyFetcherLauncher *fetcherLauncher = new ReplyFetcherLauncher(fetcher, nam, request, postData); - QTimer::singleShot(0, fetcherLauncher, SLOT(start())); - - qint64 time1 = QDateTime::currentMSecsSinceEpoch(); - QString url = request.url().toString(); - QLOG_DEBUG() << "QEverCloud.http.simpleDownload: sending http request url=" << url; - QLOG_TRACE() << "postData=" << postData; - loop.exec(QEventLoop::ExcludeUserInputEvents); - - fetcherLauncher->deleteLater(); - - qint64 time2 = QDateTime::currentMSecsSinceEpoch(); - int httpCodeLocal = fetcher->httpStatusCode(); - bool isError = fetcher->isError(); - *httpStatusCode = httpCodeLocal; - - QByteArray receivedData = fetcher->receivedData(); - - - QLOG_DEBUG() << "QEverCloud.http.simpleDownload: got reply for url=" << url << ", http code " << httpCodeLocal - << ", isError=" << isError - << ", " << (time2 - time1) << " ms"; - QLOG_DEBUG() << "QEverCloud.http.simpleDownload: got reply for url=" << url; - QLOG_TRACE() << "data=" << receivedData; - - if (isError) { - QString errorText = fetcher->errorText(); - QLOG_WARN() << "QEverCloud.http.simpleDownload: reply for url=" << url - << " is error: " << errorText << " => EverCloudException " << errorText; - fetcher->deleteLater(); - throw EverCloudException(errorText); - } - - fetcher->deleteLater(); - return receivedData; -} - -QNetworkRequest createEvernoteRequest(QString url) -{ - QNetworkRequest request; - request.setUrl(url); - request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-thrift")); - -#if QT_VERSION < 0x050000 - request.setRawHeader("User-Agent", QString::fromUtf8("QEverCloud %1.%2").arg(libraryVersion() / 10000).arg(libraryVersion() % 10000).toLatin1()); -#else - request.setHeader(QNetworkRequest::UserAgentHeader, QStringLiteral("QEverCloud %1.%2").arg(libraryVersion() / 10000).arg(libraryVersion() % 10000)); -#endif - - request.setRawHeader("Accept", "application/x-thrift"); - return request; -} - -QByteArray askEvernote(QString url, QByteArray postData) -{ - QLOG_DEBUG() << "QEverCloud.http.askEvernote: sending http request url=" << url; - int httpStatusCode = 0; - QByteArray reply = simpleDownload(evernoteNetworkAccessManager(), createEvernoteRequest(url), postData, &httpStatusCode); - - if (httpStatusCode != 200) { - QLOG_WARN() << "QEverCloud.askEvernote: http code=" << httpStatusCode << " => EverCloudException"; - - throw EverCloudException(QStringLiteral("HTTP Status Code = %1").arg(httpStatusCode)); - } - - return reply; -} - -ReplyFetcherLauncher::ReplyFetcherLauncher(ReplyFetcher * fetcher, QNetworkAccessManager * nam, - const QNetworkRequest & request, const QByteArray & postData) : - QObject(nam), - m_fetcher(fetcher), - m_nam(nam), - m_request(request), - m_postData(postData) -{} - -void ReplyFetcherLauncher::start() -{ - m_fetcher->start(m_nam, m_request, m_postData); -} - -} // namespace qevercloud - -/** @endcond */ diff --git a/src/qevercloud/QEverCloud/src/http.h b/src/qevercloud/QEverCloud/src/http.h deleted file mode 100644 index 0438166c..00000000 --- a/src/qevercloud/QEverCloud/src/http.h +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - */ - -#ifndef QEVERCLOUD_HTTP_H -#define QEVERCLOUD_HTTP_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** @cond HIDDEN_SYMBOLS */ - -namespace qevercloud { - -QNetworkAccessManager * evernoteNetworkAccessManager(); - -// the class greatly simplifies QNetworkReply handling -class ReplyFetcher: public QObject -{ - Q_OBJECT -public: - ReplyFetcher(QObject * parent = Q_NULLPTR); - - void start(QNetworkAccessManager * nam, QUrl url); - // if !postData.isNull() then POST will be issued instead of GET - void start(QNetworkAccessManager * nam, QNetworkRequest request, QByteArray postData = QByteArray()); - bool isError() { return !m_success; } - QString errorText() { return m_errorText; } - QByteArray receivedData() { return m_receivedData; } - int httpStatusCode() { return m_httpStatusCode; } - -Q_SIGNALS: - void replyFetched(QObject*); // sends itself - -private Q_SLOTS: - void onFinished(); - void onError(QNetworkReply::NetworkError); - void onSslErrors(QList l); - void onDownloadProgress(qint64, qint64); - void checkForTimeout(); - -private: - void setError(QString errorText); - -private: - QSharedPointer m_reply; - bool m_success; - QString m_errorText; - QByteArray m_receivedData; - int m_httpStatusCode; - QTimer* m_ticker; - qint64 m_lastNetworkTime; -}; - -QNetworkRequest createEvernoteRequest(QString url); - -QByteArray askEvernote(QString url, QByteArray postData); - -QByteArray simpleDownload(QNetworkAccessManager * nam, QNetworkRequest request, - QByteArray postData = QByteArray(), int * httpStatusCode = Q_NULLPTR); - -class ReplyFetcherLauncher: public QObject -{ - Q_OBJECT -public: - explicit ReplyFetcherLauncher(ReplyFetcher * fetcher, QNetworkAccessManager * nam, - const QNetworkRequest & request, const QByteArray & postData); - -public Q_SLOTS: - void start(); - -private: - ReplyFetcher * m_fetcher; - QNetworkAccessManager * m_nam; - QNetworkRequest m_request; - QByteArray m_postData; -}; - -} // namespace qevercloud - -/** @endcond */ - -#endif // QEVERCLOUD_HTTP_H diff --git a/src/qevercloud/QEverCloud/src/oauth.cpp b/src/qevercloud/QEverCloud/src/oauth.cpp deleted file mode 100644 index c24fde40..00000000 --- a/src/qevercloud/QEverCloud/src/oauth.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - */ - -#include -#include -#include "http.h" -#include -#include - -#ifdef QEVERCLOUD_USE_QT_WEB_ENGINE -#include -#include -#else -#include -#include -#include -#endif - -#include -#include - -/** @cond HIDDEN_SYMBOLS */ - -namespace { - - quint64 random64() - { - quint64 res = 0; - for(int i = 0; i < 8; i++) { - res += static_cast(qrand() % 256) << i*8; - } - - QByteArray randomData = QUuid::createUuid().toRfc4122(); - quint64 random; - std::memcpy(&random, &randomData.constData()[0], sizeof(random)); - res ^= random; - std::memcpy(&random, &randomData.constData()[sizeof(random)], sizeof(random)); - res ^= random; - - return res; - } - - typedef quint64 (*NonceGenerator)(); - NonceGenerator nonceGenerator_ = random64; - - NonceGenerator nonceGenerator() {return nonceGenerator_;} -} - -void setNonceGenerator(quint64 (*nonceGenerator)()) -{ - nonceGenerator_ = nonceGenerator; -} - -namespace qevercloud { - -#ifdef QEVERCLOUD_USE_QT_WEB_ENGINE -class EvernoteOAuthWebViewPrivate: public QWebEngineView -#else -class EvernoteOAuthWebViewPrivate: public QWebView -#endif -{ - Q_OBJECT -public: - EvernoteOAuthWebViewPrivate(QWidget * parent = Q_NULLPTR); - -Q_SIGNALS: - void authenticationFinished(bool success); - void authenticationSuceeded(); - void authenticationFailed(); - -public Q_SLOTS: - void temporaryFinished(QObject * rf); - void permanentFinished(QObject * rf); - void onUrlChanged(const QUrl & url); - void clearHtml(); - -public: - void setError(QString error); - - bool m_isSucceeded; - QSize m_sizeHint; - QString m_errorText; - QString m_oauthUrlBase; - QString m_host; - EvernoteOAuthWebView::OAuthResult m_oauthResult; -}; - -EvernoteOAuthWebViewPrivate::EvernoteOAuthWebViewPrivate(QWidget * parent) -#ifdef QEVERCLOUD_USE_QT_WEB_ENGINE - : QWebEngineView(parent), m_isSucceeded(false) -#else - : QWebView(parent), m_isSucceeded(false) -#endif -{ -#ifndef QEVERCLOUD_USE_QT_WEB_ENGINE - page()->setNetworkAccessManager(evernoteNetworkAccessManager()); -#endif -} - -void EvernoteOAuthWebViewPrivate::setError(QString errorText) -{ - m_isSucceeded = false; - this->setHtml(QLatin1String("")); - this->history()->clear(); - m_errorText = errorText; - emit authenticationFinished(false); - emit authenticationFailed(); -} - -EvernoteOAuthWebView::EvernoteOAuthWebView(QWidget * parent) : - QWidget(parent), - d_ptr(new EvernoteOAuthWebViewPrivate(this)) -{ - QObject::connect(d_ptr, QEC_SIGNAL(EvernoteOAuthWebViewPrivate,authenticationFinished,bool), - this, QEC_SIGNAL(EvernoteOAuthWebView,authenticationFinished,bool)); - QObject::connect(d_ptr, QEC_SIGNAL(EvernoteOAuthWebViewPrivate,authenticationSuceeded), - this, QEC_SIGNAL(EvernoteOAuthWebView,authenticationSuceeded)); - QObject::connect(d_ptr, QEC_SIGNAL(EvernoteOAuthWebViewPrivate,authenticationFailed), - this, QEC_SIGNAL(EvernoteOAuthWebView,authenticationFailed)); - - QVBoxLayout * pLayout = new QVBoxLayout(this); - pLayout->addWidget(d_ptr); - setLayout(pLayout); -} - -void EvernoteOAuthWebView::authenticate(QString host, QString consumerKey, QString consumerSecret) -{ - Q_D(EvernoteOAuthWebView); - d->m_host = host; - d->m_isSucceeded = false; - d->setHtml(QLatin1String("")); - d->history()->clear(); - - qint64 timestamp = QDateTime::currentMSecsSinceEpoch()/1000; - quint64 nonce = nonceGenerator()(); - d->m_oauthUrlBase = QStringLiteral("https://%1/oauth?oauth_consumer_key=%2&oauth_signature=%3&oauth_signature_method=PLAINTEXT&oauth_timestamp=%4&oauth_nonce=%5") - .arg(host, consumerKey, consumerSecret).arg(timestamp).arg(nonce); - - // step 1: acquire temporary token - ReplyFetcher * replyFetcher = new ReplyFetcher(); - QObject::connect(replyFetcher, QEC_SIGNAL(ReplyFetcher,replyFetched,QObject*), - d, QEC_SLOT(EvernoteOAuthWebViewPrivate,temporaryFinished,QObject*)); - QUrl url(d->m_oauthUrlBase + QStringLiteral("&oauth_callback=nnoauth")); -#ifdef QEVERCLOUD_USE_QT_WEB_ENGINE - replyFetcher->start(evernoteNetworkAccessManager(), url); -#else - replyFetcher->start(d->page()->networkAccessManager(), url); -#endif -} - -bool EvernoteOAuthWebView::isSucceeded() const -{ - Q_D(const EvernoteOAuthWebView); - return d->m_isSucceeded; -} - -QString EvernoteOAuthWebView::oauthError() const -{ - Q_D(const EvernoteOAuthWebView); - return d->m_errorText; -} - -EvernoteOAuthWebView::OAuthResult EvernoteOAuthWebView::oauthResult() const -{ - Q_D(const EvernoteOAuthWebView); - return d->m_oauthResult; -} - -void EvernoteOAuthWebView::setSizeHint(QSize sizeHint) -{ - Q_D(EvernoteOAuthWebView); - d->m_sizeHint = sizeHint; - updateGeometry(); -} - -QSize EvernoteOAuthWebView::sizeHint() const -{ - Q_D(const EvernoteOAuthWebView); - return d->m_sizeHint; -} - -void EvernoteOAuthWebViewPrivate::temporaryFinished(QObject * rf) -{ - ReplyFetcher * replyFetcher = qobject_cast(rf); - if (replyFetcher->isError()) - { - setError(replyFetcher->errorText()); - } - else - { - QString reply = QString::fromUtf8(replyFetcher->receivedData().constData()); - int index = reply.indexOf(QStringLiteral("&oauth_token_secret")); - QString token = reply.left(index); - - // step 2: directing a user to the login page - QObject::connect(this, QEC_SIGNAL(EvernoteOAuthWebViewPrivate,urlChanged,QUrl), - this, QEC_SLOT(EvernoteOAuthWebViewPrivate,onUrlChanged,QUrl)); - QUrl loginUrl(QStringLiteral("https://%1//OAuth.action?%2").arg(m_host, token)); - setUrl(loginUrl); - } - - replyFetcher->deleteLater(); -} - -void EvernoteOAuthWebViewPrivate::onUrlChanged(const QUrl & url) -{ - // step 3: catch the redirect to our callback url (nnoauth) - QString s = url.toString(); - QString oauthMarker = QStringLiteral("?oauth_token="); - if (s.contains(QStringLiteral("nnoauth?")) && s.contains(oauthMarker)) - { - if (s.contains(QStringLiteral("&oauth_verifier="))) - { // success - QString token = s.mid(s.indexOf(oauthMarker) + oauthMarker.length()); - - // step 4: acquire permanent token - ReplyFetcher * replyFetcher = new ReplyFetcher(); - QObject::connect(replyFetcher, QEC_SIGNAL(ReplyFetcher,replyFetched,QObject*), - this, QEC_SLOT(EvernoteOAuthWebViewPrivate,permanentFinished,QObject*)); - QUrl url(m_oauthUrlBase + QStringLiteral("&oauth_token=%1").arg(token)); -#ifdef QEVERCLOUD_USE_QT_WEB_ENGINE - replyFetcher->start(evernoteNetworkAccessManager(), url); -#else - replyFetcher->start(page()->networkAccessManager(), url); -#endif - } - else - { - setError(QStringLiteral("Authentification failed.")); - } - - QObject::disconnect(this, QEC_SIGNAL(EvernoteOAuthWebViewPrivate,urlChanged,QUrl), - this, QEC_SLOT(EvernoteOAuthWebViewPrivate,onUrlChanged,QUrl)); - QMetaObject::invokeMethod(this, "clearHtml", Qt::QueuedConnection); - } -} - -void EvernoteOAuthWebViewPrivate::permanentFinished(QObject * rf) -{ - ReplyFetcher * replyFetcher = qobject_cast(rf); - if (replyFetcher->isError()) - { - setError(replyFetcher->errorText()); - } - else - { - m_isSucceeded = true; - - QByteArray reply = replyFetcher->receivedData(); - QMap params; - QList vals = reply.split('&'); - - for(int i = 0, size = vals.length(); i < size; i++) { - QString decoded = QUrl::fromPercentEncoding(vals[i]); - int pos = decoded.indexOf(QStringLiteral("=")); - params[decoded.left(pos).trimmed()] = decoded.mid(pos + 1); - } - - m_oauthResult.noteStoreUrl = params[QStringLiteral("edam_noteStoreUrl")]; - m_oauthResult.expires = Timestamp(params[QStringLiteral("edam_expires")].toLongLong()); - m_oauthResult.shardId = params[QStringLiteral("edam_shard")]; - m_oauthResult.userId = params[QStringLiteral("edam_userId")].toInt(); - m_oauthResult.webApiUrlPrefix = params[QStringLiteral("edam_webApiUrlPrefix")]; - m_oauthResult.authenticationToken = params[QStringLiteral("oauth_token")]; - - emit authenticationFinished(true); - emit authenticationSuceeded(); - } - - replyFetcher->deleteLater(); -} - -void EvernoteOAuthWebViewPrivate::clearHtml() -{ - setHtml(QLatin1String("")); -} - -class EvernoteOAuthDialogPrivate -{ -public: - EvernoteOAuthDialogPrivate(const QString & host, const QString & consumerKey, const QString & consumerSecret) : - m_pWebView(Q_NULLPTR), - m_host(host), - m_consumerKey(consumerKey), - m_consumerSecret(consumerSecret) - {} - - EvernoteOAuthWebView* m_pWebView; - QString m_host; - QString m_consumerKey; - QString m_consumerSecret; -}; - -EvernoteOAuthDialog::EvernoteOAuthDialog(QString consumerKey, QString consumerSecret, QString host, QWidget *parent) : - QDialog(parent), - d_ptr(new EvernoteOAuthDialogPrivate(host, consumerKey, consumerSecret)) -{ - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - d_ptr->m_pWebView = new EvernoteOAuthWebView(this); - - QObject::connect(d_ptr->m_pWebView, QEC_SIGNAL(EvernoteOAuthWebView,authenticationSuceeded), - this, QEC_SLOT(EvernoteOAuthDialog,accept), Qt::QueuedConnection); - QObject::connect(d_ptr->m_pWebView, QEC_SIGNAL(EvernoteOAuthWebView,authenticationFailed), - this, QEC_SLOT(EvernoteOAuthDialog,reject), Qt::QueuedConnection); - - QVBoxLayout * pLayout = new QVBoxLayout(this); - pLayout->addWidget(d_ptr->m_pWebView); - setLayout(pLayout); - - d_ptr->m_pWebView->setSizeHint(QSize(768,576)); - adjustSize(); -} - -EvernoteOAuthDialog::~EvernoteOAuthDialog() -{ -#ifndef QEVERCLOUD_USE_QT_WEB_ENGINE - QWebSettings::clearMemoryCaches(); -#endif - - delete d_ptr; -} - -void EvernoteOAuthDialog::setWebViewSizeHint(QSize sizeHint) -{ - Q_D(EvernoteOAuthDialog); - d->m_pWebView->setSizeHint(sizeHint); -} - -bool EvernoteOAuthDialog::isSucceeded() const -{ - Q_D(const EvernoteOAuthDialog); - return d->m_pWebView->isSucceeded(); -} - -QString EvernoteOAuthDialog::oauthError() const -{ - Q_D(const EvernoteOAuthDialog); - return d->m_pWebView->oauthError(); -} - -EvernoteOAuthDialog::OAuthResult EvernoteOAuthDialog::oauthResult() const -{ - Q_D(const EvernoteOAuthDialog); - return d->m_pWebView->oauthResult(); -} - -int EvernoteOAuthDialog::exec() -{ - Q_D(EvernoteOAuthDialog); - d->m_pWebView->authenticate(d->m_host, d->m_consumerKey, d->m_consumerSecret); - return QDialog::exec(); -} - -void EvernoteOAuthDialog::open() -{ - Q_D(EvernoteOAuthDialog); - QDialog::open(); - d->m_pWebView->authenticate(d->m_host, d->m_consumerKey, d->m_consumerSecret); -} - -} // namespace qevercloud - -/** @endcond */ - -#include "oauth.moc" diff --git a/src/qevercloud/QEverCloud/src/oauth/AbstractOAuthEngine.cpp b/src/qevercloud/QEverCloud/src/oauth/AbstractOAuthEngine.cpp new file mode 100644 index 00000000..b435b835 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/AbstractOAuthEngine.cpp @@ -0,0 +1,206 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#include "AbstractOAuthEngine.h" +#include "NonceGenerator.h" + +#include +#include + +namespace qevercloud { + +EvernoteOAuthWebView::OAuthResult AbstractOAuthEngine::oauthResult() const +{ + return m_oauthResult; +} + +void AbstractOAuthEngine::setSizeHint(QSize sizeHint) +{ + m_sizeHint = sizeHint; +} + +QSize AbstractOAuthEngine::sizeHintValue() const noexcept +{ + return m_sizeHint; +} + +void AbstractOAuthEngine::authenticate( + QString host, QString consumerKey, QString consumerSecret, + const qint64 timeoutMsec) +{ + m_host = host; + m_isSucceeded = false; + m_timeoutMsec = timeoutMsec; + + if (!onStartAuthentication()) { + onAuthenticationFinished(false); + return; + } + + qint64 timestamp = QDateTime::currentMSecsSinceEpoch()/1000; + quint64 nonce = nonceGenerator()(); + m_oauthUrlBase = + QString::fromUtf8("https://%1/oauth?oauth_consumer_key=%2&" + "oauth_signature=%3&" + "oauth_signature_method=PLAINTEXT&" + "oauth_timestamp=%4&oauth_nonce=%5") + .arg(host, consumerKey, consumerSecret).arg(timestamp).arg(nonce); + + // step 1: acquire temporary token + ReplyFetcher * replyFetcher = new ReplyFetcher(context()); + QObject::connect( + replyFetcher, + &ReplyFetcher::replyFetched, + context(), + [this](ReplyFetcher * rf) + { + onTemporaryFinished(rf); + }); + + QUrl url( + m_oauthUrlBase + + QString::fromUtf8("&oauth_callback=%1").arg(oauthCallbackUrl())); + + auto * pNam = networkAccessManager(replyFetcher); + Q_ASSERT(pNam); + + pNam->setProxy(evernoteNetworkProxy()); + replyFetcher->start(pNam, url, timeoutMsec); +} + +bool AbstractOAuthEngine::onOAuthCallback(const QString & url) +{ + QEC_DEBUG("oauth[abstract]", "AbstractOAuthEngine::onOAuthCallback"); + + // step 3: catch the redirect to our callback url + bool result = false; + const QString oauthMarker = QStringLiteral("?oauth_token="); + if (url.contains(oauthMarker)) + { + if (url.contains(QStringLiteral("&oauth_verifier="))) + { + QEC_DEBUG( + "oauth[abstract]", + "Received approval for permanent token receipt"); + + result = true; + QString token = + url.mid(url.indexOf(oauthMarker) + oauthMarker.length()); + + // step 4: acquire permanent token + QEC_DEBUG( + "oauth[abstract]", + "Sending request to acquire permanent token"); + + ReplyFetcher * replyFetcher = new ReplyFetcher(context()); + QObject::connect( + replyFetcher, + &ReplyFetcher::replyFetched, + context(), + [this](ReplyFetcher * rf) + { + onPermanentFinished(rf); + }); + + QUrl url{ + m_oauthUrlBase + + QString::fromUtf8("&oauth_token=%1").arg(token)}; + + auto * pNam = networkAccessManager(replyFetcher); + pNam->setProxy(evernoteNetworkProxy()); + replyFetcher->start(pNam, url, m_timeoutMsec); + } + else + { + QEC_WARNING("oauth[abstract]", "Authentication failed"); + setError(QStringLiteral("Authentification failed.")); + } + + onOAuthResponseReceived(); + } + + return result; +} + +void AbstractOAuthEngine::setError(QString error) +{ + m_isSucceeded = false; + + clear(); + + m_errorText = error; + onAuthenticationFinished(false); +} + +void AbstractOAuthEngine::onTemporaryFinished(ReplyFetcher * rf) +{ + Q_ASSERT(rf); + if (rf->isError()) + { + QEC_WARNING("oauth[abstract]", "Failed to acquire temporary token: " + << rf->errorText()); + setError(rf->errorText()); + } + else + { + QEC_DEBUG("oauth[abstract]", "Successfully acquired temporary token"); + QString reply = QString::fromUtf8(rf->receivedData().constData()); + int index = reply.indexOf(QStringLiteral("&oauth_token_secret")); + QString token = reply.left(index); + + // step 2: directing a user to the login page + QUrl pageUrl{ + QString::fromUtf8("https://%1//OAuth.action?%2") + .arg(m_host, std::move(token))}; + + openOAuthPage(std::move(pageUrl)); + } + + rf->deleteLater(); +} + +void AbstractOAuthEngine::onPermanentFinished(ReplyFetcher * rf) +{ + Q_ASSERT(rf); + if (rf->isError()) + { + QEC_WARNING("oauth[abstract]", "Failed to acquire permanent token"); + setError(rf->errorText()); + } + else + { + QEC_DEBUG("oauth[abstract]", "Successfully acquired permanent token"); + + m_isSucceeded = true; + + QByteArray reply = rf->receivedData(); + QMap params; + QList vals = reply.split('&'); + + for(int i = 0, size = vals.length(); i < size; i++) { + QString decoded = QUrl::fromPercentEncoding(vals[i]); + int pos = decoded.indexOf(QStringLiteral("=")); + params[decoded.left(pos).trimmed()] = decoded.mid(pos + 1); + } + + m_oauthResult.noteStoreUrl = params[QStringLiteral("edam_noteStoreUrl")]; + m_oauthResult.expires = + Timestamp(params[QStringLiteral("edam_expires")].toLongLong()); + m_oauthResult.shardId = params[QStringLiteral("edam_shard")]; + m_oauthResult.userId = params[QStringLiteral("edam_userId")].toInt(); + m_oauthResult.webApiUrlPrefix = + params[QStringLiteral("edam_webApiUrlPrefix")]; + m_oauthResult.authenticationToken = params[QStringLiteral("oauth_token")]; + + m_oauthResult.cookies = extractCookies(rf); + onAuthenticationFinished(true); + } + + rf->deleteLater(); +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/oauth/AbstractOAuthEngine.h b/src/qevercloud/QEverCloud/src/oauth/AbstractOAuthEngine.h new file mode 100644 index 00000000..177b9d6a --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/AbstractOAuthEngine.h @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_ABSTRACT_OAUTH_ENGINE_H +#define QEVERCLOUD_ABSTRACT_OAUTH_ENGINE_H + +#include "../Http.h" + +#include + +#include +#include + +namespace qevercloud { + +class AbstractOAuthEngine +{ +public: + [[nodiscard]] bool isSucceeded() const noexcept { return m_isSucceeded; } + [[nodiscard]] QString oauthError() const { return m_errorText; } + [[nodiscard]] EvernoteOAuthWebView::OAuthResult oauthResult() const; + + void setSizeHint(QSize sizeHint); + [[nodiscard]] QSize sizeHintValue() const noexcept; + + void authenticate( + QString host, QString consumerKey, QString consumerSecret, + const qint64 timeoutMsec); + +protected: // Methods that subclassed need to call when appropriate + bool onOAuthCallback(const QString & url); + void setError(QString error); + +protected: // Interface for subclasses to implement + virtual void onAuthenticationFinished(bool success) = 0; + virtual void openOAuthPage(QUrl pageUrl) = 0; + virtual void onOAuthResponseReceived() = 0; + virtual void clear() = 0; + [[nodiscard]] virtual QObject * context() = 0; + [[nodiscard]] virtual bool onStartAuthentication() = 0; + [[nodiscard]] virtual QString oauthCallbackUrl() const = 0; + + [[nodiscard]] virtual QNetworkAccessManager * networkAccessManager( + QObject * rf) = 0; + + [[nodiscard]] virtual QList extractCookies( + ReplyFetcher * pReplyFetcher) = 0; + +private: + void onTemporaryFinished(ReplyFetcher * rf); + void onPermanentFinished(ReplyFetcher * rf); + +protected: + bool m_isSucceeded = false; + QSize m_sizeHint; + QString m_errorText; + QString m_oauthUrlBase; + QString m_host; + qint64 m_timeoutMsec = 0; + EvernoteOAuthWebView::OAuthResult m_oauthResult; +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_ABSTRACT_OAUTH_ENGINE_H diff --git a/src/qevercloud/QEverCloud/src/oauth/NetworkCookieJar.cpp b/src/qevercloud/QEverCloud/src/oauth/NetworkCookieJar.cpp new file mode 100644 index 00000000..cc4e445e --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/NetworkCookieJar.cpp @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2020-2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include "NetworkCookieJar.h" + +#include +#include + +namespace qevercloud { + +void NetworkCookieJar::loadStore() +{ + auto * pProfile = QWebEngineProfile::defaultProfile(); + auto * pCookieStore = pProfile->cookieStore(); + + QObject::connect( + pCookieStore, + &QWebEngineCookieStore::cookieAdded, + this, + &NetworkCookieJar::handleCookieAdded, + Qt::ConnectionType(Qt::UniqueConnection | Qt::DirectConnection)); + + pCookieStore->loadAllCookies(); +} + +void NetworkCookieJar::handleCookieAdded(const QNetworkCookie & cookie) +{ + Q_UNUSED(QNetworkCookieJar::insertCookie(cookie)) +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/oauth/NetworkCookieJar.h b/src/qevercloud/QEverCloud/src/oauth/NetworkCookieJar.h new file mode 100644 index 00000000..f992f8c2 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/NetworkCookieJar.h @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2020-2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_OAUTH_NETWORK_COOKIE_JAR_H +#define QEVERCLOUD_OAUTH_NETWORK_COOKIE_JAR_H + +#include +#include + +namespace qevercloud { + +/** + * @brief The NetworkCookieJar class is a small class subclassing from + * QNetworkCookieJar and exposing its protected members. + * + * When QEverCloud uses QtWebEngine, this class is also capable of collecting + * cookies from QtWebEngine's default profile + */ +class NetworkCookieJar: public QNetworkCookieJar +{ + Q_OBJECT +public: + explicit NetworkCookieJar(QObject * parent = nullptr) : + QNetworkCookieJar(parent) + {} + + QList allCookies() + { + return QNetworkCookieJar::allCookies(); + } + + void setAllCookies(QList cookies) + { + QNetworkCookieJar::setAllCookies(std::move(cookies)); + } + +#if QEVERCLOUD_USE_QT_WEB_ENGINE + void loadStore(); + +private Q_SLOTS: + void handleCookieAdded(const QNetworkCookie & cookie); +#endif +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_OAUTH_NETWORK_COOKIE_JAR_H diff --git a/src/qevercloud/QEverCloud/src/oauth/NonceGenerator.cpp b/src/qevercloud/QEverCloud/src/oauth/NonceGenerator.cpp new file mode 100644 index 00000000..f4966e8d --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/NonceGenerator.cpp @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#include "NonceGenerator.h" + +#include +#include + +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) +#include +#endif + +#include + +namespace qevercloud { + +namespace { + +[[nodiscard]] quint64 random64() +{ + quint64 res = 0; + for(int i = 0; i < 8; i++) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + res += (QRandomGenerator::global()->generate64() % 256) << i*8; +#else + res += static_cast(qrand() % 256) << i*8; +#endif + } + + QByteArray randomData = QUuid::createUuid().toRfc4122(); + quint64 random; + std::memcpy(&random, &randomData.constData()[0], sizeof(random)); + + res ^= random; + + std::memcpy( + &random, + &randomData.constData()[sizeof(random)], + sizeof(random)); + + res ^= random; + return res; +} + +NonceGenerator nonceGenerator_ = random64; + +} // namespace + +NonceGenerator nonceGenerator() +{ + return nonceGenerator_; +} + +void setNonceGenerator(quint64 (*nonceGenerator)()) +{ + nonceGenerator_ = nonceGenerator; +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/oauth/NonceGenerator.h b/src/qevercloud/QEverCloud/src/oauth/NonceGenerator.h new file mode 100644 index 00000000..721ebadd --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/NonceGenerator.h @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_OAUTH_NONCE_GENERATOR_H +#define QEVERCLOUD_OAUTH_NONCE_GENERATOR_H + +#include + +namespace qevercloud { + +typedef quint64 (*NonceGenerator)(); + +[[nodiscard]] NonceGenerator nonceGenerator(); + +} // namespace qevercloud + +#endif // QEVERCLOUD_OAUTH_NONCE_GENERATOR_H diff --git a/src/qevercloud/QEverCloud/src/oauth/OAuth.cpp b/src/qevercloud/QEverCloud/src/oauth/OAuth.cpp new file mode 100644 index 00000000..80afd451 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/OAuth.cpp @@ -0,0 +1,205 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include + +#include + +#if QEVERCLOUD_USE_QT_WEB_ENGINE +#include "OAuthWebEngine.h" +#elif QEVERCLOUD_USE_SYSTEM_BROWSER +#include "OAuthSystemBrowser.h" +#else +#include "OAuthWebKit.h" +#endif + +#include + +namespace qevercloud { + +EvernoteOAuthWebView::EvernoteOAuthWebView(QWidget * parent) : + QWidget(parent), + d_ptr(new EvernoteOAuthWebViewPrivate(this)) +{ + QObject::connect( + d_ptr, &EvernoteOAuthWebViewPrivate::authenticationFinished, + this, + [this](const bool success) + { + Q_EMIT authenticationFinished(success); + + if (success) { + Q_EMIT authenticationSuceeded(); + } + else { + Q_EMIT authenticationFailed(); + } + }); + + QVBoxLayout * pLayout = new QVBoxLayout(this); + pLayout->addWidget(d_ptr); + setLayout(pLayout); +} + +void EvernoteOAuthWebView::authenticate( + QString host, QString consumerKey, QString consumerSecret, + const qint64 timeoutMsec) +{ + QEC_DEBUG("oauth", "Sending request to acquire temporary token"); + + Q_D(EvernoteOAuthWebView); + d->authenticate( + std::move(host), std::move(consumerKey), std::move(consumerSecret), + timeoutMsec); +} + +bool EvernoteOAuthWebView::isSucceeded() const +{ + Q_D(const EvernoteOAuthWebView); + return d->isSucceeded(); +} + +QString EvernoteOAuthWebView::oauthError() const +{ + Q_D(const EvernoteOAuthWebView); + return d->oauthError(); +} + +EvernoteOAuthWebView::OAuthResult EvernoteOAuthWebView::oauthResult() const +{ + Q_D(const EvernoteOAuthWebView); + return d->oauthResult(); +} + +void EvernoteOAuthWebView::setSizeHint(QSize sizeHint) +{ + Q_D(EvernoteOAuthWebView); + d->setSizeHint(sizeHint); + updateGeometry(); +} + +QSize EvernoteOAuthWebView::sizeHint() const +{ + Q_D(const EvernoteOAuthWebView); + return d->sizeHintValue(); +} + +//////////////////////////////////////////////////////////////////////////////// + +void EvernoteOAuthWebView::OAuthResult::print(QTextStream & strm) const +{ + strm << "qevercloud::EvernoteOAuthWebView::OAuthResult {\n"; + + strm << " noteStoreUrl = " << noteStoreUrl << ";\n"; + strm << " expires = " << expires << ";\n"; + strm << " shardId = " << shardId << ";\n"; + strm << " userId = " << QString::number(userId) << ";\n"; + strm << " webApiUrlPrefix = " << webApiUrlPrefix << ";\n"; + strm << " authenticationToken " + << (authenticationToken.isEmpty() + ? "is empty" + : "is not empty") << ";\n"; + strm << " cookies count: " << cookies.size() << ";\n"; + + strm << "};\n"; +} + +//////////////////////////////////////////////////////////////////////////////// + +class EvernoteOAuthDialogPrivate +{ +public: + EvernoteOAuthDialogPrivate( + const QString & host, const QString & consumerKey, + const QString & consumerSecret) : + m_pWebView(nullptr), + m_host(host), + m_consumerKey(consumerKey), + m_consumerSecret(consumerSecret) + {} + + EvernoteOAuthWebView * m_pWebView; + QString m_host; + QString m_consumerKey; + QString m_consumerSecret; +}; + +//////////////////////////////////////////////////////////////////////////////// + +EvernoteOAuthDialog::EvernoteOAuthDialog( + QString consumerKey, QString consumerSecret, QString host, + QWidget * parent) : + QDialog(parent), + d_ptr(new EvernoteOAuthDialogPrivate(host, consumerKey, consumerSecret)) +{ + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + d_ptr->m_pWebView = new EvernoteOAuthWebView(this); + + QObject::connect( + d_ptr->m_pWebView, &EvernoteOAuthWebView::authenticationSuceeded, + this, &EvernoteOAuthDialog::accept, Qt::QueuedConnection); + + QObject::connect( + d_ptr->m_pWebView, &EvernoteOAuthWebView::authenticationFailed, + this, &EvernoteOAuthDialog::reject, Qt::QueuedConnection); + + QVBoxLayout * pLayout = new QVBoxLayout(this); + pLayout->addWidget(d_ptr->m_pWebView); + setLayout(pLayout); + + d_ptr->m_pWebView->setSizeHint(QSize(768,576)); + adjustSize(); +} + +EvernoteOAuthDialog::~EvernoteOAuthDialog() +{ + delete d_ptr; +} + +void EvernoteOAuthDialog::setWebViewSizeHint(QSize sizeHint) +{ + Q_D(EvernoteOAuthDialog); + d->m_pWebView->setSizeHint(sizeHint); +} + +bool EvernoteOAuthDialog::isSucceeded() const +{ + Q_D(const EvernoteOAuthDialog); + return d->m_pWebView->isSucceeded(); +} + +QString EvernoteOAuthDialog::oauthError() const +{ + Q_D(const EvernoteOAuthDialog); + return d->m_pWebView->oauthError(); +} + +EvernoteOAuthDialog::OAuthResult EvernoteOAuthDialog::oauthResult() const +{ + Q_D(const EvernoteOAuthDialog); + return d->m_pWebView->oauthResult(); +} + +int EvernoteOAuthDialog::exec() +{ + Q_D(EvernoteOAuthDialog); + d->m_pWebView->authenticate(d->m_host, d->m_consumerKey, d->m_consumerSecret); + return QDialog::exec(); +} + +void EvernoteOAuthDialog::open() +{ + Q_D(EvernoteOAuthDialog); + QDialog::open(); + d->m_pWebView->authenticate(d->m_host, d->m_consumerKey, d->m_consumerSecret); +} + +} // namespace qevercloud + +/** @endcond */ diff --git a/src/qevercloud/QEverCloud/src/oauth/OAuthSystemBrowser.cpp b/src/qevercloud/QEverCloud/src/oauth/OAuthSystemBrowser.cpp new file mode 100644 index 00000000..a8ba0774 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/OAuthSystemBrowser.cpp @@ -0,0 +1,329 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#include "OAuthSystemBrowser.h" + +#include "NetworkCookieJar.h" + +#include "../HttpRequestParser.h" +#include "../HttpUtils.h" + +#include + +#include +#include +#include + +namespace qevercloud { + +EvernoteOAuthWebViewPrivate::EvernoteOAuthWebViewPrivate(QWidget * parent) : + QWidget(parent) +{} + +void EvernoteOAuthWebViewPrivate::onAuthenticationFinished(bool success) +{ + Q_EMIT authenticationFinished(success); +} + +void EvernoteOAuthWebViewPrivate::openOAuthPage(QUrl pageUrl) +{ + auto * verticalLayout = new QVBoxLayout(this); + verticalLayout->setObjectName(QStringLiteral("verticalLayout")); + + const auto titleText = + QObject::tr( + "Authentication", + "qevercloud::EvernoteOAuthWebViewPrivate"); + + auto * titleLabel = new QLabel(this); + titleLabel->setText( + QString::fromUtf8( + "

    " + "%1" + "

    ").arg(titleText)); + + verticalLayout->addWidget(titleLabel); + + auto * descriptionLabel = new QLabel(this); + descriptionLabel->setText( + QObject::tr( + "Open the link below in your browser and authenticate the " + "application to access the data in your Evernote account", + "qevercloud::EvernoteOAuthWebViewPrivate")); + + verticalLayout->addWidget(descriptionLabel); + + m_oauthLinkLabel = new QLabel(this); + + Q_ASSERT(m_oauthLinkLabel); + m_oauthLinkLabel->setText( + QString::fromUtf8("%1").arg(pageUrl.toString())); + m_oauthLinkLabel->setTextFormat(Qt::RichText); + m_oauthLinkLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); + m_oauthLinkLabel->setOpenExternalLinks(true); + m_oauthLinkLabel->setWordWrap(true); + + verticalLayout->addWidget(m_oauthLinkLabel); + setLayout(verticalLayout); + adjustSize(); +} + +void EvernoteOAuthWebViewPrivate::onOAuthResponseReceived() +{ +} + +void EvernoteOAuthWebViewPrivate::clear() +{ +} + +QObject * EvernoteOAuthWebViewPrivate::context() +{ + return this; +} + +bool EvernoteOAuthWebViewPrivate::onStartAuthentication() +{ + Q_ASSERT(!m_oauthCallbackServer); + m_oauthCallbackServer = new QTcpServer(this); + const bool listen = m_oauthCallbackServer->listen(QHostAddress::LocalHost); + if (Q_UNLIKELY(!listen)) { + QEC_ERROR( + "oauth[browser]", + "Failed to set up local TCP server to listen for OAuth callback: " + << "(" << m_oauthCallbackServer->serverError() << ") " + << m_oauthCallbackServer->errorString()); + return false; + } + + QTcpSocket * pSocket = nullptr; + QObject::connect( + m_oauthCallbackServer, + &QTcpServer::newConnection, + this, + [this] { + QEC_DEBUG( + "oauth[browser]", + "New connection for OAuth callback server"); + + if (Q_UNLIKELY(!m_oauthCallbackServer)) { + QEC_INFO( + "oauth[browser]", + "OAuth callback server has already been shut down"); + return; + } + + auto pSocket = m_oauthCallbackServer->nextPendingConnection(); + Q_ASSERT(pSocket); + + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QEC_ERROR( + "oauth[browser]", + "Local OAuth callback server failed to establish incoming " + "connection"); + m_errorText = QObject::tr( + "Failed to establish connection between browser and local " + "OAuth server", + "qevercloud::EvernoteOAuthWebViewPrivate"); + Q_EMIT authenticationFinished(false); + return; + } + + auto pWeakSocket = QPointer{pSocket}; + + auto * pHttpRequestParser = new HttpRequestParser(*pSocket, this); + QObject::connect( + pHttpRequestParser, + &HttpRequestParser::finished, + this, + [this, pHttpRequestParser, pWeakSocket] + { + QEC_DEBUG( + "oauth[browser]", "HttpRequestParser is finished"); + + auto httpRequestData = pHttpRequestParser->requestData(); + pHttpRequestParser->deleteLater(); + + if (onOAuthCallback(QString::fromUtf8(httpRequestData.uri))) { + respondWithAuthenticationIsCompletePage(pWeakSocket); + } + else { + respondWithAuthenticationFailedPage(pWeakSocket); + } + }); + + QObject::connect( + pHttpRequestParser, + &HttpRequestParser::failed, + this, + [this, pHttpRequestParser, pWeakSocket] + { + QEC_WARNING("oauth[browser]", "HttpRequestParser failed"); + + setError(QObject::tr( + "Authentification failed", + "qevercloud::EvernoteOAuthWebViewPrivate")); + + pHttpRequestParser->deleteLater(); + respondWithAuthenticationFailedPage(pWeakSocket); + }); + }); + + return true; +} + +QString EvernoteOAuthWebViewPrivate::oauthCallbackUrl() const +{ + Q_ASSERT(m_oauthCallbackServer); + return QString::fromUtf8(QUrl( + QString::fromUtf8("http://127.0.0.1:%1") + .arg(m_oauthCallbackServer->serverPort())).toEncoded()); +} + +QNetworkAccessManager * EvernoteOAuthWebViewPrivate::networkAccessManager( + QObject * rf) +{ + auto * pNam = new QNetworkAccessManager(rf); + pNam->setCookieJar(new NetworkCookieJar); + return pNam; +} + +QList EvernoteOAuthWebViewPrivate::extractCookies( + ReplyFetcher * pReplyFetcher) +{ + Q_ASSERT(pReplyFetcher); + + auto * pNam = pReplyFetcher->networkAccessManager(); + if (Q_UNLIKELY(!pNam)) { + QEC_WARNING("oauth[browser]", "Failed to extract cookies after OAuth: " + << "network access manager instance expired"); + return {}; + } + + auto * pCookieJar = qobject_cast(pNam->cookieJar()); + if (Q_UNLIKELY(!pCookieJar)) { + QEC_WARNING("oauth[browser]", "Failed to extract cookies after OAuth: " + << "unexpected instance of cookie jar"); + return {}; + } + + return pCookieJar->allCookies(); +} + +void EvernoteOAuthWebViewPrivate::respondWithAuthenticationIsCompletePage( + const QPointer & pWeakSocket) +{ + QEC_DEBUG( + "oauth[browser]", + "Responding with authentication is complete HTML page on OAuth " + << "callback request"); + + respondImpl( + authenticationIsCompleteResponseText(), pWeakSocket); +} + +void EvernoteOAuthWebViewPrivate::respondWithAuthenticationFailedPage( + const QPointer & pWeakSocket) +{ + QEC_DEBUG( + "oauth[browser]", + "Responding with authentication failed HTML page on OAuth callback " + << "request"); + + respondImpl( + authenticationFailedResponseText(), pWeakSocket); +} + +void EvernoteOAuthWebViewPrivate::respondImpl( + const QString & text, const QPointer & pWeakSocket) +{ + if (pWeakSocket.isNull()) { + QEC_WARNING( + "oauth[browser]", + "Cannot respond on OAuth callback request: socket is dead"); + return; + } + + auto * pSocket = pWeakSocket.data(); + + QByteArray responseHtml = QString::fromUtf8( + "

    " + "%1" + "

    ").arg(text).toUtf8(); + + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(responseHtml.size()); + buffer.append("\r\n"); + buffer.append("Content-Type: text/html\r\n\r\n"); + buffer.append(responseHtml); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QEC_WARNING( + "oauth[browser]", + "Failed to write response to socket for OAuth callback"); + cleanupSocketAndServer(pWeakSocket); + return; + } + + QEC_DEBUG("oauth[browser]", "Responded on OAuth callback request"); + + // Need to cleanup the resources but not immediately: the browser needs the + // socket still open until it is able to receive the entire response + auto timer = new QTimer(this); + timer->setSingleShot(true); + timer->setInterval(5000); // 5 seconds should be enough + QObject::connect( + timer, + &QTimer::timeout, + this, + [this, timer, pWeakSocket] + { + timer->deleteLater(); + cleanupSocketAndServer(pWeakSocket); + }); + + timer->start(); +} + +QString EvernoteOAuthWebViewPrivate::authenticationIsCompleteResponseText() const +{ + return QObject::tr( + "Authentication is complete! You can now close " + "this page and return to the app", + "qevercloud::EvernoteOAuthWebViewPrivate"); +} + +QString EvernoteOAuthWebViewPrivate::authenticationFailedResponseText() const +{ + return QObject::tr( + "Authentication failed!", + "qevercloud::EvernoteOAuthWebViewPrivate"); +} + +void EvernoteOAuthWebViewPrivate::cleanupSocketAndServer( + const QPointer & pWeakSocket) +{ + if (!pWeakSocket.isNull()) { + auto * pSocket = pWeakSocket.data(); + pSocket->close(); + pSocket->deleteLater(); + } + + if (m_oauthCallbackServer) { + m_oauthCallbackServer->close(); + m_oauthCallbackServer->deleteLater(); + m_oauthCallbackServer = nullptr; + } +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/oauth/OAuthSystemBrowser.h b/src/qevercloud/QEverCloud/src/oauth/OAuthSystemBrowser.h new file mode 100644 index 00000000..c5a09e3e --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/OAuthSystemBrowser.h @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_OAUTH_SYSTEM_BROWSER_H +#define QEVERCLOUD_OAUTH_SYSTEM_BROWSER_H + +#include "AbstractOAuthEngine.h" + +#include +#include + +QT_BEGIN_NAMESPACE; + +class QLabel; +class QTcpServer; +class QTcpSocket; + +QT_END_NAMESPACE; + +namespace qevercloud { + +class EvernoteOAuthWebViewPrivate: public QWidget, public AbstractOAuthEngine +{ + Q_OBJECT +public: + explicit EvernoteOAuthWebViewPrivate(QWidget * parent = nullptr); + +Q_SIGNALS: + void authenticationFinished(bool success); + +private: // AbstractOAuthEngine + void onAuthenticationFinished(bool success) override; + void openOAuthPage(QUrl pageUrl) override; + void onOAuthResponseReceived() override; + void clear() override; + [[nodiscard]] QObject * context() override; + [[nodiscard]] bool onStartAuthentication() override; + [[nodiscard]] QString oauthCallbackUrl() const override; + + [[nodiscard]] QNetworkAccessManager * networkAccessManager( + QObject * rf) override; + + [[nodiscard]] QList extractCookies( + ReplyFetcher * pReplyFetcher) override; + +private: + void respondWithAuthenticationIsCompletePage( + const QPointer & pWeakSocket); + + void respondWithAuthenticationFailedPage( + const QPointer & pWeakSocket); + + void respondImpl( + const QString & text, const QPointer & pWeakSocket); + + [[nodiscard]] QString authenticationIsCompleteResponseText() const; + [[nodiscard]] QString authenticationFailedResponseText() const; + + void cleanupSocketAndServer(const QPointer & pWeakSocket); + +private: + QTcpServer * m_oauthCallbackServer = nullptr; + QLabel * m_oauthLinkLabel = nullptr; +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_OAUTH_SYSTEM_BROWSER_H diff --git a/src/qevercloud/QEverCloud/src/oauth/OAuthWebEngine.cpp b/src/qevercloud/QEverCloud/src/oauth/OAuthWebEngine.cpp new file mode 100644 index 00000000..0ca97577 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/OAuthWebEngine.cpp @@ -0,0 +1,106 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#include "OAuthWebEngine.h" + +#include "NetworkCookieJar.h" +#include "Utils.h" + +#include + +namespace qevercloud { + +EvernoteOAuthWebViewPrivate::EvernoteOAuthWebViewPrivate(QWidget * parent) : + QWebEngineView(parent), + m_pCookieJar{new NetworkCookieJar(this)} +{ + m_pCookieJar->loadStore(); + + page()->profile()->defaultProfile()->setHttpAcceptLanguage( + httpAcceptLanguage()); +} + +void EvernoteOAuthWebViewPrivate::clearHtml() +{ + setHtml(QLatin1String("")); +} + +void EvernoteOAuthWebViewPrivate::onUrlChanged(const QUrl & url) +{ + const auto urlString = url.toString(); + if (!urlString.contains(QString::fromUtf8("%1?").arg(oauthCallbackUrl()))) { + return; + } + + onOAuthCallback(urlString); +} + +void EvernoteOAuthWebViewPrivate::onAuthenticationFinished(bool success) +{ + Q_EMIT authenticationFinished(success); +} + +void EvernoteOAuthWebViewPrivate::openOAuthPage(QUrl pageUrl) +{ + QEC_DEBUG("oauth[webengine]", "EvernoteOAuthWebViewPrivate::openOAuthPage"); + + QObject::connect( + this, &EvernoteOAuthWebViewPrivate::urlChanged, + this, &EvernoteOAuthWebViewPrivate::onUrlChanged); + + setUrl(std::move(pageUrl)); +} + +void EvernoteOAuthWebViewPrivate::onOAuthResponseReceived() +{ + QObject::disconnect( + this, &EvernoteOAuthWebViewPrivate::urlChanged, + this, &EvernoteOAuthWebViewPrivate::onUrlChanged); + + QMetaObject::invokeMethod(this, "clearHtml", Qt::QueuedConnection); +} + +void EvernoteOAuthWebViewPrivate::clear() +{ + setHtml(QLatin1String("")); + history()->clear(); +} + +QObject * EvernoteOAuthWebViewPrivate::context() +{ + return this; +} + +bool EvernoteOAuthWebViewPrivate::onStartAuthentication() +{ + setHtml(QLatin1String("")); + history()->clear(); + return true; +} + +QString EvernoteOAuthWebViewPrivate::oauthCallbackUrl() const +{ + return QStringLiteral("nnoauth"); +} + +QNetworkAccessManager * EvernoteOAuthWebViewPrivate::networkAccessManager( + QObject * rf) +{ + auto * pNam = new QNetworkAccessManager(rf); + pNam->setCookieJar(new NetworkCookieJar); + return pNam; +} + +QList EvernoteOAuthWebViewPrivate::extractCookies( + ReplyFetcher * rf) +{ + Q_UNUSED(rf) + Q_ASSERT(m_pCookieJar); + return m_pCookieJar->allCookies(); +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/oauth/OAuthWebEngine.h b/src/qevercloud/QEverCloud/src/oauth/OAuthWebEngine.h new file mode 100644 index 00000000..05ee1da9 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/OAuthWebEngine.h @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_OAUTH_WEBENGINE_H +#define QEVERCLOUD_OAUTH_WEBENGINE_H + +#include "AbstractOAuthEngine.h" + +#include +#include +#include + +namespace qevercloud { + +class NetworkCookieJar; + +class EvernoteOAuthWebViewPrivate: + public QWebEngineView, public AbstractOAuthEngine +{ + Q_OBJECT +public: + explicit EvernoteOAuthWebViewPrivate(QWidget * parent = nullptr); + +Q_SIGNALS: + void authenticationFinished(bool success); + +public Q_SLOTS: + void clearHtml(); + +private Q_SLOTS: + void onUrlChanged(const QUrl & url); + +private: // AbstractOAuthEngine + void onAuthenticationFinished(bool success) override; + void openOAuthPage(QUrl pageUrl) override; + void onOAuthResponseReceived() override; + void clear() override; + [[nodiscard]] QObject * context() override; + [[nodiscard]] bool onStartAuthentication() override; + [[nodiscard]] QString oauthCallbackUrl() const override; + + [[nodiscard]] QNetworkAccessManager * networkAccessManager( + QObject * rf) override; + + [[nodiscard]] QList extractCookies( + ReplyFetcher * pReplyFetcher) override; + +private: + NetworkCookieJar * m_pCookieJar = nullptr; +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_OAUTH_WEBENGINE_H diff --git a/src/qevercloud/QEverCloud/src/oauth/OAuthWebKit.cpp b/src/qevercloud/QEverCloud/src/oauth/OAuthWebKit.cpp new file mode 100644 index 00000000..491ccbdf --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/OAuthWebKit.cpp @@ -0,0 +1,130 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#include "OAuthWebKit.h" + +#include "NetworkCookieJar.h" +#include "Utils.h" + +#include +#include + +namespace qevercloud { + +EvernoteOAuthWebViewPrivate::EvernoteOAuthWebViewPrivate(QWidget * parent) : + QWebView(parent) +{ + auto * pNam = page()->networkAccessManager(); + pNam->setProxy(evernoteNetworkProxy()); + pNam->setCookieJar(new NetworkCookieJar); +} + +EvernoteOAuthWebViewPrivate::~EvernoteOAuthWebViewPrivate() +{ + QWebSettings::clearMemoryCaches(); +} + +void EvernoteOAuthWebViewPrivate::clearHtml() +{ + setHtml(QLatin1String("")); +} + +void EvernoteOAuthWebViewPrivate::onUrlChanged(const QUrl & url) +{ + const auto urlString = url.toString(); + if (!urlString.contains(QString::fromUtf8("%1?").arg(oauthCallbackUrl()))) { + // Hack which appears to solve the problem of login page freezing on + // analytics pitstop + back(); + return; + } + + onOAuthCallback(urlString); +} + +void EvernoteOAuthWebViewPrivate::onAuthenticationFinished(bool success) +{ + Q_EMIT authenticationFinished(success); +} + +void EvernoteOAuthWebViewPrivate::openOAuthPage(QUrl pageUrl) +{ + QEC_DEBUG("oauth[webkit]", "EvernoteOAuthWebViewPrivate::openOAuthPage"); + + QObject::connect( + this, &EvernoteOAuthWebViewPrivate::urlChanged, + this, &EvernoteOAuthWebViewPrivate::onUrlChanged); + + QNetworkRequest request; + request.setUrl(pageUrl); + request.setRawHeader( + QByteArray("Accept-Language"), httpAcceptLanguage().toUtf8()); + + load(request); +} + +void EvernoteOAuthWebViewPrivate::onOAuthResponseReceived() +{ + QObject::disconnect( + this, &EvernoteOAuthWebViewPrivate::urlChanged, + this, &EvernoteOAuthWebViewPrivate::onUrlChanged); + + QMetaObject::invokeMethod(this, "clearHtml", Qt::QueuedConnection); +} + +void EvernoteOAuthWebViewPrivate::clear() +{ + setHtml(QLatin1String("")); + history()->clear(); +} + +QObject * EvernoteOAuthWebViewPrivate::context() +{ + return this; +} + +bool EvernoteOAuthWebViewPrivate::onStartAuthentication() +{ + setHtml(QLatin1String("")); + history()->clear(); + return true; +} + +QString EvernoteOAuthWebViewPrivate::oauthCallbackUrl() const +{ + return QStringLiteral("nnoauth"); +} + +QNetworkAccessManager * EvernoteOAuthWebViewPrivate::networkAccessManager( + QObject * rf) +{ + return page()->networkAccessManager(); +} + +QList EvernoteOAuthWebViewPrivate::extractCookies( + ReplyFetcher * rf) +{ + Q_ASSERT(rf); + + auto * pNam = rf->networkAccessManager(); + if (Q_UNLIKELY(!pNam)) { + QEC_WARNING("oauth[webkit]", "Failed to extract cookies after OAuth: " + << "network access manager instance expired"); + return {}; + } + + auto * pCookieJar = qobject_cast(pNam->cookieJar()); + if (Q_UNLIKELY(!pCookieJar)) { + QEC_WARNING("oauth[webkit]", "Failed to extract cookies after OAuth: " + << "unexpected instance of cookie jar"); + return {}; + } + + return pCookieJar->allCookies(); +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/oauth/OAuthWebKit.h b/src/qevercloud/QEverCloud/src/oauth/OAuthWebKit.h new file mode 100644 index 00000000..7153aa8e --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/OAuthWebKit.h @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_OAUTH_WEBKIT_H +#define QEVERCLOUD_OAUTH_WEBKIT_H + +#include "AbstractOAuthEngine.h" + +#include +#include +#include +#include +#include + +namespace qevercloud { + +class EvernoteOAuthWebViewPrivate: public QWebView, public AbstractOAuthEngine +{ + Q_OBJECT +public: + explicit EvernoteOAuthWebViewPrivate(QWidget * parent = nullptr); + ~EvernoteOAuthWebViewPrivate() override; + +Q_SIGNALS: + void authenticationFinished(bool success); + +public Q_SLOTS: + void clearHtml(); + +private Q_SLOTS: + void onUrlChanged(const QUrl & url); + +private: // AbstractOAuthEngine + void onAuthenticationFinished(bool success) override; + void openOAuthPage(QUrl pageUrl) override; + void onOAuthResponseReceived() override; + void clear() override; + [[nodiscard]] QObject * context() override; + [[nodiscard]] bool onStartAuthentication() override; + [[nodiscard]] QString oauthCallbackUrl() const override; + + [[nodiscard]] QNetworkAccessManager * networkAccessManager( + QObject * rf) override; + + [[nodiscard]] QList extractCookies( + ReplyFetcher * pReplyFetcher) override; +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_OAUTH_WEBKIT_H diff --git a/src/qevercloud/QEverCloud/src/oauth/Utils.cpp b/src/qevercloud/QEverCloud/src/oauth/Utils.cpp new file mode 100644 index 00000000..3712bd99 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/Utils.cpp @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#include "Utils.h" + +#include + +namespace qevercloud { + +QString httpAcceptLanguage() +{ + auto uiLanguages = QLocale::system().uiLanguages(); + const QString en = QStringLiteral("en"); + if (!uiLanguages.contains(en)) { + uiLanguages << en; + } + + return uiLanguages.join(QStringLiteral(", ")); +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/oauth/Utils.h b/src/qevercloud/QEverCloud/src/oauth/Utils.h new file mode 100644 index 00000000..10920dae --- /dev/null +++ b/src/qevercloud/QEverCloud/src/oauth/Utils.h @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_OAUTH_UTILS_H +#define QEVERCLOUD_OAUTH_UTILS_H + +#include + +namespace qevercloud { + +[[nodiscard]] QString httpAcceptLanguage(); + +} // namespace qevercloud + +#endif // QEVERCLOUD_OAUTH_UTILS_H diff --git a/src/qevercloud/QEverCloud/src/services_nongenerated.cpp b/src/qevercloud/QEverCloud/src/services_nongenerated.cpp deleted file mode 100644 index 79c0b192..00000000 --- a/src/qevercloud/QEverCloud/src/services_nongenerated.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - */ - -#include -#include -#include - -namespace qevercloud { - -/** - * @brief Constructs UserStore object. - * @param host - * www.evernote.com or sandbox.evernote.com - * @param authenticationToken - * This token that will be used as the default token. - */ -UserStore::UserStore(QString host, QString authenticationToken, QObject * parent) : - QObject(parent) -{ - QUrl url; - url.setScheme(QStringLiteral("https")); - url.setHost(host); - url.setPath(QStringLiteral("/edam/user")); - m_url = url.toString(QUrl::StripTrailingSlash); - setAuthenticationToken(authenticationToken); -} - -/** - * Constructs NoteStore object. - * @param noteStoreUrl - * EDAM NoteStore service url. In general it's different for different users. - * @param authenticationToken - * This token that will be used as the default token. - * - */ -NoteStore::NoteStore(QString noteStoreUrl, QString authenticationToken, QObject * parent) : - QObject(parent) -{ - setNoteStoreUrl(noteStoreUrl); - setAuthenticationToken(authenticationToken); -} - -/** - * Constructs NoteStore object. - * - * noteStoreUrl and possibly authenticationToken are expected to be specified later. - */ -NoteStore::NoteStore(QObject * parent) : - QObject(parent) -{} - -/** @fn qevercloud::UserStore::setAuthenticationToken - * Sets a value that will be used as the default token. - * */ - -/** @fn qevercloud::UserStore::authenticationToken - * @returns the default authentication token value. - * */ - -/** @fn qevercloud::NoteStore::setAuthenticationToken - * Sets a value that will be used as the default token. - * */ - -/** @fn qevercloud::NoteStore::authenticationToken - * @returns the default authentication token value. - * */ - -/** @fn qevercloud::NoteStore::setNoteStoreUrl - * Sets a value that will be used as EDAM NoteStore service url by this object. - * */ - -/** @fn qevercloud::NoteStore::authenticationToken - * @returns EDAM NoteStore service url that is used by this NoteStore object. - * */ - -} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/tests/MessageHandler.cpp b/src/qevercloud/QEverCloud/src/tests/MessageHandler.cpp new file mode 100644 index 00000000..f487fc7d --- /dev/null +++ b/src/qevercloud/QEverCloud/src/tests/MessageHandler.cpp @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include "MessageHandler.h" + +#include +#include + +#include +#include + +namespace qevercloud { + +void testMessageOutput( + const QtMsgType type, const QMessageLogContext & context, + const QString & msg) +{ + QByteArray localMsg = msg.toLocal8Bit(); + const char *file = context.file ? context.file : ""; + const char *function = context.function ? context.function : ""; + switch (type) { + case QtDebugMsg: + fprintf( + stderr, + "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, + function); + break; + case QtInfoMsg: + fprintf( + stderr, + "Info: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, + function); + break; + case QtWarningMsg: + fprintf( + stderr, + "Warning: %s (%s:%u, %s)\n", localMsg.constData(), file, + context.line, function); + break; + case QtCriticalMsg: + fprintf( + stderr, + "Critical: %s (%s:%u, %s)\n", localMsg.constData(), file, + context.line, function); + break; + case QtFatalMsg: + fprintf( + stderr, + "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, + function); + break; + } +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/tests/MessageHandler.h b/src/qevercloud/QEverCloud/src/tests/MessageHandler.h new file mode 100644 index 00000000..f8055331 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/tests/MessageHandler.h @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2023 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_TESTS_MESSAGE_HANDLER_H +#define QEVERCLOUD_TESTS_MESSAGE_HANDLER_H + +#include + +namespace qevercloud { + +void testMessageOutput( + QtMsgType type, const QMessageLogContext & context, const QString & msg); + +} // namespace qevercloud + +#endif // QEVERCLOUD_TESTS_MESSAGE_HANDLER_H diff --git a/src/qevercloud/QEverCloud/src/tests/TestDurableService.cpp b/src/qevercloud/QEverCloud/src/tests/TestDurableService.cpp new file mode 100644 index 00000000..c923fd77 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/tests/TestDurableService.cpp @@ -0,0 +1,430 @@ +/** + * Copyright (c) 2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include "TestDurableService.h" + +#include +#include + +#include +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +class ValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit ValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QVariant m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + Q_UNUSED(ctx) + m_value = value; + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +DurableServiceTester::DurableServiceTester(QObject * parent) : + QObject(parent) +{} + +void DurableServiceTester::shouldExecuteSyncServiceCall() +{ + auto durableService = newDurableService(); + + bool serviceCallDetected = false; + QVariant value = QStringLiteral("value"); + + IDurableService::SyncRequest request("request", {}, + [&] (IRequestContextPtr ctx) -> IDurableService::SyncResult { + Q_ASSERT(ctx); + serviceCallDetected = true; + return {value, {}}; + }); + + auto result = durableService->executeSyncRequest( + std::move(request), + newRequestContext()); + + QVERIFY(serviceCallDetected); + QVERIFY(result.first == value); + QVERIFY(!result.second); +} + +void DurableServiceTester::shouldExecuteAsyncServiceCall() +{ + auto durableService = newDurableService(); + + bool serviceCallDetected = false; + QVariant value = QStringLiteral("value"); + + IDurableService::AsyncRequest request("request", {}, + [&] (IRequestContextPtr ctx) -> AsyncResult* { + Q_ASSERT(ctx); + serviceCallDetected = true; + return new AsyncResult(value, {}, ctx); + }); + + AsyncResult * result = durableService->executeAsyncRequest( + std::move(request), + newRequestContext()); + + ValueFetcher valueFetcher; + QObject::connect(result, &AsyncResult::finished, + &valueFetcher, &ValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect(&valueFetcher, &ValueFetcher::finished, + &loop, &QEventLoop::quit); + loop.exec(); + + QVERIFY(serviceCallDetected); + QVERIFY(valueFetcher.m_value == value); + QVERIFY(!valueFetcher.m_exceptionData); +} + +void DurableServiceTester::shouldRetrySyncServiceCalls() +{ + auto durableService = newDurableService(); + + int serviceCallCounter = 0; + int maxServiceCallCounter = 3; + + auto ctx = newRequestContext( + QString(), + DEFAULT_REQUEST_TIMEOUT_MSEC, + DEFAULT_REQUEST_TIMEOUT_EXPONENTIAL_INCREASE, + DEFAULT_MAX_REQUEST_TIMEOUT_MSEC, + maxServiceCallCounter); + + QVariant value = QStringLiteral("value"); + + IDurableService::SyncRequest request("request", {}, + [&] (IRequestContextPtr ctx) -> IDurableService::SyncResult { + Q_ASSERT(ctx); + Q_ASSERT(ctx->maxRequestRetryCount() == maxServiceCallCounter); + + ++serviceCallCounter; + if (serviceCallCounter < maxServiceCallCounter) + { + EverCloudExceptionDataPtr data; + try { + throw NetworkException(QNetworkReply::TimeoutError); + } + catch(const EverCloudException & e) { + data = e.exceptionData(); + } + + return {{}, data}; + } + + return {value, {}}; + }); + + auto result = durableService->executeSyncRequest(std::move(request), ctx); + + QVERIFY(serviceCallCounter == maxServiceCallCounter); + QVERIFY(result.first == value); + QVERIFY(!result.second); +} + +void DurableServiceTester::shouldRetryAsyncServiceCalls() +{ + auto durableService = newDurableService(); + + int serviceCallCounter = 0; + int maxServiceCallCounter = 3; + + auto ctx = newRequestContext( + QString(), + DEFAULT_REQUEST_TIMEOUT_MSEC, + DEFAULT_REQUEST_TIMEOUT_EXPONENTIAL_INCREASE, + DEFAULT_MAX_REQUEST_TIMEOUT_MSEC, + maxServiceCallCounter); + + QVariant value = QStringLiteral("value"); + + IDurableService::AsyncRequest request("request", {}, + [&] (IRequestContextPtr ctx) -> AsyncResult* { + Q_ASSERT(ctx); + Q_ASSERT(ctx->maxRequestRetryCount() == maxServiceCallCounter); + + ++serviceCallCounter; + if (serviceCallCounter < maxServiceCallCounter) + { + EverCloudExceptionDataPtr data; + try { + throw NetworkException(QNetworkReply::TimeoutError); + } + catch(const EverCloudException & e) { + data = e.exceptionData(); + } + + return new AsyncResult(QVariant(), data, ctx); + } + + return new AsyncResult(value, {}, ctx); + }); + + AsyncResult * result = durableService->executeAsyncRequest( + std::move(request), + ctx); + + ValueFetcher valueFetcher; + QObject::connect(result, &AsyncResult::finished, + &valueFetcher, &ValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect(&valueFetcher, &ValueFetcher::finished, + &loop, &QEventLoop::quit); + loop.exec(); + + QVERIFY(serviceCallCounter == maxServiceCallCounter); + QVERIFY(valueFetcher.m_value == value); + QVERIFY(!valueFetcher.m_exceptionData); +} + +void DurableServiceTester::shouldNotRetrySyncServiceCallMoreThanMaxTimes() +{ + auto durableService = newDurableService(); + + int serviceCallCounter = 0; + int maxServiceCallCounter = 3; + + auto ctx = newRequestContext( + QString(), + DEFAULT_REQUEST_TIMEOUT_MSEC, + DEFAULT_REQUEST_TIMEOUT_EXPONENTIAL_INCREASE, + DEFAULT_MAX_REQUEST_TIMEOUT_MSEC, + maxServiceCallCounter); + + IDurableService::SyncRequest request("request", {}, + [&] (IRequestContextPtr ctx) -> IDurableService::SyncResult { + Q_ASSERT(ctx); + Q_ASSERT(ctx->maxRequestRetryCount() == maxServiceCallCounter); + + ++serviceCallCounter; + EverCloudExceptionDataPtr data; + try { + throw NetworkException(QNetworkReply::TimeoutError); + } + catch(const EverCloudException & e) { + data = e.exceptionData(); + } + + return {{}, data}; + }); + + auto result = durableService->executeSyncRequest(std::move(request), ctx); + + QVERIFY(serviceCallCounter == maxServiceCallCounter); + QVERIFY(!result.first.isValid()); + QVERIFY(result.second.get() != nullptr); + + bool exceptionCaught = false; + try { + result.second->throwException(); + } + catch(const NetworkException & e) { + exceptionCaught = true; + QVERIFY(e.type() == QNetworkReply::TimeoutError); + } + QVERIFY(exceptionCaught); +} + +void DurableServiceTester::shouldNotRetryAsyncServiceCallMoreThanMaxTimes() +{ + auto durableService = newDurableService(); + + int serviceCallCounter = 0; + int maxServiceCallCounter = 3; + + auto ctx = newRequestContext( + QString(), + DEFAULT_REQUEST_TIMEOUT_MSEC, + DEFAULT_REQUEST_TIMEOUT_EXPONENTIAL_INCREASE, + DEFAULT_MAX_REQUEST_TIMEOUT_MSEC, + maxServiceCallCounter); + + IDurableService::AsyncRequest request("request", {}, + [&] (IRequestContextPtr ctx) -> AsyncResult* { + Q_ASSERT(ctx); + Q_ASSERT(ctx->maxRequestRetryCount() == maxServiceCallCounter); + + ++serviceCallCounter; + EverCloudExceptionDataPtr data; + try { + throw NetworkException(QNetworkReply::TimeoutError); + } + catch(const EverCloudException & e) { + data = e.exceptionData(); + } + + return new AsyncResult(QVariant(), data, ctx); + }); + + AsyncResult * result = durableService->executeAsyncRequest( + std::move(request), + ctx); + + ValueFetcher valueFetcher; + QObject::connect(result, &AsyncResult::finished, + &valueFetcher, &ValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect(&valueFetcher, &ValueFetcher::finished, + &loop, &QEventLoop::quit); + loop.exec(); + + QVERIFY(serviceCallCounter == maxServiceCallCounter); + QVERIFY(!valueFetcher.m_value.isValid()); + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + + bool exceptionCaught = false; + try { + valueFetcher.m_exceptionData->throwException(); + } + catch(const NetworkException & e) { + exceptionCaught = true; + QVERIFY(e.type() == QNetworkReply::TimeoutError); + } + QVERIFY(exceptionCaught); +} + +void DurableServiceTester::shouldNotRetrySyncServiceCallInCaseOfUnretriableError() +{ + auto durableService = newDurableService(); + + int serviceCallCounter = 0; + int maxServiceCallCounter = 3; + + auto ctx = newRequestContext( + QString(), + DEFAULT_REQUEST_TIMEOUT_MSEC, + DEFAULT_REQUEST_TIMEOUT_EXPONENTIAL_INCREASE, + DEFAULT_MAX_REQUEST_TIMEOUT_MSEC, + maxServiceCallCounter); + + IDurableService::SyncRequest request("request", {}, + [&] (IRequestContextPtr ctx) -> IDurableService::SyncResult { + Q_ASSERT(ctx); + Q_ASSERT(ctx->maxRequestRetryCount() == maxServiceCallCounter); + + ++serviceCallCounter; + EverCloudExceptionDataPtr data; + try { + EDAMUserException e; + e.errorCode = EDAMErrorCode::AUTH_EXPIRED; + throw e; + } + catch(const EverCloudException & e) { + data = e.exceptionData(); + } + + return {{}, data}; + }); + + auto result = durableService->executeSyncRequest(std::move(request), ctx); + + QVERIFY(serviceCallCounter == 1); + QVERIFY(!result.first.isValid()); + QVERIFY(result.second.get() != nullptr); + + bool exceptionCaught = false; + try { + result.second->throwException(); + } + catch(const EDAMUserException & e) { + exceptionCaught = true; + QVERIFY(e.errorCode == EDAMErrorCode::AUTH_EXPIRED); + } + QVERIFY(exceptionCaught); +} + +void DurableServiceTester::shouldNotRetryAsyncServiceCallInCaseOfUnretriableError() +{ + auto durableService = newDurableService(); + + int serviceCallCounter = 0; + int maxServiceCallCounter = 3; + + auto ctx = newRequestContext( + QString(), + DEFAULT_REQUEST_TIMEOUT_MSEC, + DEFAULT_REQUEST_TIMEOUT_EXPONENTIAL_INCREASE, + DEFAULT_MAX_REQUEST_TIMEOUT_MSEC, + maxServiceCallCounter); + + IDurableService::AsyncRequest request("request", {}, + [&] (IRequestContextPtr ctx) -> AsyncResult* { + Q_ASSERT(ctx); + Q_ASSERT(ctx->maxRequestRetryCount() == maxServiceCallCounter); + + ++serviceCallCounter; + EverCloudExceptionDataPtr data; + try { + EDAMUserException e; + e.errorCode = EDAMErrorCode::AUTH_EXPIRED; + throw e; + } + catch(const EverCloudException & e) { + data = e.exceptionData(); + } + + return new AsyncResult(QVariant(), data, ctx); + }); + + AsyncResult * result = durableService->executeAsyncRequest( + std::move(request), + ctx); + + ValueFetcher valueFetcher; + QObject::connect(result, &AsyncResult::finished, + &valueFetcher, &ValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect(&valueFetcher, &ValueFetcher::finished, + &loop, &QEventLoop::quit); + loop.exec(); + + QVERIFY(serviceCallCounter == 1); + QVERIFY(!valueFetcher.m_value.isValid()); + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + + bool exceptionCaught = false; + try { + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) { + exceptionCaught = true; + QVERIFY(e.errorCode == EDAMErrorCode::AUTH_EXPIRED); + } + QVERIFY(exceptionCaught); +} + +} // namespace qevercloud + +#include diff --git a/src/qevercloud/QEverCloud/src/tests/TestDurableService.h b/src/qevercloud/QEverCloud/src/tests/TestDurableService.h new file mode 100644 index 00000000..06c85fd2 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/tests/TestDurableService.h @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_TEST_DURABLE_SERVICE_H +#define QEVERCLOUD_TEST_DURABLE_SERVICE_H + +#include + +namespace qevercloud { + +class DurableServiceTester: public QObject +{ + Q_OBJECT +public: + explicit DurableServiceTester(QObject * parent = nullptr); + +private Q_SLOTS: + void shouldExecuteSyncServiceCall(); + void shouldExecuteAsyncServiceCall(); + void shouldRetrySyncServiceCalls(); + void shouldRetryAsyncServiceCalls(); + void shouldNotRetrySyncServiceCallMoreThanMaxTimes(); + void shouldNotRetryAsyncServiceCallMoreThanMaxTimes(); + void shouldNotRetrySyncServiceCallInCaseOfUnretriableError(); + void shouldNotRetryAsyncServiceCallInCaseOfUnretriableError(); +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_TEST_DURABLE_SERVICE_H diff --git a/src/qevercloud/QEverCloud/src/tests/TestOptional.cpp b/src/qevercloud/QEverCloud/src/tests/TestOptional.cpp new file mode 100644 index 00000000..5e016be6 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/tests/TestOptional.cpp @@ -0,0 +1,139 @@ +/** + * Copyright (c) 2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include "TestOptional.h" + +#include +#include + +#include + +namespace qevercloud { + +OptionalTester::OptionalTester(QObject * parent) : + QObject(parent) +{} + +void OptionalTester::shouldDetectValueNotSet() +{ + Optional i; + QVERIFY(!i.isSet()); +} + +void OptionalTester::shouldClearValue() +{ + Optional i; + i = 10; + QVERIFY(i.isSet()); + QVERIFY(i == 10); + i.clear(); + QVERIFY(!i.isSet()); +} + +void OptionalTester::shouldDetectExternalValueChange() +{ + Optional i; + i.init().ref() = 11; + QVERIFY(i == 11); + static_cast(i) = 12; + QVERIFY(i == 12); +} + +void OptionalTester::shouldCastToIntFromAscii() +{ + const Optional ic = ' '; + QVERIFY(ic == 32); +} + +void OptionalTester::shouldInitValue() +{ + Optional i; + i.init(); + QVERIFY2(i.isSet() && i == int(), "i.isSet() && i == int()"); +} + +void OptionalTester::shouldThrowExceptionOnAttemptToReferenceUnsetValue() +{ + Optional i; + bool exceptionThrown = false; + try { + int a = i; + } + catch(const EverCloudException &) { + exceptionThrown = true; + } + QVERIFY(exceptionThrown); +} + +void OptionalTester::shouldAssignFromOtherOptionals() +{ + Optional y, k = 10; + y = k; + QVERIFY(y == 10); + Optional d; + d = y; + QVERIFY(d == 10.0); + d = ' '; + QVERIFY(d == 32.0); +} + +void OptionalTester::shouldProcessEqualityChecks() +{ + Optional y = 10; + Optional d = 32; + + Optional d2(y), d3(' '), d4(d); + QVERIFY(d2 == 10.0); + QVERIFY(d3 == 32.0); + QVERIFY(d4.ref() == d.ref()); + + Optional oi; + Optional od; + QVERIFY(oi.isEqual(od)); oi = 1; + QVERIFY(!oi.isEqual(od)); + od = 1; + QVERIFY(oi.isEqual(od)); + oi = 2; + QVERIFY(!oi.isEqual(od)); +} + +void OptionalTester::shouldProcessStructEqualityChecks() +{ + Note n1, n2; + QVERIFY(n1 == n2); + n1.guid = QStringLiteral("12345"); + QVERIFY(n1 != n2); + n2.guid = n1.guid; + QVERIFY(n1 == n2); +} + +void OptionalTester::shouldProcessValueMoves() +{ + Optional oi1, oi2; + oi1 = 10; + oi2 = std::move(oi1); + QVERIFY(oi2 == 10); + QVERIFY(!oi1.isSet()); + + Note note1, note2; + note1.guid = QStringLiteral("12345"); + QVERIFY(note1.guid.isSet()); + QVERIFY(!note2.guid.isSet()); + note2 = std::move(note1); + QVERIFY(note2.guid.isSet()); + QVERIFY(!note1.guid.isSet()); +} + +void OptionalTester::shouldHandleZeroTimestamp() +{ + Optional t; + t = Timestamp(0); + QVERIFY(t.ref() == Timestamp(0)); +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/tests/TestOptional.h b/src/qevercloud/QEverCloud/src/tests/TestOptional.h new file mode 100644 index 00000000..e9c0d325 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/tests/TestOptional.h @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#ifndef QEVERCLOUD_TEST_OPTIONAL_H +#define QEVERCLOUD_TEST_OPTIONAL_H + +#include + +namespace qevercloud { + +class OptionalTester: public QObject +{ + Q_OBJECT +public: + explicit OptionalTester(QObject * parent = nullptr); + +private Q_SLOTS: + void shouldDetectValueNotSet(); + void shouldClearValue(); + void shouldDetectExternalValueChange(); + void shouldCastToIntFromAscii(); + void shouldInitValue(); + void shouldThrowExceptionOnAttemptToReferenceUnsetValue(); + void shouldAssignFromOtherOptionals(); + void shouldProcessEqualityChecks(); + void shouldProcessStructEqualityChecks(); + void shouldProcessValueMoves(); + void shouldHandleZeroTimestamp(); +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_TEST_OPTIONAL_H diff --git a/src/qevercloud/QEverCloud/src/tests/TestQEverCloud.cpp b/src/qevercloud/QEverCloud/src/tests/TestQEverCloud.cpp index b25392d7..82669958 100644 --- a/src/qevercloud/QEverCloud/src/tests/TestQEverCloud.cpp +++ b/src/qevercloud/QEverCloud/src/tests/TestQEverCloud.cpp @@ -1,126 +1,48 @@ -#include -#include -#include - -#ifdef QEVERCLOUD_SHARED_LIBRARY -#undef QEVERCLOUD_SHARED_LIBRARY -#endif - -#ifdef QEVERCLOUD_STATIC_LIBRARY -#undef QEVERCLOUD_STATIC_LIBRARY -#endif +/** + * Copyright (c) 2019 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + */ + +#include "MessageHandler.h" +#include "TestDurableService.h" +#include "TestOptional.h" +#include "generated/TestNoteStore.h" +#include "generated/TestUserStore.h" #include -#include - -class TestEverCloudTest: public QObject -{ - Q_OBJECT -public: - TestEverCloudTest(); -private Q_SLOTS: - void testOptional(); -}; +#include +#include -TestEverCloudTest::TestEverCloudTest() -{} +#include using namespace qevercloud; -void TestEverCloudTest::testOptional() +int main(int argc, char *argv[]) { - Optional i; - QVERIFY(!i.isSet()); - - i = 10; - QVERIFY(i.isSet()); - QVERIFY(i == 10); - i.clear(); - QVERIFY(!i.isSet()); - - i.init().ref() = 11; - QVERIFY(i == 11); - static_cast(i) = 12; - QVERIFY(i == 12); - - const Optional ic = ' '; - QVERIFY(ic == 32); + // Fixed seed for rand() calls + std::srand(1575003691); - i.clear(); - i.init(); - QVERIFY2(i.isSet() && i == int(), "i.isSet() && i == int()"); + qInstallMessageHandler(testMessageOutput); + QCoreApplication app(argc, argv); - i.clear(); - bool exception = false; - try { - qDebug() << i; - } - catch(const EverCloudException &) { - exception = true; - } - QVERIFY(exception); + initializeQEverCloud(); - Optional y, k = 10; - y = k; - QVERIFY(y == 10); - Optional d; - d = y; - QVERIFY(d == 10); - d = ' '; - QVERIFY(d == 32); + int res = 0; +#define RUN_TESTS(tester) \ + res = QTest::qExec(new tester); \ + if (res != 0) { \ + return res; \ + } \ +// RUN_TESTS - Optional d2(y), d3(' '), d4(d); - QVERIFY(d2 == 10); - QVERIFY(d3 == 32); - QVERIFY(d4 == d); + RUN_TESTS(DurableServiceTester) + RUN_TESTS(OptionalTester) + RUN_TESTS(NoteStoreTester) + RUN_TESTS(UserStoreTester) - Optional oi; - Optional od; - QVERIFY(oi.isEqual(od)); oi = 1; - QVERIFY(!oi.isEqual(od)); - od = 1; - QVERIFY(oi.isEqual(od)); - oi = 2; - QVERIFY(!oi.isEqual(od)); - - Note n1, n2; - QVERIFY(n1 == n2); - n1.guid = QStringLiteral("12345"); - QVERIFY(n1 != n2); - n2.guid = n1.guid; - QVERIFY(n1 == n2); - -#if defined(Q_COMPILER_RVALUE_REFS) && !defined(_MSC_VER) - Optional oi1, oi2; - oi1 = 10; - oi2 = std::move(oi1); - QVERIFY(oi2 == 10); - QVERIFY(!oi1.isSet()); - - Note note1, note2; - note1.guid = QStringLiteral("12345"); - QVERIFY(note1.guid.isSet()); - QVERIFY(!note2.guid.isSet()); - note2 = std::move(note1); - QVERIFY(note2.guid.isSet()); - QVERIFY(!note1.guid.isSet()); -#endif - - Optional t; - t = 0; - t = Timestamp(0); - QVERIFY(t.ref() == Timestamp(0)); + return 0; } - -#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) -#ifdef QT_GUI_LIB -#undef QT_GUI_LIB -QTEST_MAIN(TestEverCloudTest) -#define QT_GUI_LIB -#endif // QT_GUI_LIB -#else -QTEST_GUILESS_MAIN(TestEverCloudTest) -#endif - -#include "TestQEverCloud.moc" diff --git a/src/qevercloud/QEverCloud/src/tests/generated/RandomDataGenerators.cpp b/src/qevercloud/QEverCloud/src/tests/generated/RandomDataGenerators.cpp new file mode 100644 index 00000000..02d6c85f --- /dev/null +++ b/src/qevercloud/QEverCloud/src/tests/generated/RandomDataGenerators.cpp @@ -0,0 +1,1330 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + * + * This file was generated from Evernote Thrift API + */ + +#include "RandomDataGenerators.h" +#include "../../Impl.h" +#include +#include +#include +#include +#include +#include +#include +#include + +namespace qevercloud { + +namespace { + +//////////////////////////////////////////////////////////////////////////////// + +Q_GLOBAL_STATIC_WITH_ARGS( + QString, + randomStringAvailableCharacters, + (QString::fromUtf8( + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"))) + +template +T generateRandomIntType() +{ + T min = std::numeric_limits::min() / 4; + T max = std::numeric_limits::max() / 4; + return min + (rand() % static_cast(max - min + 1)); +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// + +QString generateRandomString(int len) +{ + if (len <= 0) { + return {}; + } + + QString res; + res.reserve(len); + for(int i = 0; i < len; ++i) { + int index = rand() % randomStringAvailableCharacters->length(); + res.append(randomStringAvailableCharacters->at(index)); + } + + return res; +} + +qint8 generateRandomInt8() +{ + return generateRandomIntType(); +} + +qint16 generateRandomInt16() +{ + return generateRandomIntType(); +} + +qint32 generateRandomInt32() +{ + return generateRandomIntType(); +} + +qint64 generateRandomInt64() +{ + return generateRandomIntType(); +} + +quint8 generateRandomUint8() +{ + return generateRandomIntType(); +} + +quint16 generateRandomUint16() +{ + return generateRandomIntType(); +} + +quint32 generateRandomUint32() +{ + return generateRandomIntType(); +} + +quint64 generateRandomUint64() +{ + return generateRandomIntType(); +} + +double generateRandomDouble() +{ + double minval = std::numeric_limits::min(); + double maxval = std::numeric_limits::max(); + double f = (double)rand() / RAND_MAX; + return minval + f * (maxval - minval); +} + +bool generateRandomBool() +{ + return generateRandomInt8() >= 0; +} + +//////////////////////////////////////////////////////////////////////////////// + +SyncState generateRandomSyncState() +{ + SyncState result; + result.currentTime = generateRandomInt64(); + result.fullSyncBefore = generateRandomInt64(); + result.updateCount = generateRandomInt32(); + result.uploaded = generateRandomInt64(); + result.userLastUpdated = generateRandomInt64(); + result.userMaxMessageEventId = generateRandomInt64(); + return result; +} + +SyncChunk generateRandomSyncChunk() +{ + SyncChunk result; + result.currentTime = generateRandomInt64(); + result.chunkHighUSN = generateRandomInt32(); + result.updateCount = generateRandomInt32(); + result.notes = QList(); + result.notes.ref() << generateRandomNote(); + result.notes.ref() << generateRandomNote(); + result.notes.ref() << generateRandomNote(); + result.notebooks = QList(); + result.notebooks.ref() << generateRandomNotebook(); + result.notebooks.ref() << generateRandomNotebook(); + result.notebooks.ref() << generateRandomNotebook(); + result.tags = QList(); + result.tags.ref() << generateRandomTag(); + result.tags.ref() << generateRandomTag(); + result.tags.ref() << generateRandomTag(); + result.searches = QList(); + result.searches.ref() << generateRandomSavedSearch(); + result.searches.ref() << generateRandomSavedSearch(); + result.searches.ref() << generateRandomSavedSearch(); + result.resources = QList(); + result.resources.ref() << generateRandomResource(); + result.resources.ref() << generateRandomResource(); + result.resources.ref() << generateRandomResource(); + result.expungedNotes = QList(); + result.expungedNotes.ref() << generateRandomString(); + result.expungedNotes.ref() << generateRandomString(); + result.expungedNotes.ref() << generateRandomString(); + result.expungedNotebooks = QList(); + result.expungedNotebooks.ref() << generateRandomString(); + result.expungedNotebooks.ref() << generateRandomString(); + result.expungedNotebooks.ref() << generateRandomString(); + result.expungedTags = QList(); + result.expungedTags.ref() << generateRandomString(); + result.expungedTags.ref() << generateRandomString(); + result.expungedTags.ref() << generateRandomString(); + result.expungedSearches = QList(); + result.expungedSearches.ref() << generateRandomString(); + result.expungedSearches.ref() << generateRandomString(); + result.expungedSearches.ref() << generateRandomString(); + result.linkedNotebooks = QList(); + result.linkedNotebooks.ref() << generateRandomLinkedNotebook(); + result.linkedNotebooks.ref() << generateRandomLinkedNotebook(); + result.linkedNotebooks.ref() << generateRandomLinkedNotebook(); + result.expungedLinkedNotebooks = QList(); + result.expungedLinkedNotebooks.ref() << generateRandomString(); + result.expungedLinkedNotebooks.ref() << generateRandomString(); + result.expungedLinkedNotebooks.ref() << generateRandomString(); + return result; +} + +SyncChunkFilter generateRandomSyncChunkFilter() +{ + SyncChunkFilter result; + result.includeNotes = generateRandomBool(); + result.includeNoteResources = generateRandomBool(); + result.includeNoteAttributes = generateRandomBool(); + result.includeNotebooks = generateRandomBool(); + result.includeTags = generateRandomBool(); + result.includeSearches = generateRandomBool(); + result.includeResources = generateRandomBool(); + result.includeLinkedNotebooks = generateRandomBool(); + result.includeExpunged = generateRandomBool(); + result.includeNoteApplicationDataFullMap = generateRandomBool(); + result.includeResourceApplicationDataFullMap = generateRandomBool(); + result.includeNoteResourceApplicationDataFullMap = generateRandomBool(); + result.includeSharedNotes = generateRandomBool(); + result.omitSharedNotebooks = generateRandomBool(); + result.requireNoteContentClass = generateRandomString(); + result.notebookGuids = QSet(); + result.notebookGuids->insert(generateRandomString()); + result.notebookGuids->insert(generateRandomString()); + result.notebookGuids->insert(generateRandomString()); + return result; +} + +NoteFilter generateRandomNoteFilter() +{ + NoteFilter result; + result.order = generateRandomInt32(); + result.ascending = generateRandomBool(); + result.words = generateRandomString(); + result.notebookGuid = generateRandomString(); + result.tagGuids = QList(); + result.tagGuids.ref() << generateRandomString(); + result.tagGuids.ref() << generateRandomString(); + result.tagGuids.ref() << generateRandomString(); + result.timeZone = generateRandomString(); + result.inactive = generateRandomBool(); + result.emphasized = generateRandomString(); + result.includeAllReadableNotebooks = generateRandomBool(); + result.includeAllReadableWorkspaces = generateRandomBool(); + result.context = generateRandomString(); + result.rawWords = generateRandomString(); + result.searchContextBytes = generateRandomString().toUtf8(); + return result; +} + +NoteList generateRandomNoteList() +{ + NoteList result; + result.startIndex = generateRandomInt32(); + result.totalNotes = generateRandomInt32(); + result.notes << generateRandomNote(); + result.notes << generateRandomNote(); + result.notes << generateRandomNote(); + result.stoppedWords = QList(); + result.stoppedWords.ref() << generateRandomString(); + result.stoppedWords.ref() << generateRandomString(); + result.stoppedWords.ref() << generateRandomString(); + result.searchedWords = QList(); + result.searchedWords.ref() << generateRandomString(); + result.searchedWords.ref() << generateRandomString(); + result.searchedWords.ref() << generateRandomString(); + result.updateCount = generateRandomInt32(); + result.searchContextBytes = generateRandomString().toUtf8(); + result.debugInfo = generateRandomString(); + return result; +} + +NoteMetadata generateRandomNoteMetadata() +{ + NoteMetadata result; + result.guid = generateRandomString(); + result.title = generateRandomString(); + result.contentLength = generateRandomInt32(); + result.created = generateRandomInt64(); + result.updated = generateRandomInt64(); + result.deleted = generateRandomInt64(); + result.updateSequenceNum = generateRandomInt32(); + result.notebookGuid = generateRandomString(); + result.tagGuids = QList(); + result.tagGuids.ref() << generateRandomString(); + result.tagGuids.ref() << generateRandomString(); + result.tagGuids.ref() << generateRandomString(); + result.attributes = generateRandomNoteAttributes(); + result.largestResourceMime = generateRandomString(); + result.largestResourceSize = generateRandomInt32(); + return result; +} + +NotesMetadataList generateRandomNotesMetadataList() +{ + NotesMetadataList result; + result.startIndex = generateRandomInt32(); + result.totalNotes = generateRandomInt32(); + result.notes << generateRandomNoteMetadata(); + result.notes << generateRandomNoteMetadata(); + result.notes << generateRandomNoteMetadata(); + result.stoppedWords = QList(); + result.stoppedWords.ref() << generateRandomString(); + result.stoppedWords.ref() << generateRandomString(); + result.stoppedWords.ref() << generateRandomString(); + result.searchedWords = QList(); + result.searchedWords.ref() << generateRandomString(); + result.searchedWords.ref() << generateRandomString(); + result.searchedWords.ref() << generateRandomString(); + result.updateCount = generateRandomInt32(); + result.searchContextBytes = generateRandomString().toUtf8(); + result.debugInfo = generateRandomString(); + return result; +} + +NotesMetadataResultSpec generateRandomNotesMetadataResultSpec() +{ + NotesMetadataResultSpec result; + result.includeTitle = generateRandomBool(); + result.includeContentLength = generateRandomBool(); + result.includeCreated = generateRandomBool(); + result.includeUpdated = generateRandomBool(); + result.includeDeleted = generateRandomBool(); + result.includeUpdateSequenceNum = generateRandomBool(); + result.includeNotebookGuid = generateRandomBool(); + result.includeTagGuids = generateRandomBool(); + result.includeAttributes = generateRandomBool(); + result.includeLargestResourceMime = generateRandomBool(); + result.includeLargestResourceSize = generateRandomBool(); + return result; +} + +NoteCollectionCounts generateRandomNoteCollectionCounts() +{ + NoteCollectionCounts result; + result.notebookCounts = QMap(); + result.notebookCounts.ref()[generateRandomString()] = generateRandomInt32(); + result.notebookCounts.ref()[generateRandomString()] = generateRandomInt32(); + result.notebookCounts.ref()[generateRandomString()] = generateRandomInt32(); + result.tagCounts = QMap(); + result.tagCounts.ref()[generateRandomString()] = generateRandomInt32(); + result.tagCounts.ref()[generateRandomString()] = generateRandomInt32(); + result.tagCounts.ref()[generateRandomString()] = generateRandomInt32(); + result.trashCount = generateRandomInt32(); + return result; +} + +NoteResultSpec generateRandomNoteResultSpec() +{ + NoteResultSpec result; + result.includeContent = generateRandomBool(); + result.includeResourcesData = generateRandomBool(); + result.includeResourcesRecognition = generateRandomBool(); + result.includeResourcesAlternateData = generateRandomBool(); + result.includeSharedNotes = generateRandomBool(); + result.includeNoteAppDataValues = generateRandomBool(); + result.includeResourceAppDataValues = generateRandomBool(); + result.includeAccountLimits = generateRandomBool(); + return result; +} + +NoteEmailParameters generateRandomNoteEmailParameters() +{ + NoteEmailParameters result; + result.guid = generateRandomString(); + result.note = generateRandomNote(); + result.toAddresses = QList(); + result.toAddresses.ref() << generateRandomString(); + result.toAddresses.ref() << generateRandomString(); + result.toAddresses.ref() << generateRandomString(); + result.ccAddresses = QList(); + result.ccAddresses.ref() << generateRandomString(); + result.ccAddresses.ref() << generateRandomString(); + result.ccAddresses.ref() << generateRandomString(); + result.subject = generateRandomString(); + result.message = generateRandomString(); + return result; +} + +NoteVersionId generateRandomNoteVersionId() +{ + NoteVersionId result; + result.updateSequenceNum = generateRandomInt32(); + result.updated = generateRandomInt64(); + result.saved = generateRandomInt64(); + result.title = generateRandomString(); + result.lastEditorId = generateRandomInt32(); + return result; +} + +RelatedQuery generateRandomRelatedQuery() +{ + RelatedQuery result; + result.noteGuid = generateRandomString(); + result.plainText = generateRandomString(); + result.filter = generateRandomNoteFilter(); + result.referenceUri = generateRandomString(); + result.context = generateRandomString(); + result.cacheKey = generateRandomString(); + return result; +} + +RelatedResult generateRandomRelatedResult() +{ + RelatedResult result; + result.notes = QList(); + result.notes.ref() << generateRandomNote(); + result.notes.ref() << generateRandomNote(); + result.notes.ref() << generateRandomNote(); + result.notebooks = QList(); + result.notebooks.ref() << generateRandomNotebook(); + result.notebooks.ref() << generateRandomNotebook(); + result.notebooks.ref() << generateRandomNotebook(); + result.tags = QList(); + result.tags.ref() << generateRandomTag(); + result.tags.ref() << generateRandomTag(); + result.tags.ref() << generateRandomTag(); + result.containingNotebooks = QList(); + result.containingNotebooks.ref() << generateRandomNotebookDescriptor(); + result.containingNotebooks.ref() << generateRandomNotebookDescriptor(); + result.containingNotebooks.ref() << generateRandomNotebookDescriptor(); + result.debugInfo = generateRandomString(); + result.experts = QList(); + result.experts.ref() << generateRandomUserProfile(); + result.experts.ref() << generateRandomUserProfile(); + result.experts.ref() << generateRandomUserProfile(); + result.relatedContent = QList(); + result.relatedContent.ref() << generateRandomRelatedContent(); + result.relatedContent.ref() << generateRandomRelatedContent(); + result.relatedContent.ref() << generateRandomRelatedContent(); + result.cacheKey = generateRandomString(); + result.cacheExpires = generateRandomInt32(); + return result; +} + +RelatedResultSpec generateRandomRelatedResultSpec() +{ + RelatedResultSpec result; + result.maxNotes = generateRandomInt32(); + result.maxNotebooks = generateRandomInt32(); + result.maxTags = generateRandomInt32(); + result.writableNotebooksOnly = generateRandomBool(); + result.includeContainingNotebooks = generateRandomBool(); + result.includeDebugInfo = generateRandomBool(); + result.maxExperts = generateRandomInt32(); + result.maxRelatedContent = generateRandomInt32(); + result.relatedContentTypes = QSet(); + result.relatedContentTypes->insert(RelatedContentType::NEWS_ARTICLE); + result.relatedContentTypes->insert(RelatedContentType::NEWS_ARTICLE); + result.relatedContentTypes->insert(RelatedContentType::PROFILE_PERSON); + return result; +} + +UpdateNoteIfUsnMatchesResult generateRandomUpdateNoteIfUsnMatchesResult() +{ + UpdateNoteIfUsnMatchesResult result; + result.note = generateRandomNote(); + result.updated = generateRandomBool(); + return result; +} + +ShareRelationshipRestrictions generateRandomShareRelationshipRestrictions() +{ + ShareRelationshipRestrictions result; + result.noSetReadOnly = generateRandomBool(); + result.noSetReadPlusActivity = generateRandomBool(); + result.noSetModify = generateRandomBool(); + result.noSetFullAccess = generateRandomBool(); + return result; +} + +InvitationShareRelationship generateRandomInvitationShareRelationship() +{ + InvitationShareRelationship result; + result.displayName = generateRandomString(); + result.recipientUserIdentity = generateRandomUserIdentity(); + result.privilege = ShareRelationshipPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY; + result.sharerUserId = generateRandomInt32(); + return result; +} + +MemberShareRelationship generateRandomMemberShareRelationship() +{ + MemberShareRelationship result; + result.displayName = generateRandomString(); + result.recipientUserId = generateRandomInt32(); + result.bestPrivilege = ShareRelationshipPrivilegeLevel::READ_NOTEBOOK; + result.individualPrivilege = ShareRelationshipPrivilegeLevel::READ_NOTEBOOK; + result.restrictions = generateRandomShareRelationshipRestrictions(); + result.sharerUserId = generateRandomInt32(); + return result; +} + +ShareRelationships generateRandomShareRelationships() +{ + ShareRelationships result; + result.invitations = QList(); + result.invitations.ref() << generateRandomInvitationShareRelationship(); + result.invitations.ref() << generateRandomInvitationShareRelationship(); + result.invitations.ref() << generateRandomInvitationShareRelationship(); + result.memberships = QList(); + result.memberships.ref() << generateRandomMemberShareRelationship(); + result.memberships.ref() << generateRandomMemberShareRelationship(); + result.memberships.ref() << generateRandomMemberShareRelationship(); + result.invitationRestrictions = generateRandomShareRelationshipRestrictions(); + return result; +} + +ManageNotebookSharesParameters generateRandomManageNotebookSharesParameters() +{ + ManageNotebookSharesParameters result; + result.notebookGuid = generateRandomString(); + result.inviteMessage = generateRandomString(); + result.membershipsToUpdate = QList(); + result.membershipsToUpdate.ref() << generateRandomMemberShareRelationship(); + result.membershipsToUpdate.ref() << generateRandomMemberShareRelationship(); + result.membershipsToUpdate.ref() << generateRandomMemberShareRelationship(); + result.invitationsToCreateOrUpdate = QList(); + result.invitationsToCreateOrUpdate.ref() << generateRandomInvitationShareRelationship(); + result.invitationsToCreateOrUpdate.ref() << generateRandomInvitationShareRelationship(); + result.invitationsToCreateOrUpdate.ref() << generateRandomInvitationShareRelationship(); + result.unshares = QList(); + result.unshares.ref() << generateRandomUserIdentity(); + result.unshares.ref() << generateRandomUserIdentity(); + result.unshares.ref() << generateRandomUserIdentity(); + return result; +} + +ManageNotebookSharesError generateRandomManageNotebookSharesError() +{ + ManageNotebookSharesError result; + result.userIdentity = generateRandomUserIdentity(); + result.userException = EDAMUserException(); + result.userException->errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + result.userException->parameter = generateRandomString(); + result.notFoundException = EDAMNotFoundException(); + result.notFoundException->identifier = generateRandomString(); + result.notFoundException->key = generateRandomString(); + return result; +} + +ManageNotebookSharesResult generateRandomManageNotebookSharesResult() +{ + ManageNotebookSharesResult result; + result.errors = QList(); + result.errors.ref() << generateRandomManageNotebookSharesError(); + result.errors.ref() << generateRandomManageNotebookSharesError(); + result.errors.ref() << generateRandomManageNotebookSharesError(); + return result; +} + +SharedNoteTemplate generateRandomSharedNoteTemplate() +{ + SharedNoteTemplate result; + result.noteGuid = generateRandomString(); + result.recipientThreadId = generateRandomInt64(); + result.recipientContacts = QList(); + result.recipientContacts.ref() << generateRandomContact(); + result.recipientContacts.ref() << generateRandomContact(); + result.recipientContacts.ref() << generateRandomContact(); + result.privilege = SharedNotePrivilegeLevel::READ_NOTE; + return result; +} + +NotebookShareTemplate generateRandomNotebookShareTemplate() +{ + NotebookShareTemplate result; + result.notebookGuid = generateRandomString(); + result.recipientThreadId = generateRandomInt64(); + result.recipientContacts = QList(); + result.recipientContacts.ref() << generateRandomContact(); + result.recipientContacts.ref() << generateRandomContact(); + result.recipientContacts.ref() << generateRandomContact(); + result.privilege = SharedNotebookPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY; + return result; +} + +CreateOrUpdateNotebookSharesResult generateRandomCreateOrUpdateNotebookSharesResult() +{ + CreateOrUpdateNotebookSharesResult result; + result.updateSequenceNum = generateRandomInt32(); + result.matchingShares = QList(); + result.matchingShares.ref() << generateRandomSharedNotebook(); + result.matchingShares.ref() << generateRandomSharedNotebook(); + result.matchingShares.ref() << generateRandomSharedNotebook(); + return result; +} + +NoteShareRelationshipRestrictions generateRandomNoteShareRelationshipRestrictions() +{ + NoteShareRelationshipRestrictions result; + result.noSetReadNote = generateRandomBool(); + result.noSetModifyNote = generateRandomBool(); + result.noSetFullAccess = generateRandomBool(); + return result; +} + +NoteMemberShareRelationship generateRandomNoteMemberShareRelationship() +{ + NoteMemberShareRelationship result; + result.displayName = generateRandomString(); + result.recipientUserId = generateRandomInt32(); + result.privilege = SharedNotePrivilegeLevel::FULL_ACCESS; + result.restrictions = generateRandomNoteShareRelationshipRestrictions(); + result.sharerUserId = generateRandomInt32(); + return result; +} + +NoteInvitationShareRelationship generateRandomNoteInvitationShareRelationship() +{ + NoteInvitationShareRelationship result; + result.displayName = generateRandomString(); + result.recipientIdentityId = generateRandomInt64(); + result.privilege = SharedNotePrivilegeLevel::MODIFY_NOTE; + result.sharerUserId = generateRandomInt32(); + return result; +} + +NoteShareRelationships generateRandomNoteShareRelationships() +{ + NoteShareRelationships result; + result.invitations = QList(); + result.invitations.ref() << generateRandomNoteInvitationShareRelationship(); + result.invitations.ref() << generateRandomNoteInvitationShareRelationship(); + result.invitations.ref() << generateRandomNoteInvitationShareRelationship(); + result.memberships = QList(); + result.memberships.ref() << generateRandomNoteMemberShareRelationship(); + result.memberships.ref() << generateRandomNoteMemberShareRelationship(); + result.memberships.ref() << generateRandomNoteMemberShareRelationship(); + result.invitationRestrictions = generateRandomNoteShareRelationshipRestrictions(); + return result; +} + +ManageNoteSharesParameters generateRandomManageNoteSharesParameters() +{ + ManageNoteSharesParameters result; + result.noteGuid = generateRandomString(); + result.membershipsToUpdate = QList(); + result.membershipsToUpdate.ref() << generateRandomNoteMemberShareRelationship(); + result.membershipsToUpdate.ref() << generateRandomNoteMemberShareRelationship(); + result.membershipsToUpdate.ref() << generateRandomNoteMemberShareRelationship(); + result.invitationsToUpdate = QList(); + result.invitationsToUpdate.ref() << generateRandomNoteInvitationShareRelationship(); + result.invitationsToUpdate.ref() << generateRandomNoteInvitationShareRelationship(); + result.invitationsToUpdate.ref() << generateRandomNoteInvitationShareRelationship(); + result.membershipsToUnshare = QList(); + result.membershipsToUnshare.ref() << generateRandomInt32(); + result.membershipsToUnshare.ref() << generateRandomInt32(); + result.membershipsToUnshare.ref() << generateRandomInt32(); + result.invitationsToUnshare = QList(); + result.invitationsToUnshare.ref() << generateRandomInt64(); + result.invitationsToUnshare.ref() << generateRandomInt64(); + result.invitationsToUnshare.ref() << generateRandomInt64(); + return result; +} + +ManageNoteSharesError generateRandomManageNoteSharesError() +{ + ManageNoteSharesError result; + result.identityID = generateRandomInt64(); + result.userID = generateRandomInt32(); + result.userException = EDAMUserException(); + result.userException->errorCode = EDAMErrorCode::OPENID_ALREADY_TAKEN; + result.userException->parameter = generateRandomString(); + result.notFoundException = EDAMNotFoundException(); + result.notFoundException->identifier = generateRandomString(); + result.notFoundException->key = generateRandomString(); + return result; +} + +ManageNoteSharesResult generateRandomManageNoteSharesResult() +{ + ManageNoteSharesResult result; + result.errors = QList(); + result.errors.ref() << generateRandomManageNoteSharesError(); + result.errors.ref() << generateRandomManageNoteSharesError(); + result.errors.ref() << generateRandomManageNoteSharesError(); + return result; +} + +Data generateRandomData() +{ + Data result; + result.bodyHash = generateRandomString().toUtf8(); + result.size = generateRandomInt32(); + result.body = generateRandomString().toUtf8(); + return result; +} + +UserAttributes generateRandomUserAttributes() +{ + UserAttributes result; + result.defaultLocationName = generateRandomString(); + result.defaultLatitude = generateRandomDouble(); + result.defaultLongitude = generateRandomDouble(); + result.preactivation = generateRandomBool(); + result.viewedPromotions = QList(); + result.viewedPromotions.ref() << generateRandomString(); + result.viewedPromotions.ref() << generateRandomString(); + result.viewedPromotions.ref() << generateRandomString(); + result.incomingEmailAddress = generateRandomString(); + result.recentMailedAddresses = QList(); + result.recentMailedAddresses.ref() << generateRandomString(); + result.recentMailedAddresses.ref() << generateRandomString(); + result.recentMailedAddresses.ref() << generateRandomString(); + result.comments = generateRandomString(); + result.dateAgreedToTermsOfService = generateRandomInt64(); + result.maxReferrals = generateRandomInt32(); + result.referralCount = generateRandomInt32(); + result.refererCode = generateRandomString(); + result.sentEmailDate = generateRandomInt64(); + result.sentEmailCount = generateRandomInt32(); + result.dailyEmailLimit = generateRandomInt32(); + result.emailOptOutDate = generateRandomInt64(); + result.partnerEmailOptInDate = generateRandomInt64(); + result.preferredLanguage = generateRandomString(); + result.preferredCountry = generateRandomString(); + result.clipFullPage = generateRandomBool(); + result.twitterUserName = generateRandomString(); + result.twitterId = generateRandomString(); + result.groupName = generateRandomString(); + result.recognitionLanguage = generateRandomString(); + result.referralProof = generateRandomString(); + result.educationalDiscount = generateRandomBool(); + result.businessAddress = generateRandomString(); + result.hideSponsorBilling = generateRandomBool(); + result.useEmailAutoFiling = generateRandomBool(); + result.reminderEmailConfig = ReminderEmailConfig::DO_NOT_SEND; + result.emailAddressLastConfirmed = generateRandomInt64(); + result.passwordUpdated = generateRandomInt64(); + result.salesforcePushEnabled = generateRandomBool(); + result.shouldLogClientEvent = generateRandomBool(); + result.optOutMachineLearning = generateRandomBool(); + return result; +} + +BusinessUserAttributes generateRandomBusinessUserAttributes() +{ + BusinessUserAttributes result; + result.title = generateRandomString(); + result.location = generateRandomString(); + result.department = generateRandomString(); + result.mobilePhone = generateRandomString(); + result.linkedInProfileUrl = generateRandomString(); + result.workPhone = generateRandomString(); + result.companyStartDate = generateRandomInt64(); + return result; +} + +Accounting generateRandomAccounting() +{ + Accounting result; + result.uploadLimitEnd = generateRandomInt64(); + result.uploadLimitNextMonth = generateRandomInt64(); + result.premiumServiceStatus = PremiumOrderStatus::PENDING; + result.premiumOrderNumber = generateRandomString(); + result.premiumCommerceService = generateRandomString(); + result.premiumServiceStart = generateRandomInt64(); + result.premiumServiceSKU = generateRandomString(); + result.lastSuccessfulCharge = generateRandomInt64(); + result.lastFailedCharge = generateRandomInt64(); + result.lastFailedChargeReason = generateRandomString(); + result.nextPaymentDue = generateRandomInt64(); + result.premiumLockUntil = generateRandomInt64(); + result.updated = generateRandomInt64(); + result.premiumSubscriptionNumber = generateRandomString(); + result.lastRequestedCharge = generateRandomInt64(); + result.currency = generateRandomString(); + result.unitPrice = generateRandomInt32(); + result.businessId = generateRandomInt32(); + result.businessName = generateRandomString(); + result.businessRole = BusinessUserRole::NORMAL; + result.unitDiscount = generateRandomInt32(); + result.nextChargeDate = generateRandomInt64(); + result.availablePoints = generateRandomInt32(); + return result; +} + +BusinessUserInfo generateRandomBusinessUserInfo() +{ + BusinessUserInfo result; + result.businessId = generateRandomInt32(); + result.businessName = generateRandomString(); + result.role = BusinessUserRole::ADMIN; + result.email = generateRandomString(); + result.updated = generateRandomInt64(); + return result; +} + +AccountLimits generateRandomAccountLimits() +{ + AccountLimits result; + result.userMailLimitDaily = generateRandomInt32(); + result.noteSizeMax = generateRandomInt64(); + result.resourceSizeMax = generateRandomInt64(); + result.userLinkedNotebookMax = generateRandomInt32(); + result.uploadLimit = generateRandomInt64(); + result.userNoteCountMax = generateRandomInt32(); + result.userNotebookCountMax = generateRandomInt32(); + result.userTagCountMax = generateRandomInt32(); + result.noteTagCountMax = generateRandomInt32(); + result.userSavedSearchesMax = generateRandomInt32(); + result.noteResourceCountMax = generateRandomInt32(); + return result; +} + +User generateRandomUser() +{ + User result; + result.id = generateRandomInt32(); + result.username = generateRandomString(); + result.email = generateRandomString(); + result.name = generateRandomString(); + result.timezone = generateRandomString(); + result.privilege = PrivilegeLevel::MANAGER; + result.serviceLevel = ServiceLevel::PLUS; + result.created = generateRandomInt64(); + result.updated = generateRandomInt64(); + result.deleted = generateRandomInt64(); + result.active = generateRandomBool(); + result.shardId = generateRandomString(); + result.attributes = generateRandomUserAttributes(); + result.accounting = generateRandomAccounting(); + result.businessUserInfo = generateRandomBusinessUserInfo(); + result.photoUrl = generateRandomString(); + result.photoLastUpdated = generateRandomInt64(); + result.accountLimits = generateRandomAccountLimits(); + return result; +} + +Contact generateRandomContact() +{ + Contact result; + result.name = generateRandomString(); + result.id = generateRandomString(); + result.type = ContactType::EVERNOTE; + result.photoUrl = generateRandomString(); + result.photoLastUpdated = generateRandomInt64(); + result.messagingPermit = generateRandomString().toUtf8(); + result.messagingPermitExpires = generateRandomInt64(); + return result; +} + +Identity generateRandomIdentity() +{ + Identity result; + result.id = generateRandomInt64(); + result.contact = generateRandomContact(); + result.userId = generateRandomInt32(); + result.deactivated = generateRandomBool(); + result.sameBusiness = generateRandomBool(); + result.blocked = generateRandomBool(); + result.userConnected = generateRandomBool(); + result.eventId = generateRandomInt64(); + return result; +} + +Tag generateRandomTag() +{ + Tag result; + result.guid = generateRandomString(); + result.name = generateRandomString(); + result.parentGuid = generateRandomString(); + result.updateSequenceNum = generateRandomInt32(); + return result; +} + +LazyMap generateRandomLazyMap() +{ + LazyMap result; + result.keysOnly = QSet(); + result.keysOnly->insert(generateRandomString()); + result.keysOnly->insert(generateRandomString()); + result.keysOnly->insert(generateRandomString()); + result.fullMap = QMap(); + result.fullMap.ref()[generateRandomString()] = generateRandomString(); + result.fullMap.ref()[generateRandomString()] = generateRandomString(); + result.fullMap.ref()[generateRandomString()] = generateRandomString(); + return result; +} + +ResourceAttributes generateRandomResourceAttributes() +{ + ResourceAttributes result; + result.sourceURL = generateRandomString(); + result.timestamp = generateRandomInt64(); + result.latitude = generateRandomDouble(); + result.longitude = generateRandomDouble(); + result.altitude = generateRandomDouble(); + result.cameraMake = generateRandomString(); + result.cameraModel = generateRandomString(); + result.clientWillIndex = generateRandomBool(); + result.recoType = generateRandomString(); + result.fileName = generateRandomString(); + result.attachment = generateRandomBool(); + result.applicationData = generateRandomLazyMap(); + return result; +} + +Resource generateRandomResource() +{ + Resource result; + result.guid = generateRandomString(); + result.noteGuid = generateRandomString(); + result.data = generateRandomData(); + result.mime = generateRandomString(); + result.width = generateRandomInt16(); + result.height = generateRandomInt16(); + result.duration = generateRandomInt16(); + result.active = generateRandomBool(); + result.recognition = generateRandomData(); + result.attributes = generateRandomResourceAttributes(); + result.updateSequenceNum = generateRandomInt32(); + result.alternateData = generateRandomData(); + return result; +} + +NoteAttributes generateRandomNoteAttributes() +{ + NoteAttributes result; + result.subjectDate = generateRandomInt64(); + result.latitude = generateRandomDouble(); + result.longitude = generateRandomDouble(); + result.altitude = generateRandomDouble(); + result.author = generateRandomString(); + result.source = generateRandomString(); + result.sourceURL = generateRandomString(); + result.sourceApplication = generateRandomString(); + result.shareDate = generateRandomInt64(); + result.reminderOrder = generateRandomInt64(); + result.reminderDoneTime = generateRandomInt64(); + result.reminderTime = generateRandomInt64(); + result.placeName = generateRandomString(); + result.contentClass = generateRandomString(); + result.applicationData = generateRandomLazyMap(); + result.lastEditedBy = generateRandomString(); + result.classifications = QMap(); + result.classifications.ref()[generateRandomString()] = generateRandomString(); + result.classifications.ref()[generateRandomString()] = generateRandomString(); + result.classifications.ref()[generateRandomString()] = generateRandomString(); + result.creatorId = generateRandomInt32(); + result.lastEditorId = generateRandomInt32(); + result.sharedWithBusiness = generateRandomBool(); + result.conflictSourceNoteGuid = generateRandomString(); + result.noteTitleQuality = generateRandomInt32(); + return result; +} + +SharedNote generateRandomSharedNote() +{ + SharedNote result; + result.sharerUserID = generateRandomInt32(); + result.recipientIdentity = generateRandomIdentity(); + result.privilege = SharedNotePrivilegeLevel::FULL_ACCESS; + result.serviceCreated = generateRandomInt64(); + result.serviceUpdated = generateRandomInt64(); + result.serviceAssigned = generateRandomInt64(); + return result; +} + +NoteRestrictions generateRandomNoteRestrictions() +{ + NoteRestrictions result; + result.noUpdateTitle = generateRandomBool(); + result.noUpdateContent = generateRandomBool(); + result.noEmail = generateRandomBool(); + result.noShare = generateRandomBool(); + result.noSharePublicly = generateRandomBool(); + return result; +} + +NoteLimits generateRandomNoteLimits() +{ + NoteLimits result; + result.noteResourceCountMax = generateRandomInt32(); + result.uploadLimit = generateRandomInt64(); + result.resourceSizeMax = generateRandomInt64(); + result.noteSizeMax = generateRandomInt64(); + result.uploaded = generateRandomInt64(); + return result; +} + +Note generateRandomNote() +{ + Note result; + result.guid = generateRandomString(); + result.title = generateRandomString(); + result.content = generateRandomString(); + result.contentHash = generateRandomString().toUtf8(); + result.contentLength = generateRandomInt32(); + result.created = generateRandomInt64(); + result.updated = generateRandomInt64(); + result.deleted = generateRandomInt64(); + result.active = generateRandomBool(); + result.updateSequenceNum = generateRandomInt32(); + result.notebookGuid = generateRandomString(); + result.tagGuids = QList(); + result.tagGuids.ref() << generateRandomString(); + result.tagGuids.ref() << generateRandomString(); + result.tagGuids.ref() << generateRandomString(); + result.resources = QList(); + result.resources.ref() << generateRandomResource(); + result.resources.ref() << generateRandomResource(); + result.resources.ref() << generateRandomResource(); + result.attributes = generateRandomNoteAttributes(); + result.tagNames = QList(); + result.tagNames.ref() << generateRandomString(); + result.tagNames.ref() << generateRandomString(); + result.tagNames.ref() << generateRandomString(); + result.sharedNotes = QList(); + result.sharedNotes.ref() << generateRandomSharedNote(); + result.sharedNotes.ref() << generateRandomSharedNote(); + result.sharedNotes.ref() << generateRandomSharedNote(); + result.restrictions = generateRandomNoteRestrictions(); + result.limits = generateRandomNoteLimits(); + return result; +} + +Publishing generateRandomPublishing() +{ + Publishing result; + result.uri = generateRandomString(); + result.order = NoteSortOrder::UPDATED; + result.ascending = generateRandomBool(); + result.publicDescription = generateRandomString(); + return result; +} + +BusinessNotebook generateRandomBusinessNotebook() +{ + BusinessNotebook result; + result.notebookDescription = generateRandomString(); + result.privilege = SharedNotebookPrivilegeLevel::GROUP; + result.recommended = generateRandomBool(); + return result; +} + +SavedSearchScope generateRandomSavedSearchScope() +{ + SavedSearchScope result; + result.includeAccount = generateRandomBool(); + result.includePersonalLinkedNotebooks = generateRandomBool(); + result.includeBusinessLinkedNotebooks = generateRandomBool(); + return result; +} + +SavedSearch generateRandomSavedSearch() +{ + SavedSearch result; + result.guid = generateRandomString(); + result.name = generateRandomString(); + result.query = generateRandomString(); + result.format = QueryFormat::USER; + result.updateSequenceNum = generateRandomInt32(); + result.scope = generateRandomSavedSearchScope(); + return result; +} + +SharedNotebookRecipientSettings generateRandomSharedNotebookRecipientSettings() +{ + SharedNotebookRecipientSettings result; + result.reminderNotifyEmail = generateRandomBool(); + result.reminderNotifyInApp = generateRandomBool(); + return result; +} + +NotebookRecipientSettings generateRandomNotebookRecipientSettings() +{ + NotebookRecipientSettings result; + result.reminderNotifyEmail = generateRandomBool(); + result.reminderNotifyInApp = generateRandomBool(); + result.inMyList = generateRandomBool(); + result.stack = generateRandomString(); + result.recipientStatus = RecipientStatus::IN_MY_LIST_AND_DEFAULT_NOTEBOOK; + return result; +} + +SharedNotebook generateRandomSharedNotebook() +{ + SharedNotebook result; + result.id = generateRandomInt64(); + result.userId = generateRandomInt32(); + result.notebookGuid = generateRandomString(); + result.email = generateRandomString(); + result.recipientIdentityId = generateRandomInt64(); + result.notebookModifiable = generateRandomBool(); + result.serviceCreated = generateRandomInt64(); + result.serviceUpdated = generateRandomInt64(); + result.globalId = generateRandomString(); + result.username = generateRandomString(); + result.privilege = SharedNotebookPrivilegeLevel::GROUP; + result.recipientSettings = generateRandomSharedNotebookRecipientSettings(); + result.sharerUserId = generateRandomInt32(); + result.recipientUsername = generateRandomString(); + result.recipientUserId = generateRandomInt32(); + result.serviceAssigned = generateRandomInt64(); + return result; +} + +CanMoveToContainerRestrictions generateRandomCanMoveToContainerRestrictions() +{ + CanMoveToContainerRestrictions result; + result.canMoveToContainer = CanMoveToContainerStatus::INSUFFICIENT_ENTITY_PRIVILEGE; + return result; +} + +NotebookRestrictions generateRandomNotebookRestrictions() +{ + NotebookRestrictions result; + result.noReadNotes = generateRandomBool(); + result.noCreateNotes = generateRandomBool(); + result.noUpdateNotes = generateRandomBool(); + result.noExpungeNotes = generateRandomBool(); + result.noShareNotes = generateRandomBool(); + result.noEmailNotes = generateRandomBool(); + result.noSendMessageToRecipients = generateRandomBool(); + result.noUpdateNotebook = generateRandomBool(); + result.noExpungeNotebook = generateRandomBool(); + result.noSetDefaultNotebook = generateRandomBool(); + result.noSetNotebookStack = generateRandomBool(); + result.noPublishToPublic = generateRandomBool(); + result.noPublishToBusinessLibrary = generateRandomBool(); + result.noCreateTags = generateRandomBool(); + result.noUpdateTags = generateRandomBool(); + result.noExpungeTags = generateRandomBool(); + result.noSetParentTag = generateRandomBool(); + result.noCreateSharedNotebooks = generateRandomBool(); + result.updateWhichSharedNotebookRestrictions = SharedNotebookInstanceRestrictions::ASSIGNED; + result.expungeWhichSharedNotebookRestrictions = SharedNotebookInstanceRestrictions::NO_SHARED_NOTEBOOKS; + result.noShareNotesWithBusiness = generateRandomBool(); + result.noRenameNotebook = generateRandomBool(); + result.noSetInMyList = generateRandomBool(); + result.noChangeContact = generateRandomBool(); + result.canMoveToContainerRestrictions = generateRandomCanMoveToContainerRestrictions(); + result.noSetReminderNotifyEmail = generateRandomBool(); + result.noSetReminderNotifyInApp = generateRandomBool(); + result.noSetRecipientSettingsStack = generateRandomBool(); + result.noCanMoveNote = generateRandomBool(); + return result; +} + +Notebook generateRandomNotebook() +{ + Notebook result; + result.guid = generateRandomString(); + result.name = generateRandomString(); + result.updateSequenceNum = generateRandomInt32(); + result.defaultNotebook = generateRandomBool(); + result.serviceCreated = generateRandomInt64(); + result.serviceUpdated = generateRandomInt64(); + result.publishing = generateRandomPublishing(); + result.published = generateRandomBool(); + result.stack = generateRandomString(); + result.sharedNotebookIds = QList(); + result.sharedNotebookIds.ref() << generateRandomInt64(); + result.sharedNotebookIds.ref() << generateRandomInt64(); + result.sharedNotebookIds.ref() << generateRandomInt64(); + result.sharedNotebooks = QList(); + result.sharedNotebooks.ref() << generateRandomSharedNotebook(); + result.sharedNotebooks.ref() << generateRandomSharedNotebook(); + result.sharedNotebooks.ref() << generateRandomSharedNotebook(); + result.businessNotebook = generateRandomBusinessNotebook(); + result.contact = generateRandomUser(); + result.restrictions = generateRandomNotebookRestrictions(); + result.recipientSettings = generateRandomNotebookRecipientSettings(); + return result; +} + +LinkedNotebook generateRandomLinkedNotebook() +{ + LinkedNotebook result; + result.shareName = generateRandomString(); + result.username = generateRandomString(); + result.shardId = generateRandomString(); + result.sharedNotebookGlobalId = generateRandomString(); + result.uri = generateRandomString(); + result.guid = generateRandomString(); + result.updateSequenceNum = generateRandomInt32(); + result.noteStoreUrl = generateRandomString(); + result.webApiUrlPrefix = generateRandomString(); + result.stack = generateRandomString(); + result.businessId = generateRandomInt32(); + return result; +} + +NotebookDescriptor generateRandomNotebookDescriptor() +{ + NotebookDescriptor result; + result.guid = generateRandomString(); + result.notebookDisplayName = generateRandomString(); + result.contactName = generateRandomString(); + result.hasSharedNotebook = generateRandomBool(); + result.joinedUserCount = generateRandomInt32(); + return result; +} + +UserProfile generateRandomUserProfile() +{ + UserProfile result; + result.id = generateRandomInt32(); + result.name = generateRandomString(); + result.email = generateRandomString(); + result.username = generateRandomString(); + result.attributes = generateRandomBusinessUserAttributes(); + result.joined = generateRandomInt64(); + result.photoLastUpdated = generateRandomInt64(); + result.photoUrl = generateRandomString(); + result.role = BusinessUserRole::NORMAL; + result.status = BusinessUserStatus::ACTIVE; + return result; +} + +RelatedContentImage generateRandomRelatedContentImage() +{ + RelatedContentImage result; + result.url = generateRandomString(); + result.width = generateRandomInt32(); + result.height = generateRandomInt32(); + result.pixelRatio = generateRandomDouble(); + result.fileSize = generateRandomInt32(); + return result; +} + +RelatedContent generateRandomRelatedContent() +{ + RelatedContent result; + result.contentId = generateRandomString(); + result.title = generateRandomString(); + result.url = generateRandomString(); + result.sourceId = generateRandomString(); + result.sourceUrl = generateRandomString(); + result.sourceFaviconUrl = generateRandomString(); + result.sourceName = generateRandomString(); + result.date = generateRandomInt64(); + result.teaser = generateRandomString(); + result.thumbnails = QList(); + result.thumbnails.ref() << generateRandomRelatedContentImage(); + result.thumbnails.ref() << generateRandomRelatedContentImage(); + result.thumbnails.ref() << generateRandomRelatedContentImage(); + result.contentType = RelatedContentType::NEWS_ARTICLE; + result.accessType = RelatedContentAccess::DIRECT_LINK_EMBEDDED_VIEW; + result.visibleUrl = generateRandomString(); + result.clipUrl = generateRandomString(); + result.contact = generateRandomContact(); + result.authors = QList(); + result.authors.ref() << generateRandomString(); + result.authors.ref() << generateRandomString(); + result.authors.ref() << generateRandomString(); + return result; +} + +BusinessInvitation generateRandomBusinessInvitation() +{ + BusinessInvitation result; + result.businessId = generateRandomInt32(); + result.email = generateRandomString(); + result.role = BusinessUserRole::ADMIN; + result.status = BusinessInvitationStatus::APPROVED; + result.requesterId = generateRandomInt32(); + result.fromWorkChat = generateRandomBool(); + result.created = generateRandomInt64(); + result.mostRecentReminder = generateRandomInt64(); + return result; +} + +UserIdentity generateRandomUserIdentity() +{ + UserIdentity result; + result.type = UserIdentityType::IDENTITYID; + result.stringIdentifier = generateRandomString(); + result.longIdentifier = generateRandomInt64(); + return result; +} + +PublicUserInfo generateRandomPublicUserInfo() +{ + PublicUserInfo result; + result.userId = generateRandomInt32(); + result.serviceLevel = ServiceLevel::PLUS; + result.username = generateRandomString(); + result.noteStoreUrl = generateRandomString(); + result.webApiUrlPrefix = generateRandomString(); + return result; +} + +UserUrls generateRandomUserUrls() +{ + UserUrls result; + result.noteStoreUrl = generateRandomString(); + result.webApiUrlPrefix = generateRandomString(); + result.userStoreUrl = generateRandomString(); + result.utilityUrl = generateRandomString(); + result.messageStoreUrl = generateRandomString(); + result.userWebSocketUrl = generateRandomString(); + return result; +} + +AuthenticationResult generateRandomAuthenticationResult() +{ + AuthenticationResult result; + result.currentTime = generateRandomInt64(); + result.authenticationToken = generateRandomString(); + result.expiration = generateRandomInt64(); + result.user = generateRandomUser(); + result.publicUserInfo = generateRandomPublicUserInfo(); + result.noteStoreUrl = generateRandomString(); + result.webApiUrlPrefix = generateRandomString(); + result.secondFactorRequired = generateRandomBool(); + result.secondFactorDeliveryHint = generateRandomString(); + result.urls = generateRandomUserUrls(); + return result; +} + +BootstrapSettings generateRandomBootstrapSettings() +{ + BootstrapSettings result; + result.serviceHost = generateRandomString(); + result.marketingUrl = generateRandomString(); + result.supportUrl = generateRandomString(); + result.accountEmailDomain = generateRandomString(); + result.enableFacebookSharing = generateRandomBool(); + result.enableGiftSubscriptions = generateRandomBool(); + result.enableSupportTickets = generateRandomBool(); + result.enableSharedNotebooks = generateRandomBool(); + result.enableSingleNoteSharing = generateRandomBool(); + result.enableSponsoredAccounts = generateRandomBool(); + result.enableTwitterSharing = generateRandomBool(); + result.enableLinkedInSharing = generateRandomBool(); + result.enablePublicNotebooks = generateRandomBool(); + result.enableGoogle = generateRandomBool(); + return result; +} + +BootstrapProfile generateRandomBootstrapProfile() +{ + BootstrapProfile result; + result.name = generateRandomString(); + result.settings = generateRandomBootstrapSettings(); + return result; +} + +BootstrapInfo generateRandomBootstrapInfo() +{ + BootstrapInfo result; + result.profiles << generateRandomBootstrapProfile(); + result.profiles << generateRandomBootstrapProfile(); + result.profiles << generateRandomBootstrapProfile(); + return result; +} + +} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/src/tests/generated/RandomDataGenerators.h b/src/qevercloud/QEverCloud/src/tests/generated/RandomDataGenerators.h new file mode 100644 index 00000000..df24d567 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/tests/generated/RandomDataGenerators.h @@ -0,0 +1,195 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + * + * This file was generated from Evernote Thrift API + */ + +#ifndef QEVERCLOUD_GENERATED_RANDOMDATAGENERATORS_H +#define QEVERCLOUD_GENERATED_RANDOMDATAGENERATORS_H + +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +QString generateRandomString(int len = 10); + +qint8 generateRandomInt8(); + +qint16 generateRandomInt16(); + +qint32 generateRandomInt32(); + +qint64 generateRandomInt64(); + +quint8 generateRandomUint8(); + +quint16 generateRandomUint16(); + +quint32 generateRandomUint32(); + +quint64 generateRandomUint64(); + +double generateRandomDouble(); + +bool generateRandomBool(); + +//////////////////////////////////////////////////////////////////////////////// + +SyncState generateRandomSyncState(); + +SyncChunk generateRandomSyncChunk(); + +SyncChunkFilter generateRandomSyncChunkFilter(); + +NoteFilter generateRandomNoteFilter(); + +NoteList generateRandomNoteList(); + +NoteMetadata generateRandomNoteMetadata(); + +NotesMetadataList generateRandomNotesMetadataList(); + +NotesMetadataResultSpec generateRandomNotesMetadataResultSpec(); + +NoteCollectionCounts generateRandomNoteCollectionCounts(); + +NoteResultSpec generateRandomNoteResultSpec(); + +NoteEmailParameters generateRandomNoteEmailParameters(); + +NoteVersionId generateRandomNoteVersionId(); + +RelatedQuery generateRandomRelatedQuery(); + +RelatedResult generateRandomRelatedResult(); + +RelatedResultSpec generateRandomRelatedResultSpec(); + +UpdateNoteIfUsnMatchesResult generateRandomUpdateNoteIfUsnMatchesResult(); + +ShareRelationshipRestrictions generateRandomShareRelationshipRestrictions(); + +InvitationShareRelationship generateRandomInvitationShareRelationship(); + +MemberShareRelationship generateRandomMemberShareRelationship(); + +ShareRelationships generateRandomShareRelationships(); + +ManageNotebookSharesParameters generateRandomManageNotebookSharesParameters(); + +ManageNotebookSharesError generateRandomManageNotebookSharesError(); + +ManageNotebookSharesResult generateRandomManageNotebookSharesResult(); + +SharedNoteTemplate generateRandomSharedNoteTemplate(); + +NotebookShareTemplate generateRandomNotebookShareTemplate(); + +CreateOrUpdateNotebookSharesResult generateRandomCreateOrUpdateNotebookSharesResult(); + +NoteShareRelationshipRestrictions generateRandomNoteShareRelationshipRestrictions(); + +NoteMemberShareRelationship generateRandomNoteMemberShareRelationship(); + +NoteInvitationShareRelationship generateRandomNoteInvitationShareRelationship(); + +NoteShareRelationships generateRandomNoteShareRelationships(); + +ManageNoteSharesParameters generateRandomManageNoteSharesParameters(); + +ManageNoteSharesError generateRandomManageNoteSharesError(); + +ManageNoteSharesResult generateRandomManageNoteSharesResult(); + +Data generateRandomData(); + +UserAttributes generateRandomUserAttributes(); + +BusinessUserAttributes generateRandomBusinessUserAttributes(); + +Accounting generateRandomAccounting(); + +BusinessUserInfo generateRandomBusinessUserInfo(); + +AccountLimits generateRandomAccountLimits(); + +User generateRandomUser(); + +Contact generateRandomContact(); + +Identity generateRandomIdentity(); + +Tag generateRandomTag(); + +LazyMap generateRandomLazyMap(); + +ResourceAttributes generateRandomResourceAttributes(); + +Resource generateRandomResource(); + +NoteAttributes generateRandomNoteAttributes(); + +SharedNote generateRandomSharedNote(); + +NoteRestrictions generateRandomNoteRestrictions(); + +NoteLimits generateRandomNoteLimits(); + +Note generateRandomNote(); + +Publishing generateRandomPublishing(); + +BusinessNotebook generateRandomBusinessNotebook(); + +SavedSearchScope generateRandomSavedSearchScope(); + +SavedSearch generateRandomSavedSearch(); + +SharedNotebookRecipientSettings generateRandomSharedNotebookRecipientSettings(); + +NotebookRecipientSettings generateRandomNotebookRecipientSettings(); + +SharedNotebook generateRandomSharedNotebook(); + +CanMoveToContainerRestrictions generateRandomCanMoveToContainerRestrictions(); + +NotebookRestrictions generateRandomNotebookRestrictions(); + +Notebook generateRandomNotebook(); + +LinkedNotebook generateRandomLinkedNotebook(); + +NotebookDescriptor generateRandomNotebookDescriptor(); + +UserProfile generateRandomUserProfile(); + +RelatedContentImage generateRandomRelatedContentImage(); + +RelatedContent generateRandomRelatedContent(); + +BusinessInvitation generateRandomBusinessInvitation(); + +UserIdentity generateRandomUserIdentity(); + +PublicUserInfo generateRandomPublicUserInfo(); + +UserUrls generateRandomUserUrls(); + +AuthenticationResult generateRandomAuthenticationResult(); + +BootstrapSettings generateRandomBootstrapSettings(); + +BootstrapProfile generateRandomBootstrapProfile(); + +BootstrapInfo generateRandomBootstrapInfo(); + +} // namespace qevercloud + +#endif // QEVERCLOUD_GENERATED_RANDOMDATAGENERATORS_H diff --git a/src/qevercloud/QEverCloud/src/tests/generated/TestNoteStore.cpp b/src/qevercloud/QEverCloud/src/tests/generated/TestNoteStore.cpp new file mode 100644 index 00000000..84b46fed --- /dev/null +++ b/src/qevercloud/QEverCloud/src/tests/generated/TestNoteStore.cpp @@ -0,0 +1,83285 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + * + * This file was generated from Evernote Thrift API + */ + +#include "TestNoteStore.h" +#include "../../Impl.h" +#include "../../HttpUtils.h" +#include "RandomDataGenerators.h" +#include +#include +#include +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +NoteStoreTester::NoteStoreTester(QObject * parent) : + QObject(parent) +{} + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetSyncStateTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + SyncState( + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetSyncStateTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getSyncStateRequestReady( + SyncState value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetSyncStateRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT getSyncStateRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getSyncStateRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetFilteredSyncChunkTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + SyncChunk( + qint32, + qint32, + const SyncChunkFilter &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetFilteredSyncChunkTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getFilteredSyncChunkRequestReady( + SyncChunk value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetFilteredSyncChunkRequestReceived( + qint32 afterUSN, + qint32 maxEntries, + SyncChunkFilter filter, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + afterUSN, + maxEntries, + filter, + ctx); + + Q_EMIT getFilteredSyncChunkRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getFilteredSyncChunkRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetLinkedNotebookSyncStateTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + SyncState( + const LinkedNotebook &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetLinkedNotebookSyncStateTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getLinkedNotebookSyncStateRequestReady( + SyncState value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetLinkedNotebookSyncStateRequestReceived( + LinkedNotebook linkedNotebook, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + linkedNotebook, + ctx); + + Q_EMIT getLinkedNotebookSyncStateRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getLinkedNotebookSyncStateRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetLinkedNotebookSyncChunkTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + SyncChunk( + const LinkedNotebook &, + qint32, + qint32, + bool, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetLinkedNotebookSyncChunkTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getLinkedNotebookSyncChunkRequestReady( + SyncChunk value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetLinkedNotebookSyncChunkRequestReceived( + LinkedNotebook linkedNotebook, + qint32 afterUSN, + qint32 maxEntries, + bool fullSyncOnly, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + + Q_EMIT getLinkedNotebookSyncChunkRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getLinkedNotebookSyncChunkRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListNotebooksTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QList( + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreListNotebooksTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void listNotebooksRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onListNotebooksRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT listNotebooksRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT listNotebooksRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListAccessibleBusinessNotebooksTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QList( + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreListAccessibleBusinessNotebooksTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void listAccessibleBusinessNotebooksRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onListAccessibleBusinessNotebooksRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT listAccessibleBusinessNotebooksRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT listAccessibleBusinessNotebooksRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Notebook( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getNotebookRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetNotebookRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT getNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetDefaultNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Notebook( + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetDefaultNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getDefaultNotebookRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetDefaultNotebookRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT getDefaultNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getDefaultNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCreateNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Notebook( + const Notebook &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreCreateNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void createNotebookRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onCreateNotebookRequestReceived( + Notebook notebook, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + notebook, + ctx); + + Q_EMIT createNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT createNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + const Notebook &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreUpdateNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void updateNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onUpdateNotebookRequestReceived( + Notebook notebook, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + notebook, + ctx); + + Q_EMIT updateNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT updateNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreExpungeNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreExpungeNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void expungeNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onExpungeNotebookRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT expungeNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT expungeNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListTagsTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QList( + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreListTagsTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void listTagsRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onListTagsRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT listTagsRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT listTagsRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListTagsByNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QList( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreListTagsByNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void listTagsByNotebookRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onListTagsByNotebookRequestReceived( + Guid notebookGuid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + notebookGuid, + ctx); + + Q_EMIT listTagsByNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT listTagsByNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetTagTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Tag( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetTagTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getTagRequestReady( + Tag value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetTagRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT getTagRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getTagRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCreateTagTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Tag( + const Tag &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreCreateTagTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void createTagRequestReady( + Tag value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onCreateTagRequestReceived( + Tag tag, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + tag, + ctx); + + Q_EMIT createTagRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT createTagRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateTagTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + const Tag &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreUpdateTagTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void updateTagRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onUpdateTagRequestReceived( + Tag tag, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + tag, + ctx); + + Q_EMIT updateTagRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT updateTagRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUntagAllTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + void( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreUntagAllTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void untagAllRequestReady( + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onUntagAllRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + m_executor( + guid, + ctx); + + Q_EMIT untagAllRequestReady( + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT untagAllRequestReady( + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreExpungeTagTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreExpungeTagTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void expungeTagRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onExpungeTagRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT expungeTagRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT expungeTagRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListSearchesTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QList( + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreListSearchesTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void listSearchesRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onListSearchesRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT listSearchesRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT listSearchesRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetSearchTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + SavedSearch( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetSearchTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getSearchRequestReady( + SavedSearch value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetSearchRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT getSearchRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getSearchRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCreateSearchTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + SavedSearch( + const SavedSearch &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreCreateSearchTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void createSearchRequestReady( + SavedSearch value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onCreateSearchRequestReceived( + SavedSearch search, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + search, + ctx); + + Q_EMIT createSearchRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT createSearchRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateSearchTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + const SavedSearch &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreUpdateSearchTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void updateSearchRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onUpdateSearchRequestReceived( + SavedSearch search, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + search, + ctx); + + Q_EMIT updateSearchRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT updateSearchRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreExpungeSearchTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreExpungeSearchTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void expungeSearchRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onExpungeSearchRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT expungeSearchRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT expungeSearchRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreFindNoteOffsetTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + const NoteFilter &, + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreFindNoteOffsetTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void findNoteOffsetRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onFindNoteOffsetRequestReceived( + NoteFilter filter, + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + filter, + guid, + ctx); + + Q_EMIT findNoteOffsetRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT findNoteOffsetRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreFindNotesMetadataTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + NotesMetadataList( + const NoteFilter &, + qint32, + qint32, + const NotesMetadataResultSpec &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreFindNotesMetadataTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void findNotesMetadataRequestReady( + NotesMetadataList value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onFindNotesMetadataRequestReceived( + NoteFilter filter, + qint32 offset, + qint32 maxNotes, + NotesMetadataResultSpec resultSpec, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + filter, + offset, + maxNotes, + resultSpec, + ctx); + + Q_EMIT findNotesMetadataRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT findNotesMetadataRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreFindNoteCountsTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + NoteCollectionCounts( + const NoteFilter &, + bool, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreFindNoteCountsTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void findNoteCountsRequestReady( + NoteCollectionCounts value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onFindNoteCountsRequestReceived( + NoteFilter filter, + bool withTrash, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + filter, + withTrash, + ctx); + + Q_EMIT findNoteCountsRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT findNoteCountsRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteWithResultSpecTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Note( + Guid, + const NoteResultSpec &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetNoteWithResultSpecTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getNoteWithResultSpecRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetNoteWithResultSpecRequestReceived( + Guid guid, + NoteResultSpec resultSpec, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + resultSpec, + ctx); + + Q_EMIT getNoteWithResultSpecRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getNoteWithResultSpecRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Note( + Guid, + bool, + bool, + bool, + bool, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetNoteTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getNoteRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetNoteRequestReceived( + Guid guid, + bool withContent, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + Q_EMIT getNoteRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getNoteRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteApplicationDataTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + LazyMap( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetNoteApplicationDataTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getNoteApplicationDataRequestReady( + LazyMap value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetNoteApplicationDataRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT getNoteApplicationDataRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getNoteApplicationDataRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteApplicationDataEntryTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QString( + Guid, + QString, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetNoteApplicationDataEntryTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getNoteApplicationDataEntryRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetNoteApplicationDataEntryRequestReceived( + Guid guid, + QString key, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + key, + ctx); + + Q_EMIT getNoteApplicationDataEntryRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getNoteApplicationDataEntryRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreSetNoteApplicationDataEntryTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + Guid, + QString, + QString, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreSetNoteApplicationDataEntryTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void setNoteApplicationDataEntryRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onSetNoteApplicationDataEntryRequestReceived( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + key, + value, + ctx); + + Q_EMIT setNoteApplicationDataEntryRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT setNoteApplicationDataEntryRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUnsetNoteApplicationDataEntryTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + Guid, + QString, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreUnsetNoteApplicationDataEntryTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void unsetNoteApplicationDataEntryRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onUnsetNoteApplicationDataEntryRequestReceived( + Guid guid, + QString key, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + key, + ctx); + + Q_EMIT unsetNoteApplicationDataEntryRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT unsetNoteApplicationDataEntryRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteContentTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QString( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetNoteContentTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getNoteContentRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetNoteContentRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT getNoteContentRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getNoteContentRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteSearchTextTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QString( + Guid, + bool, + bool, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetNoteSearchTextTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getNoteSearchTextRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetNoteSearchTextRequestReceived( + Guid guid, + bool noteOnly, + bool tokenizeForIndexing, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + + Q_EMIT getNoteSearchTextRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getNoteSearchTextRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceSearchTextTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QString( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetResourceSearchTextTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getResourceSearchTextRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetResourceSearchTextRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT getResourceSearchTextRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getResourceSearchTextRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteTagNamesTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QStringList( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetNoteTagNamesTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getNoteTagNamesRequestReady( + QStringList value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetNoteTagNamesRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT getNoteTagNamesRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getNoteTagNamesRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCreateNoteTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Note( + const Note &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreCreateNoteTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void createNoteRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onCreateNoteRequestReceived( + Note note, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + note, + ctx); + + Q_EMIT createNoteRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT createNoteRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateNoteTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Note( + const Note &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreUpdateNoteTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void updateNoteRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onUpdateNoteRequestReceived( + Note note, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + note, + ctx); + + Q_EMIT updateNoteRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT updateNoteRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreDeleteNoteTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreDeleteNoteTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void deleteNoteRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onDeleteNoteRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT deleteNoteRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT deleteNoteRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreExpungeNoteTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreExpungeNoteTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void expungeNoteRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onExpungeNoteRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT expungeNoteRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT expungeNoteRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCopyNoteTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Note( + Guid, + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreCopyNoteTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void copyNoteRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onCopyNoteRequestReceived( + Guid noteGuid, + Guid toNotebookGuid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + noteGuid, + toNotebookGuid, + ctx); + + Q_EMIT copyNoteRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT copyNoteRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListNoteVersionsTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QList( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreListNoteVersionsTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void listNoteVersionsRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onListNoteVersionsRequestReceived( + Guid noteGuid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + noteGuid, + ctx); + + Q_EMIT listNoteVersionsRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT listNoteVersionsRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteVersionTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Note( + Guid, + qint32, + bool, + bool, + bool, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetNoteVersionTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getNoteVersionRequestReady( + Note value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetNoteVersionRequestReceived( + Guid noteGuid, + qint32 updateSequenceNum, + bool withResourcesData, + bool withResourcesRecognition, + bool withResourcesAlternateData, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + Q_EMIT getNoteVersionRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getNoteVersionRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Resource( + Guid, + bool, + bool, + bool, + bool, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetResourceTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getResourceRequestReady( + Resource value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetResourceRequestReceived( + Guid guid, + bool withData, + bool withRecognition, + bool withAttributes, + bool withAlternateData, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + + Q_EMIT getResourceRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getResourceRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceApplicationDataTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + LazyMap( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetResourceApplicationDataTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getResourceApplicationDataRequestReady( + LazyMap value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetResourceApplicationDataRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT getResourceApplicationDataRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getResourceApplicationDataRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceApplicationDataEntryTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QString( + Guid, + QString, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetResourceApplicationDataEntryTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getResourceApplicationDataEntryRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetResourceApplicationDataEntryRequestReceived( + Guid guid, + QString key, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + key, + ctx); + + Q_EMIT getResourceApplicationDataEntryRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getResourceApplicationDataEntryRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreSetResourceApplicationDataEntryTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + Guid, + QString, + QString, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreSetResourceApplicationDataEntryTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void setResourceApplicationDataEntryRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onSetResourceApplicationDataEntryRequestReceived( + Guid guid, + QString key, + QString value, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + key, + value, + ctx); + + Q_EMIT setResourceApplicationDataEntryRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT setResourceApplicationDataEntryRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUnsetResourceApplicationDataEntryTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + Guid, + QString, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreUnsetResourceApplicationDataEntryTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void unsetResourceApplicationDataEntryRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onUnsetResourceApplicationDataEntryRequestReceived( + Guid guid, + QString key, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + key, + ctx); + + Q_EMIT unsetResourceApplicationDataEntryRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT unsetResourceApplicationDataEntryRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateResourceTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + const Resource &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreUpdateResourceTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void updateResourceRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onUpdateResourceRequestReceived( + Resource resource, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + resource, + ctx); + + Q_EMIT updateResourceRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT updateResourceRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceDataTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QByteArray( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetResourceDataTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getResourceDataRequestReady( + QByteArray value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetResourceDataRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT getResourceDataRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getResourceDataRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceByHashTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Resource( + Guid, + QByteArray, + bool, + bool, + bool, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetResourceByHashTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getResourceByHashRequestReady( + Resource value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetResourceByHashRequestReceived( + Guid noteGuid, + QByteArray contentHash, + bool withData, + bool withRecognition, + bool withAlternateData, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + + Q_EMIT getResourceByHashRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getResourceByHashRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceRecognitionTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QByteArray( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetResourceRecognitionTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getResourceRecognitionRequestReady( + QByteArray value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetResourceRecognitionRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT getResourceRecognitionRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getResourceRecognitionRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceAlternateDataTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QByteArray( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetResourceAlternateDataTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getResourceAlternateDataRequestReady( + QByteArray value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetResourceAlternateDataRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT getResourceAlternateDataRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getResourceAlternateDataRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceAttributesTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + ResourceAttributes( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetResourceAttributesTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getResourceAttributesRequestReady( + ResourceAttributes value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetResourceAttributesRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT getResourceAttributesRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getResourceAttributesRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetPublicNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Notebook( + UserID, + QString, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetPublicNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getPublicNotebookRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetPublicNotebookRequestReceived( + UserID userId, + QString publicUri, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + userId, + publicUri, + ctx); + + Q_EMIT getPublicNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getPublicNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreShareNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + SharedNotebook( + const SharedNotebook &, + QString, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreShareNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void shareNotebookRequestReady( + SharedNotebook value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onShareNotebookRequestReceived( + SharedNotebook sharedNotebook, + QString message, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + sharedNotebook, + message, + ctx); + + Q_EMIT shareNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT shareNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCreateOrUpdateNotebookSharesTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + CreateOrUpdateNotebookSharesResult( + const NotebookShareTemplate &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreCreateOrUpdateNotebookSharesTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void createOrUpdateNotebookSharesRequestReady( + CreateOrUpdateNotebookSharesResult value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onCreateOrUpdateNotebookSharesRequestReceived( + NotebookShareTemplate shareTemplate, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + shareTemplate, + ctx); + + Q_EMIT createOrUpdateNotebookSharesRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT createOrUpdateNotebookSharesRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateSharedNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + const SharedNotebook &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreUpdateSharedNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void updateSharedNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onUpdateSharedNotebookRequestReceived( + SharedNotebook sharedNotebook, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + sharedNotebook, + ctx); + + Q_EMIT updateSharedNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT updateSharedNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreSetNotebookRecipientSettingsTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + Notebook( + QString, + const NotebookRecipientSettings &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreSetNotebookRecipientSettingsTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void setNotebookRecipientSettingsRequestReady( + Notebook value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onSetNotebookRecipientSettingsRequestReceived( + QString notebookGuid, + NotebookRecipientSettings recipientSettings, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + notebookGuid, + recipientSettings, + ctx); + + Q_EMIT setNotebookRecipientSettingsRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT setNotebookRecipientSettingsRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListSharedNotebooksTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QList( + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreListSharedNotebooksTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void listSharedNotebooksRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onListSharedNotebooksRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT listSharedNotebooksRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT listSharedNotebooksRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCreateLinkedNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + LinkedNotebook( + const LinkedNotebook &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreCreateLinkedNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void createLinkedNotebookRequestReady( + LinkedNotebook value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onCreateLinkedNotebookRequestReceived( + LinkedNotebook linkedNotebook, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + linkedNotebook, + ctx); + + Q_EMIT createLinkedNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT createLinkedNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateLinkedNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + const LinkedNotebook &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreUpdateLinkedNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void updateLinkedNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onUpdateLinkedNotebookRequestReceived( + LinkedNotebook linkedNotebook, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + linkedNotebook, + ctx); + + Q_EMIT updateLinkedNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT updateLinkedNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListLinkedNotebooksTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QList( + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreListLinkedNotebooksTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void listLinkedNotebooksRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onListLinkedNotebooksRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT listLinkedNotebooksRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT listLinkedNotebooksRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreExpungeLinkedNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + qint32( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreExpungeLinkedNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void expungeLinkedNotebookRequestReady( + qint32 value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onExpungeLinkedNotebookRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT expungeLinkedNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT expungeLinkedNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreAuthenticateToSharedNotebookTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + AuthenticationResult( + QString, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreAuthenticateToSharedNotebookTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void authenticateToSharedNotebookRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onAuthenticateToSharedNotebookRequestReceived( + QString shareKeyOrGlobalId, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + shareKeyOrGlobalId, + ctx); + + Q_EMIT authenticateToSharedNotebookRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT authenticateToSharedNotebookRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetSharedNotebookByAuthTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + SharedNotebook( + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetSharedNotebookByAuthTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getSharedNotebookByAuthRequestReady( + SharedNotebook value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetSharedNotebookByAuthRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT getSharedNotebookByAuthRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getSharedNotebookByAuthRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreEmailNoteTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + void( + const NoteEmailParameters &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreEmailNoteTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void emailNoteRequestReady( + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onEmailNoteRequestReceived( + NoteEmailParameters parameters, + IRequestContextPtr ctx) + { + try + { + m_executor( + parameters, + ctx); + + Q_EMIT emailNoteRequestReady( + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT emailNoteRequestReady( + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreShareNoteTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QString( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreShareNoteTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void shareNoteRequestReady( + QString value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onShareNoteRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + ctx); + + Q_EMIT shareNoteRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT shareNoteRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreStopSharingNoteTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + void( + Guid, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreStopSharingNoteTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void stopSharingNoteRequestReady( + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onStopSharingNoteRequestReceived( + Guid guid, + IRequestContextPtr ctx) + { + try + { + m_executor( + guid, + ctx); + + Q_EMIT stopSharingNoteRequestReady( + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT stopSharingNoteRequestReady( + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreAuthenticateToSharedNoteTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + AuthenticationResult( + QString, + QString, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreAuthenticateToSharedNoteTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void authenticateToSharedNoteRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onAuthenticateToSharedNoteRequestReceived( + QString guid, + QString noteKey, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + guid, + noteKey, + ctx); + + Q_EMIT authenticateToSharedNoteRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT authenticateToSharedNoteRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreFindRelatedTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + RelatedResult( + const RelatedQuery &, + const RelatedResultSpec &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreFindRelatedTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void findRelatedRequestReady( + RelatedResult value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onFindRelatedRequestReceived( + RelatedQuery query, + RelatedResultSpec resultSpec, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + query, + resultSpec, + ctx); + + Q_EMIT findRelatedRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT findRelatedRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateNoteIfUsnMatchesTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + UpdateNoteIfUsnMatchesResult( + const Note &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreUpdateNoteIfUsnMatchesTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void updateNoteIfUsnMatchesRequestReady( + UpdateNoteIfUsnMatchesResult value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onUpdateNoteIfUsnMatchesRequestReceived( + Note note, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + note, + ctx); + + Q_EMIT updateNoteIfUsnMatchesRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT updateNoteIfUsnMatchesRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreManageNotebookSharesTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + ManageNotebookSharesResult( + const ManageNotebookSharesParameters &, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreManageNotebookSharesTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void manageNotebookSharesRequestReady( + ManageNotebookSharesResult value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onManageNotebookSharesRequestReceived( + ManageNotebookSharesParameters parameters, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + parameters, + ctx); + + Q_EMIT manageNotebookSharesRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT manageNotebookSharesRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNotebookSharesTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + ShareRelationships( + QString, + IRequestContextPtr ctx)>; + +public: + explicit NoteStoreGetNotebookSharesTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getNotebookSharesRequestReady( + ShareRelationships value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetNotebookSharesRequestReceived( + QString notebookGuid, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + notebookGuid, + ctx); + + Q_EMIT getNotebookSharesRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getNotebookSharesRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetSyncStateAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetSyncStateAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + SyncState m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetFilteredSyncChunkAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetFilteredSyncChunkAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + SyncChunk m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + SyncState m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + SyncChunk m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListNotebooksAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreListNotebooksAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QList m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast>(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QList m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast>(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Notebook m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetDefaultNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetDefaultNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Notebook m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCreateNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreCreateNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Notebook m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreUpdateNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreExpungeNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreExpungeNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListTagsAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreListTagsAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QList m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast>(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListTagsByNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreListTagsByNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QList m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast>(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetTagAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetTagAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Tag m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCreateTagAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreCreateTagAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Tag m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateTagAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreUpdateTagAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUntagAllAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreUntagAllAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + Q_UNUSED(value) + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreExpungeTagAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreExpungeTagAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListSearchesAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreListSearchesAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QList m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast>(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetSearchAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetSearchAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + SavedSearch m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCreateSearchAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreCreateSearchAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + SavedSearch m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateSearchAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreUpdateSearchAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreExpungeSearchAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreExpungeSearchAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreFindNoteOffsetAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreFindNoteOffsetAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreFindNotesMetadataAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreFindNotesMetadataAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + NotesMetadataList m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreFindNoteCountsAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreFindNoteCountsAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + NoteCollectionCounts m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteWithResultSpecAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetNoteWithResultSpecAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Note m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetNoteAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Note m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteApplicationDataAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetNoteApplicationDataAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + LazyMap m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QString m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteContentAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetNoteContentAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QString m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteSearchTextAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetNoteSearchTextAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QString m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceSearchTextAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetResourceSearchTextAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QString m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteTagNamesAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetNoteTagNamesAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QStringList m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCreateNoteAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreCreateNoteAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Note m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateNoteAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreUpdateNoteAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Note m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreDeleteNoteAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreDeleteNoteAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreExpungeNoteAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreExpungeNoteAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCopyNoteAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreCopyNoteAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Note m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListNoteVersionsAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreListNoteVersionsAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QList m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast>(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNoteVersionAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetNoteVersionAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Note m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetResourceAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Resource m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceApplicationDataAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetResourceApplicationDataAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + LazyMap m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QString m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateResourceAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreUpdateResourceAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceDataAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetResourceDataAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QByteArray m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceByHashAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetResourceByHashAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Resource m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceRecognitionAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetResourceRecognitionAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QByteArray m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceAlternateDataAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetResourceAlternateDataAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QByteArray m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetResourceAttributesAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetResourceAttributesAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + ResourceAttributes m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetPublicNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetPublicNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Notebook m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreShareNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreShareNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + SharedNotebook m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + CreateOrUpdateNotebookSharesResult m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateSharedNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreUpdateSharedNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + Notebook m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListSharedNotebooksAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreListSharedNotebooksAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QList m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast>(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreCreateLinkedNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreCreateLinkedNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + LinkedNotebook m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateLinkedNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreUpdateLinkedNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreListLinkedNotebooksAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreListLinkedNotebooksAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QList m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast>(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreExpungeLinkedNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreExpungeLinkedNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + qint32 m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + AuthenticationResult m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetSharedNotebookByAuthAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetSharedNotebookByAuthAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + SharedNotebook m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreEmailNoteAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreEmailNoteAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + Q_UNUSED(value) + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreShareNoteAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreShareNoteAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QString m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreStopSharingNoteAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreStopSharingNoteAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + Q_UNUSED(value) + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreAuthenticateToSharedNoteAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreAuthenticateToSharedNoteAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + AuthenticationResult m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreFindRelatedAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreFindRelatedAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + RelatedResult m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + UpdateNoteIfUsnMatchesResult m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreManageNotebookSharesAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreManageNotebookSharesAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + ManageNotebookSharesResult m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreGetNotebookSharesAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreGetNotebookSharesAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + ShareRelationships m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetSyncState() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SyncState response = generateRandomSyncState(); + + NoteStoreGetSyncStateTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequest, + &helper, + &NoteStoreGetSyncStateTesterHelper::onGetSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSyncStateTesterHelper::getSyncStateRequestReady, + &server, + &NoteStoreServer::onGetSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + SyncState res = noteStore->getSyncState( + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetSyncState() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_MANY; + userException.parameter = generateRandomString(); + + NoteStoreGetSyncStateTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequest, + &helper, + &NoteStoreGetSyncStateTesterHelper::onGetSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSyncStateTesterHelper::getSyncStateRequestReady, + &server, + &NoteStoreServer::onGetSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncState res = noteStore->getSyncState( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetSyncState() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INTERNAL_ERROR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetSyncStateTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequest, + &helper, + &NoteStoreGetSyncStateTesterHelper::onGetSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSyncStateTesterHelper::getSyncStateRequestReady, + &server, + &NoteStoreServer::onGetSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncState res = noteStore->getSyncState( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetSyncState() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetSyncStateTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequest, + &helper, + &NoteStoreGetSyncStateTesterHelper::onGetSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSyncStateTesterHelper::getSyncStateRequestReady, + &server, + &NoteStoreServer::onGetSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncState res = noteStore->getSyncState( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetSyncStateAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SyncState response = generateRandomSyncState(); + + NoteStoreGetSyncStateTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequest, + &helper, + &NoteStoreGetSyncStateTesterHelper::onGetSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSyncStateTesterHelper::getSyncStateRequestReady, + &server, + &NoteStoreServer::onGetSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getSyncStateAsync( + ctx); + + NoteStoreGetSyncStateAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSyncStateAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSyncStateAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetSyncStateAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DATA_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreGetSyncStateTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequest, + &helper, + &NoteStoreGetSyncStateTesterHelper::onGetSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSyncStateTesterHelper::getSyncStateRequestReady, + &server, + &NoteStoreServer::onGetSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getSyncStateAsync( + ctx); + + NoteStoreGetSyncStateAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSyncStateAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSyncStateAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetSyncStateAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetSyncStateTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequest, + &helper, + &NoteStoreGetSyncStateTesterHelper::onGetSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSyncStateTesterHelper::getSyncStateRequestReady, + &server, + &NoteStoreServer::onGetSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getSyncStateAsync( + ctx); + + NoteStoreGetSyncStateAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSyncStateAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSyncStateAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetSyncStateAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetSyncStateTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequest, + &helper, + &NoteStoreGetSyncStateTesterHelper::onGetSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSyncStateTesterHelper::getSyncStateRequestReady, + &server, + &NoteStoreServer::onGetSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getSyncStateAsync( + ctx); + + NoteStoreGetSyncStateAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSyncStateAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSyncStateAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetFilteredSyncChunk() +{ + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + SyncChunkFilter filter = generateRandomSyncChunkFilter(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SyncChunk response = generateRandomSyncChunk(); + + NoteStoreGetFilteredSyncChunkTesterHelper helper( + [&] (qint32 afterUSNParam, + qint32 maxEntriesParam, + const SyncChunkFilter & filterParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(filter == filterParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequest, + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::onGetFilteredSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::getFilteredSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetFilteredSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + SyncChunk res = noteStore->getFilteredSyncChunk( + afterUSN, + maxEntries, + filter, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetFilteredSyncChunk() +{ + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + SyncChunkFilter filter = generateRandomSyncChunkFilter(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INTERNAL_ERROR; + userException.parameter = generateRandomString(); + + NoteStoreGetFilteredSyncChunkTesterHelper helper( + [&] (qint32 afterUSNParam, + qint32 maxEntriesParam, + const SyncChunkFilter & filterParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(filter == filterParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequest, + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::onGetFilteredSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::getFilteredSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetFilteredSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncChunk res = noteStore->getFilteredSyncChunk( + afterUSN, + maxEntries, + filter, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetFilteredSyncChunk() +{ + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + SyncChunkFilter filter = generateRandomSyncChunkFilter(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LEN_TOO_LONG; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetFilteredSyncChunkTesterHelper helper( + [&] (qint32 afterUSNParam, + qint32 maxEntriesParam, + const SyncChunkFilter & filterParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(filter == filterParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequest, + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::onGetFilteredSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::getFilteredSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetFilteredSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncChunk res = noteStore->getFilteredSyncChunk( + afterUSN, + maxEntries, + filter, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetFilteredSyncChunk() +{ + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + SyncChunkFilter filter = generateRandomSyncChunkFilter(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetFilteredSyncChunkTesterHelper helper( + [&] (qint32 afterUSNParam, + qint32 maxEntriesParam, + const SyncChunkFilter & filterParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(filter == filterParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequest, + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::onGetFilteredSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::getFilteredSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetFilteredSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncChunk res = noteStore->getFilteredSyncChunk( + afterUSN, + maxEntries, + filter, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetFilteredSyncChunkAsync() +{ + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + SyncChunkFilter filter = generateRandomSyncChunkFilter(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SyncChunk response = generateRandomSyncChunk(); + + NoteStoreGetFilteredSyncChunkTesterHelper helper( + [&] (qint32 afterUSNParam, + qint32 maxEntriesParam, + const SyncChunkFilter & filterParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(filter == filterParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequest, + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::onGetFilteredSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::getFilteredSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetFilteredSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getFilteredSyncChunkAsync( + afterUSN, + maxEntries, + filter, + ctx); + + NoteStoreGetFilteredSyncChunkAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetFilteredSyncChunkAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetFilteredSyncChunkAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetFilteredSyncChunkAsync() +{ + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + SyncChunkFilter filter = generateRandomSyncChunkFilter(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + userException.parameter = generateRandomString(); + + NoteStoreGetFilteredSyncChunkTesterHelper helper( + [&] (qint32 afterUSNParam, + qint32 maxEntriesParam, + const SyncChunkFilter & filterParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(filter == filterParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequest, + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::onGetFilteredSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::getFilteredSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetFilteredSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getFilteredSyncChunkAsync( + afterUSN, + maxEntries, + filter, + ctx); + + NoteStoreGetFilteredSyncChunkAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetFilteredSyncChunkAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetFilteredSyncChunkAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetFilteredSyncChunkAsync() +{ + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + SyncChunkFilter filter = generateRandomSyncChunkFilter(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::AUTH_EXPIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetFilteredSyncChunkTesterHelper helper( + [&] (qint32 afterUSNParam, + qint32 maxEntriesParam, + const SyncChunkFilter & filterParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(filter == filterParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequest, + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::onGetFilteredSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::getFilteredSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetFilteredSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getFilteredSyncChunkAsync( + afterUSN, + maxEntries, + filter, + ctx); + + NoteStoreGetFilteredSyncChunkAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetFilteredSyncChunkAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetFilteredSyncChunkAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetFilteredSyncChunkAsync() +{ + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + SyncChunkFilter filter = generateRandomSyncChunkFilter(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetFilteredSyncChunkTesterHelper helper( + [&] (qint32 afterUSNParam, + qint32 maxEntriesParam, + const SyncChunkFilter & filterParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(filter == filterParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequest, + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::onGetFilteredSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetFilteredSyncChunkTesterHelper::getFilteredSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetFilteredSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getFilteredSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getFilteredSyncChunkAsync( + afterUSN, + maxEntries, + filter, + ctx); + + NoteStoreGetFilteredSyncChunkAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetFilteredSyncChunkAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetFilteredSyncChunkAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetLinkedNotebookSyncState() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SyncState response = generateRandomSyncState(); + + NoteStoreGetLinkedNotebookSyncStateTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::onGetLinkedNotebookSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::getLinkedNotebookSyncStateRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + SyncState res = noteStore->getLinkedNotebookSyncState( + linkedNotebook, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetLinkedNotebookSyncState() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + userException.parameter = generateRandomString(); + + NoteStoreGetLinkedNotebookSyncStateTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::onGetLinkedNotebookSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::getLinkedNotebookSyncStateRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncState res = noteStore->getLinkedNotebookSyncState( + linkedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetLinkedNotebookSyncState() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetLinkedNotebookSyncStateTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::onGetLinkedNotebookSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::getLinkedNotebookSyncStateRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncState res = noteStore->getLinkedNotebookSyncState( + linkedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetLinkedNotebookSyncState() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetLinkedNotebookSyncStateTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::onGetLinkedNotebookSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::getLinkedNotebookSyncStateRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncState res = noteStore->getLinkedNotebookSyncState( + linkedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetLinkedNotebookSyncState() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetLinkedNotebookSyncStateTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::onGetLinkedNotebookSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::getLinkedNotebookSyncStateRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncState res = noteStore->getLinkedNotebookSyncState( + linkedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetLinkedNotebookSyncStateAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SyncState response = generateRandomSyncState(); + + NoteStoreGetLinkedNotebookSyncStateTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::onGetLinkedNotebookSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::getLinkedNotebookSyncStateRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getLinkedNotebookSyncStateAsync( + linkedNotebook, + ctx); + + NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetLinkedNotebookSyncStateAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_AUTH; + userException.parameter = generateRandomString(); + + NoteStoreGetLinkedNotebookSyncStateTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::onGetLinkedNotebookSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::getLinkedNotebookSyncStateRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getLinkedNotebookSyncStateAsync( + linkedNotebook, + ctx); + + NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetLinkedNotebookSyncStateAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetLinkedNotebookSyncStateTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::onGetLinkedNotebookSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::getLinkedNotebookSyncStateRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getLinkedNotebookSyncStateAsync( + linkedNotebook, + ctx); + + NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetLinkedNotebookSyncStateAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetLinkedNotebookSyncStateTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::onGetLinkedNotebookSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::getLinkedNotebookSyncStateRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getLinkedNotebookSyncStateAsync( + linkedNotebook, + ctx); + + NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetLinkedNotebookSyncStateAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetLinkedNotebookSyncStateTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> SyncState + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::onGetLinkedNotebookSyncStateRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncStateTesterHelper::getLinkedNotebookSyncStateRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncStateRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncStateRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getLinkedNotebookSyncStateAsync( + linkedNotebook, + ctx); + + NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncStateAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetLinkedNotebookSyncChunk() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + bool fullSyncOnly = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SyncChunk response = generateRandomSyncChunk(); + + NoteStoreGetLinkedNotebookSyncChunkTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + qint32 afterUSNParam, + qint32 maxEntriesParam, + bool fullSyncOnlyParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(fullSyncOnly == fullSyncOnlyParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::onGetLinkedNotebookSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::getLinkedNotebookSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + SyncChunk res = noteStore->getLinkedNotebookSyncChunk( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetLinkedNotebookSyncChunk() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + bool fullSyncOnly = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_ASSOCIATED; + userException.parameter = generateRandomString(); + + NoteStoreGetLinkedNotebookSyncChunkTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + qint32 afterUSNParam, + qint32 maxEntriesParam, + bool fullSyncOnlyParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(fullSyncOnly == fullSyncOnlyParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::onGetLinkedNotebookSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::getLinkedNotebookSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncChunk res = noteStore->getLinkedNotebookSyncChunk( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetLinkedNotebookSyncChunk() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + bool fullSyncOnly = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetLinkedNotebookSyncChunkTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + qint32 afterUSNParam, + qint32 maxEntriesParam, + bool fullSyncOnlyParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(fullSyncOnly == fullSyncOnlyParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::onGetLinkedNotebookSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::getLinkedNotebookSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncChunk res = noteStore->getLinkedNotebookSyncChunk( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetLinkedNotebookSyncChunk() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + bool fullSyncOnly = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetLinkedNotebookSyncChunkTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + qint32 afterUSNParam, + qint32 maxEntriesParam, + bool fullSyncOnlyParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(fullSyncOnly == fullSyncOnlyParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::onGetLinkedNotebookSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::getLinkedNotebookSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncChunk res = noteStore->getLinkedNotebookSyncChunk( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetLinkedNotebookSyncChunk() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + bool fullSyncOnly = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetLinkedNotebookSyncChunkTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + qint32 afterUSNParam, + qint32 maxEntriesParam, + bool fullSyncOnlyParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(fullSyncOnly == fullSyncOnlyParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::onGetLinkedNotebookSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::getLinkedNotebookSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SyncChunk res = noteStore->getLinkedNotebookSyncChunk( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetLinkedNotebookSyncChunkAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + bool fullSyncOnly = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SyncChunk response = generateRandomSyncChunk(); + + NoteStoreGetLinkedNotebookSyncChunkTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + qint32 afterUSNParam, + qint32 maxEntriesParam, + bool fullSyncOnlyParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(fullSyncOnly == fullSyncOnlyParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::onGetLinkedNotebookSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::getLinkedNotebookSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getLinkedNotebookSyncChunkAsync( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + + NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetLinkedNotebookSyncChunkAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + bool fullSyncOnly = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_LONG; + userException.parameter = generateRandomString(); + + NoteStoreGetLinkedNotebookSyncChunkTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + qint32 afterUSNParam, + qint32 maxEntriesParam, + bool fullSyncOnlyParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(fullSyncOnly == fullSyncOnlyParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::onGetLinkedNotebookSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::getLinkedNotebookSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getLinkedNotebookSyncChunkAsync( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + + NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetLinkedNotebookSyncChunkAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + bool fullSyncOnly = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ENML_VALIDATION; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetLinkedNotebookSyncChunkTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + qint32 afterUSNParam, + qint32 maxEntriesParam, + bool fullSyncOnlyParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(fullSyncOnly == fullSyncOnlyParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::onGetLinkedNotebookSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::getLinkedNotebookSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getLinkedNotebookSyncChunkAsync( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + + NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetLinkedNotebookSyncChunkAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + bool fullSyncOnly = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetLinkedNotebookSyncChunkTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + qint32 afterUSNParam, + qint32 maxEntriesParam, + bool fullSyncOnlyParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(fullSyncOnly == fullSyncOnlyParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::onGetLinkedNotebookSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::getLinkedNotebookSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getLinkedNotebookSyncChunkAsync( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + + NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetLinkedNotebookSyncChunkAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + qint32 afterUSN = generateRandomInt32(); + qint32 maxEntries = generateRandomInt32(); + bool fullSyncOnly = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetLinkedNotebookSyncChunkTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + qint32 afterUSNParam, + qint32 maxEntriesParam, + bool fullSyncOnlyParam, + IRequestContextPtr ctxParam) -> SyncChunk + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + Q_ASSERT(afterUSN == afterUSNParam); + Q_ASSERT(maxEntries == maxEntriesParam); + Q_ASSERT(fullSyncOnly == fullSyncOnlyParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequest, + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::onGetLinkedNotebookSyncChunkRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetLinkedNotebookSyncChunkTesterHelper::getLinkedNotebookSyncChunkRequestReady, + &server, + &NoteStoreServer::onGetLinkedNotebookSyncChunkRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getLinkedNotebookSyncChunkRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getLinkedNotebookSyncChunkAsync( + linkedNotebook, + afterUSN, + maxEntries, + fullSyncOnly, + ctx); + + NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetLinkedNotebookSyncChunkAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteListNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomNotebook(); + response << generateRandomNotebook(); + response << generateRandomNotebook(); + + NoteStoreListNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequest, + &helper, + &NoteStoreListNotebooksTesterHelper::onListNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNotebooksTesterHelper::listNotebooksRequestReady, + &server, + &NoteStoreServer::onListNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QList res = noteStore->listNotebooks( + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + userException.parameter = generateRandomString(); + + NoteStoreListNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequest, + &helper, + &NoteStoreListNotebooksTesterHelper::onListNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNotebooksTesterHelper::listNotebooksRequestReady, + &server, + &NoteStoreServer::onListNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::SHARD_UNAVAILABLE; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequest, + &helper, + &NoteStoreListNotebooksTesterHelper::onListNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNotebooksTesterHelper::listNotebooksRequestReady, + &server, + &NoteStoreServer::onListNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequest, + &helper, + &NoteStoreListNotebooksTesterHelper::onListNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNotebooksTesterHelper::listNotebooksRequestReady, + &server, + &NoteStoreServer::onListNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteListNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomNotebook(); + response << generateRandomNotebook(); + response << generateRandomNotebook(); + + NoteStoreListNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequest, + &helper, + &NoteStoreListNotebooksTesterHelper::onListNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNotebooksTesterHelper::listNotebooksRequestReady, + &server, + &NoteStoreServer::onListNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->listNotebooksAsync( + ctx); + + NoteStoreListNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_MANY; + userException.parameter = generateRandomString(); + + NoteStoreListNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequest, + &helper, + &NoteStoreListNotebooksTesterHelper::onListNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNotebooksTesterHelper::listNotebooksRequestReady, + &server, + &NoteStoreServer::onListNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listNotebooksAsync( + ctx); + + NoteStoreListNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_AUTH; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequest, + &helper, + &NoteStoreListNotebooksTesterHelper::onListNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNotebooksTesterHelper::listNotebooksRequestReady, + &server, + &NoteStoreServer::onListNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listNotebooksAsync( + ctx); + + NoteStoreListNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequest, + &helper, + &NoteStoreListNotebooksTesterHelper::onListNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNotebooksTesterHelper::listNotebooksRequestReady, + &server, + &NoteStoreServer::onListNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listNotebooksAsync( + ctx); + + NoteStoreListNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteListAccessibleBusinessNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomNotebook(); + response << generateRandomNotebook(); + response << generateRandomNotebook(); + + NoteStoreListAccessibleBusinessNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequest, + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::onListAccessibleBusinessNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::listAccessibleBusinessNotebooksRequestReady, + &server, + &NoteStoreServer::onListAccessibleBusinessNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QList res = noteStore->listAccessibleBusinessNotebooks( + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListAccessibleBusinessNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DATA_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreListAccessibleBusinessNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequest, + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::onListAccessibleBusinessNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::listAccessibleBusinessNotebooksRequestReady, + &server, + &NoteStoreServer::onListAccessibleBusinessNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listAccessibleBusinessNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListAccessibleBusinessNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListAccessibleBusinessNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequest, + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::onListAccessibleBusinessNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::listAccessibleBusinessNotebooksRequestReady, + &server, + &NoteStoreServer::onListAccessibleBusinessNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listAccessibleBusinessNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListAccessibleBusinessNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListAccessibleBusinessNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequest, + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::onListAccessibleBusinessNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::listAccessibleBusinessNotebooksRequestReady, + &server, + &NoteStoreServer::onListAccessibleBusinessNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listAccessibleBusinessNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteListAccessibleBusinessNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomNotebook(); + response << generateRandomNotebook(); + response << generateRandomNotebook(); + + NoteStoreListAccessibleBusinessNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequest, + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::onListAccessibleBusinessNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::listAccessibleBusinessNotebooksRequestReady, + &server, + &NoteStoreServer::onListAccessibleBusinessNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->listAccessibleBusinessNotebooksAsync( + ctx); + + NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListAccessibleBusinessNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreListAccessibleBusinessNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequest, + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::onListAccessibleBusinessNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::listAccessibleBusinessNotebooksRequestReady, + &server, + &NoteStoreServer::onListAccessibleBusinessNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listAccessibleBusinessNotebooksAsync( + ctx); + + NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListAccessibleBusinessNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::OPENID_ALREADY_TAKEN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListAccessibleBusinessNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequest, + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::onListAccessibleBusinessNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::listAccessibleBusinessNotebooksRequestReady, + &server, + &NoteStoreServer::onListAccessibleBusinessNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listAccessibleBusinessNotebooksAsync( + ctx); + + NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListAccessibleBusinessNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListAccessibleBusinessNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequest, + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::onListAccessibleBusinessNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListAccessibleBusinessNotebooksTesterHelper::listAccessibleBusinessNotebooksRequestReady, + &server, + &NoteStoreServer::onListAccessibleBusinessNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listAccessibleBusinessNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listAccessibleBusinessNotebooksAsync( + ctx); + + NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListAccessibleBusinessNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Notebook response = generateRandomNotebook(); + + NoteStoreGetNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequest, + &helper, + &NoteStoreGetNotebookTesterHelper::onGetNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookTesterHelper::getNotebookRequestReady, + &server, + &NoteStoreServer::onGetNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Notebook res = noteStore->getNotebook( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INTERNAL_ERROR; + userException.parameter = generateRandomString(); + + NoteStoreGetNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequest, + &helper, + &NoteStoreGetNotebookTesterHelper::onGetNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookTesterHelper::getNotebookRequestReady, + &server, + &NoteStoreServer::onGetNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->getNotebook( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TAKEN_DOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequest, + &helper, + &NoteStoreGetNotebookTesterHelper::onGetNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookTesterHelper::getNotebookRequestReady, + &server, + &NoteStoreServer::onGetNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->getNotebook( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequest, + &helper, + &NoteStoreGetNotebookTesterHelper::onGetNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookTesterHelper::getNotebookRequestReady, + &server, + &NoteStoreServer::onGetNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->getNotebook( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequest, + &helper, + &NoteStoreGetNotebookTesterHelper::onGetNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookTesterHelper::getNotebookRequestReady, + &server, + &NoteStoreServer::onGetNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->getNotebook( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Notebook response = generateRandomNotebook(); + + NoteStoreGetNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequest, + &helper, + &NoteStoreGetNotebookTesterHelper::onGetNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookTesterHelper::getNotebookRequestReady, + &server, + &NoteStoreServer::onGetNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getNotebookAsync( + guid, + ctx); + + NoteStoreGetNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_SHORT; + userException.parameter = generateRandomString(); + + NoteStoreGetNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequest, + &helper, + &NoteStoreGetNotebookTesterHelper::onGetNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookTesterHelper::getNotebookRequestReady, + &server, + &NoteStoreServer::onGetNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNotebookAsync( + guid, + ctx); + + NoteStoreGetNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::AUTH_EXPIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequest, + &helper, + &NoteStoreGetNotebookTesterHelper::onGetNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookTesterHelper::getNotebookRequestReady, + &server, + &NoteStoreServer::onGetNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNotebookAsync( + guid, + ctx); + + NoteStoreGetNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequest, + &helper, + &NoteStoreGetNotebookTesterHelper::onGetNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookTesterHelper::getNotebookRequestReady, + &server, + &NoteStoreServer::onGetNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNotebookAsync( + guid, + ctx); + + NoteStoreGetNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequest, + &helper, + &NoteStoreGetNotebookTesterHelper::onGetNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookTesterHelper::getNotebookRequestReady, + &server, + &NoteStoreServer::onGetNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNotebookAsync( + guid, + ctx); + + NoteStoreGetNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetDefaultNotebook() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Notebook response = generateRandomNotebook(); + + NoteStoreGetDefaultNotebookTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequest, + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::onGetDefaultNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::getDefaultNotebookRequestReady, + &server, + &NoteStoreServer::onGetDefaultNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Notebook res = noteStore->getDefaultNotebook( + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetDefaultNotebook() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreGetDefaultNotebookTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequest, + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::onGetDefaultNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::getDefaultNotebookRequestReady, + &server, + &NoteStoreServer::onGetDefaultNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->getDefaultNotebook( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetDefaultNotebook() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::RATE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetDefaultNotebookTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequest, + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::onGetDefaultNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::getDefaultNotebookRequestReady, + &server, + &NoteStoreServer::onGetDefaultNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->getDefaultNotebook( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetDefaultNotebook() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetDefaultNotebookTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequest, + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::onGetDefaultNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::getDefaultNotebookRequestReady, + &server, + &NoteStoreServer::onGetDefaultNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->getDefaultNotebook( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetDefaultNotebookAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Notebook response = generateRandomNotebook(); + + NoteStoreGetDefaultNotebookTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequest, + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::onGetDefaultNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::getDefaultNotebookRequestReady, + &server, + &NoteStoreServer::onGetDefaultNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getDefaultNotebookAsync( + ctx); + + NoteStoreGetDefaultNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetDefaultNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetDefaultNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetDefaultNotebookAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreGetDefaultNotebookTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequest, + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::onGetDefaultNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::getDefaultNotebookRequestReady, + &server, + &NoteStoreServer::onGetDefaultNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getDefaultNotebookAsync( + ctx); + + NoteStoreGetDefaultNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetDefaultNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetDefaultNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetDefaultNotebookAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::QUOTA_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetDefaultNotebookTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequest, + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::onGetDefaultNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::getDefaultNotebookRequestReady, + &server, + &NoteStoreServer::onGetDefaultNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getDefaultNotebookAsync( + ctx); + + NoteStoreGetDefaultNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetDefaultNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetDefaultNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetDefaultNotebookAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetDefaultNotebookTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequest, + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::onGetDefaultNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetDefaultNotebookTesterHelper::getDefaultNotebookRequestReady, + &server, + &NoteStoreServer::onGetDefaultNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getDefaultNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getDefaultNotebookAsync( + ctx); + + NoteStoreGetDefaultNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetDefaultNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetDefaultNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteCreateNotebook() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Notebook response = generateRandomNotebook(); + + NoteStoreCreateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequest, + &helper, + &NoteStoreCreateNotebookTesterHelper::onCreateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNotebookTesterHelper::createNotebookRequestReady, + &server, + &NoteStoreServer::onCreateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Notebook res = noteStore->createNotebook( + notebook, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCreateNotebook() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + userException.parameter = generateRandomString(); + + NoteStoreCreateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequest, + &helper, + &NoteStoreCreateNotebookTesterHelper::onCreateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNotebookTesterHelper::createNotebookRequestReady, + &server, + &NoteStoreServer::onCreateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->createNotebook( + notebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCreateNotebook() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCreateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequest, + &helper, + &NoteStoreCreateNotebookTesterHelper::onCreateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNotebookTesterHelper::createNotebookRequestReady, + &server, + &NoteStoreServer::onCreateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->createNotebook( + notebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInCreateNotebook() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreCreateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequest, + &helper, + &NoteStoreCreateNotebookTesterHelper::onCreateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNotebookTesterHelper::createNotebookRequestReady, + &server, + &NoteStoreServer::onCreateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->createNotebook( + notebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCreateNotebook() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCreateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequest, + &helper, + &NoteStoreCreateNotebookTesterHelper::onCreateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNotebookTesterHelper::createNotebookRequestReady, + &server, + &NoteStoreServer::onCreateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->createNotebook( + notebook, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteCreateNotebookAsync() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Notebook response = generateRandomNotebook(); + + NoteStoreCreateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequest, + &helper, + &NoteStoreCreateNotebookTesterHelper::onCreateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNotebookTesterHelper::createNotebookRequestReady, + &server, + &NoteStoreServer::onCreateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->createNotebookAsync( + notebook, + ctx); + + NoteStoreCreateNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCreateNotebookAsync() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_MANY; + userException.parameter = generateRandomString(); + + NoteStoreCreateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequest, + &helper, + &NoteStoreCreateNotebookTesterHelper::onCreateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNotebookTesterHelper::createNotebookRequestReady, + &server, + &NoteStoreServer::onCreateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createNotebookAsync( + notebook, + ctx); + + NoteStoreCreateNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCreateNotebookAsync() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DATA_CONFLICT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCreateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequest, + &helper, + &NoteStoreCreateNotebookTesterHelper::onCreateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNotebookTesterHelper::createNotebookRequestReady, + &server, + &NoteStoreServer::onCreateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createNotebookAsync( + notebook, + ctx); + + NoteStoreCreateNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInCreateNotebookAsync() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreCreateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequest, + &helper, + &NoteStoreCreateNotebookTesterHelper::onCreateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNotebookTesterHelper::createNotebookRequestReady, + &server, + &NoteStoreServer::onCreateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createNotebookAsync( + notebook, + ctx); + + NoteStoreCreateNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCreateNotebookAsync() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCreateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequest, + &helper, + &NoteStoreCreateNotebookTesterHelper::onCreateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNotebookTesterHelper::createNotebookRequestReady, + &server, + &NoteStoreServer::onCreateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createNotebookAsync( + notebook, + ctx); + + NoteStoreCreateNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteUpdateNotebook() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUpdateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequest, + &helper, + &NoteStoreUpdateNotebookTesterHelper::onUpdateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNotebookTesterHelper::updateNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->updateNotebook( + notebook, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateNotebook() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ENML_VALIDATION; + userException.parameter = generateRandomString(); + + NoteStoreUpdateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequest, + &helper, + &NoteStoreUpdateNotebookTesterHelper::onUpdateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNotebookTesterHelper::updateNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateNotebook( + notebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateNotebook() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequest, + &helper, + &NoteStoreUpdateNotebookTesterHelper::onUpdateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNotebookTesterHelper::updateNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateNotebook( + notebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateNotebook() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequest, + &helper, + &NoteStoreUpdateNotebookTesterHelper::onUpdateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNotebookTesterHelper::updateNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateNotebook( + notebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateNotebook() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequest, + &helper, + &NoteStoreUpdateNotebookTesterHelper::onUpdateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNotebookTesterHelper::updateNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateNotebook( + notebook, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteUpdateNotebookAsync() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUpdateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequest, + &helper, + &NoteStoreUpdateNotebookTesterHelper::onUpdateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNotebookTesterHelper::updateNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->updateNotebookAsync( + notebook, + ctx); + + NoteStoreUpdateNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateNotebookAsync() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TAKEN_DOWN; + userException.parameter = generateRandomString(); + + NoteStoreUpdateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequest, + &helper, + &NoteStoreUpdateNotebookTesterHelper::onUpdateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNotebookTesterHelper::updateNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateNotebookAsync( + notebook, + ctx); + + NoteStoreUpdateNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateNotebookAsync() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_NOT_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequest, + &helper, + &NoteStoreUpdateNotebookTesterHelper::onUpdateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNotebookTesterHelper::updateNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateNotebookAsync( + notebook, + ctx); + + NoteStoreUpdateNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateNotebookAsync() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequest, + &helper, + &NoteStoreUpdateNotebookTesterHelper::onUpdateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNotebookTesterHelper::updateNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateNotebookAsync( + notebook, + ctx); + + NoteStoreUpdateNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateNotebookAsync() +{ + Notebook notebook = generateRandomNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateNotebookTesterHelper helper( + [&] (const Notebook & notebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebook == notebookParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequest, + &helper, + &NoteStoreUpdateNotebookTesterHelper::onUpdateNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNotebookTesterHelper::updateNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateNotebookAsync( + notebook, + ctx); + + NoteStoreUpdateNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteExpungeNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreExpungeNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequest, + &helper, + &NoteStoreExpungeNotebookTesterHelper::onExpungeNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNotebookTesterHelper::expungeNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->expungeNotebook( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInExpungeNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_AUTH; + userException.parameter = generateRandomString(); + + NoteStoreExpungeNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequest, + &helper, + &NoteStoreExpungeNotebookTesterHelper::onExpungeNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNotebookTesterHelper::expungeNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeNotebook( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInExpungeNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::AUTH_EXPIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreExpungeNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequest, + &helper, + &NoteStoreExpungeNotebookTesterHelper::onExpungeNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNotebookTesterHelper::expungeNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeNotebook( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInExpungeNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreExpungeNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequest, + &helper, + &NoteStoreExpungeNotebookTesterHelper::onExpungeNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNotebookTesterHelper::expungeNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeNotebook( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInExpungeNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreExpungeNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequest, + &helper, + &NoteStoreExpungeNotebookTesterHelper::onExpungeNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNotebookTesterHelper::expungeNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeNotebook( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteExpungeNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreExpungeNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequest, + &helper, + &NoteStoreExpungeNotebookTesterHelper::onExpungeNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNotebookTesterHelper::expungeNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->expungeNotebookAsync( + guid, + ctx); + + NoteStoreExpungeNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInExpungeNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + userException.parameter = generateRandomString(); + + NoteStoreExpungeNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequest, + &helper, + &NoteStoreExpungeNotebookTesterHelper::onExpungeNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNotebookTesterHelper::expungeNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeNotebookAsync( + guid, + ctx); + + NoteStoreExpungeNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInExpungeNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreExpungeNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequest, + &helper, + &NoteStoreExpungeNotebookTesterHelper::onExpungeNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNotebookTesterHelper::expungeNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeNotebookAsync( + guid, + ctx); + + NoteStoreExpungeNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInExpungeNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreExpungeNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequest, + &helper, + &NoteStoreExpungeNotebookTesterHelper::onExpungeNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNotebookTesterHelper::expungeNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeNotebookAsync( + guid, + ctx); + + NoteStoreExpungeNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInExpungeNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreExpungeNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequest, + &helper, + &NoteStoreExpungeNotebookTesterHelper::onExpungeNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNotebookTesterHelper::expungeNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeNotebookAsync( + guid, + ctx); + + NoteStoreExpungeNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteListTags() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomTag(); + response << generateRandomTag(); + response << generateRandomTag(); + + NoteStoreListTagsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsRequest, + &helper, + &NoteStoreListTagsTesterHelper::onListTagsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsTesterHelper::listTagsRequestReady, + &server, + &NoteStoreServer::onListTagsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QList res = noteStore->listTags( + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListTags() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_AUTH; + userException.parameter = generateRandomString(); + + NoteStoreListTagsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsRequest, + &helper, + &NoteStoreListTagsTesterHelper::onListTagsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsTesterHelper::listTagsRequestReady, + &server, + &NoteStoreServer::onListTagsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listTags( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListTags() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TOO_MANY; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListTagsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsRequest, + &helper, + &NoteStoreListTagsTesterHelper::onListTagsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsTesterHelper::listTagsRequestReady, + &server, + &NoteStoreServer::onListTagsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listTags( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListTags() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListTagsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsRequest, + &helper, + &NoteStoreListTagsTesterHelper::onListTagsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsTesterHelper::listTagsRequestReady, + &server, + &NoteStoreServer::onListTagsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listTags( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteListTagsAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomTag(); + response << generateRandomTag(); + response << generateRandomTag(); + + NoteStoreListTagsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsRequest, + &helper, + &NoteStoreListTagsTesterHelper::onListTagsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsTesterHelper::listTagsRequestReady, + &server, + &NoteStoreServer::onListTagsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->listTagsAsync( + ctx); + + NoteStoreListTagsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListTagsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListTagsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListTagsAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_LONG; + userException.parameter = generateRandomString(); + + NoteStoreListTagsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsRequest, + &helper, + &NoteStoreListTagsTesterHelper::onListTagsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsTesterHelper::listTagsRequestReady, + &server, + &NoteStoreServer::onListTagsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listTagsAsync( + ctx); + + NoteStoreListTagsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListTagsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListTagsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListTagsAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListTagsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsRequest, + &helper, + &NoteStoreListTagsTesterHelper::onListTagsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsTesterHelper::listTagsRequestReady, + &server, + &NoteStoreServer::onListTagsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listTagsAsync( + ctx); + + NoteStoreListTagsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListTagsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListTagsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListTagsAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListTagsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsRequest, + &helper, + &NoteStoreListTagsTesterHelper::onListTagsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsTesterHelper::listTagsRequestReady, + &server, + &NoteStoreServer::onListTagsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listTagsAsync( + ctx); + + NoteStoreListTagsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListTagsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListTagsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteListTagsByNotebook() +{ + Guid notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomTag(); + response << generateRandomTag(); + response << generateRandomTag(); + + NoteStoreListTagsByNotebookTesterHelper helper( + [&] (const Guid & notebookGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequest, + &helper, + &NoteStoreListTagsByNotebookTesterHelper::onListTagsByNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsByNotebookTesterHelper::listTagsByNotebookRequestReady, + &server, + &NoteStoreServer::onListTagsByNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QList res = noteStore->listTagsByNotebook( + notebookGuid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListTagsByNotebook() +{ + Guid notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + userException.parameter = generateRandomString(); + + NoteStoreListTagsByNotebookTesterHelper helper( + [&] (const Guid & notebookGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequest, + &helper, + &NoteStoreListTagsByNotebookTesterHelper::onListTagsByNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsByNotebookTesterHelper::listTagsByNotebookRequestReady, + &server, + &NoteStoreServer::onListTagsByNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listTagsByNotebook( + notebookGuid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListTagsByNotebook() +{ + Guid notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LEN_TOO_SHORT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListTagsByNotebookTesterHelper helper( + [&] (const Guid & notebookGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequest, + &helper, + &NoteStoreListTagsByNotebookTesterHelper::onListTagsByNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsByNotebookTesterHelper::listTagsByNotebookRequestReady, + &server, + &NoteStoreServer::onListTagsByNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listTagsByNotebook( + notebookGuid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInListTagsByNotebook() +{ + Guid notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreListTagsByNotebookTesterHelper helper( + [&] (const Guid & notebookGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequest, + &helper, + &NoteStoreListTagsByNotebookTesterHelper::onListTagsByNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsByNotebookTesterHelper::listTagsByNotebookRequestReady, + &server, + &NoteStoreServer::onListTagsByNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listTagsByNotebook( + notebookGuid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListTagsByNotebook() +{ + Guid notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListTagsByNotebookTesterHelper helper( + [&] (const Guid & notebookGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequest, + &helper, + &NoteStoreListTagsByNotebookTesterHelper::onListTagsByNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsByNotebookTesterHelper::listTagsByNotebookRequestReady, + &server, + &NoteStoreServer::onListTagsByNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listTagsByNotebook( + notebookGuid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteListTagsByNotebookAsync() +{ + Guid notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomTag(); + response << generateRandomTag(); + response << generateRandomTag(); + + NoteStoreListTagsByNotebookTesterHelper helper( + [&] (const Guid & notebookGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequest, + &helper, + &NoteStoreListTagsByNotebookTesterHelper::onListTagsByNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsByNotebookTesterHelper::listTagsByNotebookRequestReady, + &server, + &NoteStoreServer::onListTagsByNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->listTagsByNotebookAsync( + notebookGuid, + ctx); + + NoteStoreListTagsByNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListTagsByNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListTagsByNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListTagsByNotebookAsync() +{ + Guid notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_REGISTERED; + userException.parameter = generateRandomString(); + + NoteStoreListTagsByNotebookTesterHelper helper( + [&] (const Guid & notebookGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequest, + &helper, + &NoteStoreListTagsByNotebookTesterHelper::onListTagsByNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsByNotebookTesterHelper::listTagsByNotebookRequestReady, + &server, + &NoteStoreServer::onListTagsByNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listTagsByNotebookAsync( + notebookGuid, + ctx); + + NoteStoreListTagsByNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListTagsByNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListTagsByNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListTagsByNotebookAsync() +{ + Guid notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TOO_FEW; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListTagsByNotebookTesterHelper helper( + [&] (const Guid & notebookGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequest, + &helper, + &NoteStoreListTagsByNotebookTesterHelper::onListTagsByNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsByNotebookTesterHelper::listTagsByNotebookRequestReady, + &server, + &NoteStoreServer::onListTagsByNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listTagsByNotebookAsync( + notebookGuid, + ctx); + + NoteStoreListTagsByNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListTagsByNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListTagsByNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInListTagsByNotebookAsync() +{ + Guid notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreListTagsByNotebookTesterHelper helper( + [&] (const Guid & notebookGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequest, + &helper, + &NoteStoreListTagsByNotebookTesterHelper::onListTagsByNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsByNotebookTesterHelper::listTagsByNotebookRequestReady, + &server, + &NoteStoreServer::onListTagsByNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listTagsByNotebookAsync( + notebookGuid, + ctx); + + NoteStoreListTagsByNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListTagsByNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListTagsByNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListTagsByNotebookAsync() +{ + Guid notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListTagsByNotebookTesterHelper helper( + [&] (const Guid & notebookGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequest, + &helper, + &NoteStoreListTagsByNotebookTesterHelper::onListTagsByNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreListTagsByNotebookTesterHelper::listTagsByNotebookRequestReady, + &server, + &NoteStoreServer::onListTagsByNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listTagsByNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listTagsByNotebookAsync( + notebookGuid, + ctx); + + NoteStoreListTagsByNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListTagsByNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListTagsByNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetTag() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Tag response = generateRandomTag(); + + NoteStoreGetTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getTagRequest, + &helper, + &NoteStoreGetTagTesterHelper::onGetTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetTagTesterHelper::getTagRequestReady, + &server, + &NoteStoreServer::onGetTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Tag res = noteStore->getTag( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetTag() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + userException.parameter = generateRandomString(); + + NoteStoreGetTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getTagRequest, + &helper, + &NoteStoreGetTagTesterHelper::onGetTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetTagTesterHelper::getTagRequestReady, + &server, + &NoteStoreServer::onGetTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Tag res = noteStore->getTag( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetTag() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_AUTH; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getTagRequest, + &helper, + &NoteStoreGetTagTesterHelper::onGetTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetTagTesterHelper::getTagRequestReady, + &server, + &NoteStoreServer::onGetTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Tag res = noteStore->getTag( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetTag() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getTagRequest, + &helper, + &NoteStoreGetTagTesterHelper::onGetTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetTagTesterHelper::getTagRequestReady, + &server, + &NoteStoreServer::onGetTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Tag res = noteStore->getTag( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetTag() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getTagRequest, + &helper, + &NoteStoreGetTagTesterHelper::onGetTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetTagTesterHelper::getTagRequestReady, + &server, + &NoteStoreServer::onGetTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Tag res = noteStore->getTag( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetTagAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Tag response = generateRandomTag(); + + NoteStoreGetTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getTagRequest, + &helper, + &NoteStoreGetTagTesterHelper::onGetTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetTagTesterHelper::getTagRequestReady, + &server, + &NoteStoreServer::onGetTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getTagAsync( + guid, + ctx); + + NoteStoreGetTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetTagAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_AUTH; + userException.parameter = generateRandomString(); + + NoteStoreGetTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getTagRequest, + &helper, + &NoteStoreGetTagTesterHelper::onGetTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetTagTesterHelper::getTagRequestReady, + &server, + &NoteStoreServer::onGetTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getTagAsync( + guid, + ctx); + + NoteStoreGetTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetTagAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DATA_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getTagRequest, + &helper, + &NoteStoreGetTagTesterHelper::onGetTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetTagTesterHelper::getTagRequestReady, + &server, + &NoteStoreServer::onGetTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getTagAsync( + guid, + ctx); + + NoteStoreGetTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetTagAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getTagRequest, + &helper, + &NoteStoreGetTagTesterHelper::onGetTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetTagTesterHelper::getTagRequestReady, + &server, + &NoteStoreServer::onGetTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getTagAsync( + guid, + ctx); + + NoteStoreGetTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetTagAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getTagRequest, + &helper, + &NoteStoreGetTagTesterHelper::onGetTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetTagTesterHelper::getTagRequestReady, + &server, + &NoteStoreServer::onGetTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getTagAsync( + guid, + ctx); + + NoteStoreGetTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteCreateTag() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Tag response = generateRandomTag(); + + NoteStoreCreateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createTagRequest, + &helper, + &NoteStoreCreateTagTesterHelper::onCreateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateTagTesterHelper::createTagRequestReady, + &server, + &NoteStoreServer::onCreateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Tag res = noteStore->createTag( + tag, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCreateTag() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_REGISTERED; + userException.parameter = generateRandomString(); + + NoteStoreCreateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createTagRequest, + &helper, + &NoteStoreCreateTagTesterHelper::onCreateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateTagTesterHelper::createTagRequestReady, + &server, + &NoteStoreServer::onCreateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Tag res = noteStore->createTag( + tag, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCreateTag() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DATA_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCreateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createTagRequest, + &helper, + &NoteStoreCreateTagTesterHelper::onCreateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateTagTesterHelper::createTagRequestReady, + &server, + &NoteStoreServer::onCreateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Tag res = noteStore->createTag( + tag, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInCreateTag() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreCreateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createTagRequest, + &helper, + &NoteStoreCreateTagTesterHelper::onCreateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateTagTesterHelper::createTagRequestReady, + &server, + &NoteStoreServer::onCreateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Tag res = noteStore->createTag( + tag, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCreateTag() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCreateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createTagRequest, + &helper, + &NoteStoreCreateTagTesterHelper::onCreateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateTagTesterHelper::createTagRequestReady, + &server, + &NoteStoreServer::onCreateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Tag res = noteStore->createTag( + tag, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteCreateTagAsync() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Tag response = generateRandomTag(); + + NoteStoreCreateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createTagRequest, + &helper, + &NoteStoreCreateTagTesterHelper::onCreateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateTagTesterHelper::createTagRequestReady, + &server, + &NoteStoreServer::onCreateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->createTagAsync( + tag, + ctx); + + NoteStoreCreateTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCreateTagAsync() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_REGISTERED; + userException.parameter = generateRandomString(); + + NoteStoreCreateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createTagRequest, + &helper, + &NoteStoreCreateTagTesterHelper::onCreateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateTagTesterHelper::createTagRequestReady, + &server, + &NoteStoreServer::onCreateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createTagAsync( + tag, + ctx); + + NoteStoreCreateTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCreateTagAsync() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCreateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createTagRequest, + &helper, + &NoteStoreCreateTagTesterHelper::onCreateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateTagTesterHelper::createTagRequestReady, + &server, + &NoteStoreServer::onCreateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createTagAsync( + tag, + ctx); + + NoteStoreCreateTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInCreateTagAsync() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreCreateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createTagRequest, + &helper, + &NoteStoreCreateTagTesterHelper::onCreateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateTagTesterHelper::createTagRequestReady, + &server, + &NoteStoreServer::onCreateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createTagAsync( + tag, + ctx); + + NoteStoreCreateTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCreateTagAsync() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCreateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> Tag + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createTagRequest, + &helper, + &NoteStoreCreateTagTesterHelper::onCreateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateTagTesterHelper::createTagRequestReady, + &server, + &NoteStoreServer::onCreateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createTagAsync( + tag, + ctx); + + NoteStoreCreateTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteUpdateTag() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUpdateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateTagRequest, + &helper, + &NoteStoreUpdateTagTesterHelper::onUpdateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateTagTesterHelper::updateTagRequestReady, + &server, + &NoteStoreServer::onUpdateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->updateTag( + tag, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateTag() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::QUOTA_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreUpdateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateTagRequest, + &helper, + &NoteStoreUpdateTagTesterHelper::onUpdateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateTagTesterHelper::updateTagRequestReady, + &server, + &NoteStoreServer::onUpdateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateTag( + tag, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateTag() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TAKEN_DOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateTagRequest, + &helper, + &NoteStoreUpdateTagTesterHelper::onUpdateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateTagTesterHelper::updateTagRequestReady, + &server, + &NoteStoreServer::onUpdateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateTag( + tag, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateTag() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateTagRequest, + &helper, + &NoteStoreUpdateTagTesterHelper::onUpdateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateTagTesterHelper::updateTagRequestReady, + &server, + &NoteStoreServer::onUpdateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateTag( + tag, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateTag() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateTagRequest, + &helper, + &NoteStoreUpdateTagTesterHelper::onUpdateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateTagTesterHelper::updateTagRequestReady, + &server, + &NoteStoreServer::onUpdateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateTag( + tag, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteUpdateTagAsync() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUpdateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateTagRequest, + &helper, + &NoteStoreUpdateTagTesterHelper::onUpdateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateTagTesterHelper::updateTagRequestReady, + &server, + &NoteStoreServer::onUpdateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->updateTagAsync( + tag, + ctx); + + NoteStoreUpdateTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateTagAsync() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::QUOTA_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreUpdateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateTagRequest, + &helper, + &NoteStoreUpdateTagTesterHelper::onUpdateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateTagTesterHelper::updateTagRequestReady, + &server, + &NoteStoreServer::onUpdateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateTagAsync( + tag, + ctx); + + NoteStoreUpdateTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateTagAsync() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::UNKNOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateTagRequest, + &helper, + &NoteStoreUpdateTagTesterHelper::onUpdateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateTagTesterHelper::updateTagRequestReady, + &server, + &NoteStoreServer::onUpdateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateTagAsync( + tag, + ctx); + + NoteStoreUpdateTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateTagAsync() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateTagRequest, + &helper, + &NoteStoreUpdateTagTesterHelper::onUpdateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateTagTesterHelper::updateTagRequestReady, + &server, + &NoteStoreServer::onUpdateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateTagAsync( + tag, + ctx); + + NoteStoreUpdateTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateTagAsync() +{ + Tag tag = generateRandomTag(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateTagTesterHelper helper( + [&] (const Tag & tagParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(tag == tagParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateTagRequest, + &helper, + &NoteStoreUpdateTagTesterHelper::onUpdateTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateTagTesterHelper::updateTagRequestReady, + &server, + &NoteStoreServer::onUpdateTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateTagAsync( + tag, + ctx); + + NoteStoreUpdateTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteUntagAll() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + NoteStoreUntagAllTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::untagAllRequest, + &helper, + &NoteStoreUntagAllTesterHelper::onUntagAllRequestReceived); + QObject::connect( + &helper, + &NoteStoreUntagAllTesterHelper::untagAllRequestReady, + &server, + &NoteStoreServer::onUntagAllRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::untagAllRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + noteStore->untagAll( + guid, + ctx); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUntagAll() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_FEW; + userException.parameter = generateRandomString(); + + NoteStoreUntagAllTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::untagAllRequest, + &helper, + &NoteStoreUntagAllTesterHelper::onUntagAllRequestReceived); + QObject::connect( + &helper, + &NoteStoreUntagAllTesterHelper::untagAllRequestReady, + &server, + &NoteStoreServer::onUntagAllRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::untagAllRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + noteStore->untagAll( + guid, + ctx); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUntagAll() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUntagAllTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::untagAllRequest, + &helper, + &NoteStoreUntagAllTesterHelper::onUntagAllRequestReceived); + QObject::connect( + &helper, + &NoteStoreUntagAllTesterHelper::untagAllRequestReady, + &server, + &NoteStoreServer::onUntagAllRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::untagAllRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + noteStore->untagAll( + guid, + ctx); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUntagAll() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUntagAllTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::untagAllRequest, + &helper, + &NoteStoreUntagAllTesterHelper::onUntagAllRequestReceived); + QObject::connect( + &helper, + &NoteStoreUntagAllTesterHelper::untagAllRequestReady, + &server, + &NoteStoreServer::onUntagAllRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::untagAllRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + noteStore->untagAll( + guid, + ctx); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUntagAll() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUntagAllTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::untagAllRequest, + &helper, + &NoteStoreUntagAllTesterHelper::onUntagAllRequestReceived); + QObject::connect( + &helper, + &NoteStoreUntagAllTesterHelper::untagAllRequestReady, + &server, + &NoteStoreServer::onUntagAllRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::untagAllRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + noteStore->untagAll( + guid, + ctx); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteUntagAllAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + NoteStoreUntagAllTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::untagAllRequest, + &helper, + &NoteStoreUntagAllTesterHelper::onUntagAllRequestReceived); + QObject::connect( + &helper, + &NoteStoreUntagAllTesterHelper::untagAllRequestReady, + &server, + &NoteStoreServer::onUntagAllRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::untagAllRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->untagAllAsync( + guid, + ctx); + + NoteStoreUntagAllAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUntagAllAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUntagAllAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUntagAllAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + userException.parameter = generateRandomString(); + + NoteStoreUntagAllTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::untagAllRequest, + &helper, + &NoteStoreUntagAllTesterHelper::onUntagAllRequestReceived); + QObject::connect( + &helper, + &NoteStoreUntagAllTesterHelper::untagAllRequestReady, + &server, + &NoteStoreServer::onUntagAllRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::untagAllRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->untagAllAsync( + guid, + ctx); + + NoteStoreUntagAllAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUntagAllAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUntagAllAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUntagAllAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::AUTH_EXPIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUntagAllTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::untagAllRequest, + &helper, + &NoteStoreUntagAllTesterHelper::onUntagAllRequestReceived); + QObject::connect( + &helper, + &NoteStoreUntagAllTesterHelper::untagAllRequestReady, + &server, + &NoteStoreServer::onUntagAllRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::untagAllRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->untagAllAsync( + guid, + ctx); + + NoteStoreUntagAllAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUntagAllAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUntagAllAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUntagAllAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUntagAllTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::untagAllRequest, + &helper, + &NoteStoreUntagAllTesterHelper::onUntagAllRequestReceived); + QObject::connect( + &helper, + &NoteStoreUntagAllTesterHelper::untagAllRequestReady, + &server, + &NoteStoreServer::onUntagAllRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::untagAllRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->untagAllAsync( + guid, + ctx); + + NoteStoreUntagAllAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUntagAllAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUntagAllAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUntagAllAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUntagAllTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::untagAllRequest, + &helper, + &NoteStoreUntagAllTesterHelper::onUntagAllRequestReceived); + QObject::connect( + &helper, + &NoteStoreUntagAllTesterHelper::untagAllRequestReady, + &server, + &NoteStoreServer::onUntagAllRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::untagAllRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->untagAllAsync( + guid, + ctx); + + NoteStoreUntagAllAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUntagAllAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUntagAllAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteExpungeTag() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreExpungeTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequest, + &helper, + &NoteStoreExpungeTagTesterHelper::onExpungeTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeTagTesterHelper::expungeTagRequestReady, + &server, + &NoteStoreServer::onExpungeTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->expungeTag( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInExpungeTag() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ENML_VALIDATION; + userException.parameter = generateRandomString(); + + NoteStoreExpungeTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequest, + &helper, + &NoteStoreExpungeTagTesterHelper::onExpungeTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeTagTesterHelper::expungeTagRequestReady, + &server, + &NoteStoreServer::onExpungeTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeTag( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInExpungeTag() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_NOT_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreExpungeTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequest, + &helper, + &NoteStoreExpungeTagTesterHelper::onExpungeTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeTagTesterHelper::expungeTagRequestReady, + &server, + &NoteStoreServer::onExpungeTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeTag( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInExpungeTag() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreExpungeTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequest, + &helper, + &NoteStoreExpungeTagTesterHelper::onExpungeTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeTagTesterHelper::expungeTagRequestReady, + &server, + &NoteStoreServer::onExpungeTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeTag( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInExpungeTag() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreExpungeTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequest, + &helper, + &NoteStoreExpungeTagTesterHelper::onExpungeTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeTagTesterHelper::expungeTagRequestReady, + &server, + &NoteStoreServer::onExpungeTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeTag( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteExpungeTagAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreExpungeTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequest, + &helper, + &NoteStoreExpungeTagTesterHelper::onExpungeTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeTagTesterHelper::expungeTagRequestReady, + &server, + &NoteStoreServer::onExpungeTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->expungeTagAsync( + guid, + ctx); + + NoteStoreExpungeTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInExpungeTagAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DATA_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreExpungeTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequest, + &helper, + &NoteStoreExpungeTagTesterHelper::onExpungeTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeTagTesterHelper::expungeTagRequestReady, + &server, + &NoteStoreServer::onExpungeTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeTagAsync( + guid, + ctx); + + NoteStoreExpungeTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInExpungeTagAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreExpungeTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequest, + &helper, + &NoteStoreExpungeTagTesterHelper::onExpungeTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeTagTesterHelper::expungeTagRequestReady, + &server, + &NoteStoreServer::onExpungeTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeTagAsync( + guid, + ctx); + + NoteStoreExpungeTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInExpungeTagAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreExpungeTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequest, + &helper, + &NoteStoreExpungeTagTesterHelper::onExpungeTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeTagTesterHelper::expungeTagRequestReady, + &server, + &NoteStoreServer::onExpungeTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeTagAsync( + guid, + ctx); + + NoteStoreExpungeTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInExpungeTagAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreExpungeTagTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequest, + &helper, + &NoteStoreExpungeTagTesterHelper::onExpungeTagRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeTagTesterHelper::expungeTagRequestReady, + &server, + &NoteStoreServer::onExpungeTagRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeTagRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeTagAsync( + guid, + ctx); + + NoteStoreExpungeTagAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeTagAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeTagAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteListSearches() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomSavedSearch(); + response << generateRandomSavedSearch(); + response << generateRandomSavedSearch(); + + NoteStoreListSearchesTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequest, + &helper, + &NoteStoreListSearchesTesterHelper::onListSearchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSearchesTesterHelper::listSearchesRequestReady, + &server, + &NoteStoreServer::onListSearchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QList res = noteStore->listSearches( + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListSearches() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DATA_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreListSearchesTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequest, + &helper, + &NoteStoreListSearchesTesterHelper::onListSearchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSearchesTesterHelper::listSearchesRequestReady, + &server, + &NoteStoreServer::onListSearchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listSearches( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListSearches() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListSearchesTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequest, + &helper, + &NoteStoreListSearchesTesterHelper::onListSearchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSearchesTesterHelper::listSearchesRequestReady, + &server, + &NoteStoreServer::onListSearchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listSearches( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListSearches() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListSearchesTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequest, + &helper, + &NoteStoreListSearchesTesterHelper::onListSearchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSearchesTesterHelper::listSearchesRequestReady, + &server, + &NoteStoreServer::onListSearchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listSearches( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteListSearchesAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomSavedSearch(); + response << generateRandomSavedSearch(); + response << generateRandomSavedSearch(); + + NoteStoreListSearchesTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequest, + &helper, + &NoteStoreListSearchesTesterHelper::onListSearchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSearchesTesterHelper::listSearchesRequestReady, + &server, + &NoteStoreServer::onListSearchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->listSearchesAsync( + ctx); + + NoteStoreListSearchesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListSearchesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListSearchesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListSearchesAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + userException.parameter = generateRandomString(); + + NoteStoreListSearchesTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequest, + &helper, + &NoteStoreListSearchesTesterHelper::onListSearchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSearchesTesterHelper::listSearchesRequestReady, + &server, + &NoteStoreServer::onListSearchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listSearchesAsync( + ctx); + + NoteStoreListSearchesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListSearchesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListSearchesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListSearchesAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_NOT_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListSearchesTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequest, + &helper, + &NoteStoreListSearchesTesterHelper::onListSearchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSearchesTesterHelper::listSearchesRequestReady, + &server, + &NoteStoreServer::onListSearchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listSearchesAsync( + ctx); + + NoteStoreListSearchesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListSearchesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListSearchesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListSearchesAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListSearchesTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequest, + &helper, + &NoteStoreListSearchesTesterHelper::onListSearchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSearchesTesterHelper::listSearchesRequestReady, + &server, + &NoteStoreServer::onListSearchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSearchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listSearchesAsync( + ctx); + + NoteStoreListSearchesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListSearchesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListSearchesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetSearch() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SavedSearch response = generateRandomSavedSearch(); + + NoteStoreGetSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSearchRequest, + &helper, + &NoteStoreGetSearchTesterHelper::onGetSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSearchTesterHelper::getSearchRequestReady, + &server, + &NoteStoreServer::onGetSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + SavedSearch res = noteStore->getSearch( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetSearch() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DATA_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreGetSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSearchRequest, + &helper, + &NoteStoreGetSearchTesterHelper::onGetSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSearchTesterHelper::getSearchRequestReady, + &server, + &NoteStoreServer::onGetSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SavedSearch res = noteStore->getSearch( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetSearch() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LEN_TOO_LONG; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSearchRequest, + &helper, + &NoteStoreGetSearchTesterHelper::onGetSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSearchTesterHelper::getSearchRequestReady, + &server, + &NoteStoreServer::onGetSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SavedSearch res = noteStore->getSearch( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetSearch() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSearchRequest, + &helper, + &NoteStoreGetSearchTesterHelper::onGetSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSearchTesterHelper::getSearchRequestReady, + &server, + &NoteStoreServer::onGetSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SavedSearch res = noteStore->getSearch( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetSearch() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSearchRequest, + &helper, + &NoteStoreGetSearchTesterHelper::onGetSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSearchTesterHelper::getSearchRequestReady, + &server, + &NoteStoreServer::onGetSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SavedSearch res = noteStore->getSearch( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetSearchAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SavedSearch response = generateRandomSavedSearch(); + + NoteStoreGetSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSearchRequest, + &helper, + &NoteStoreGetSearchTesterHelper::onGetSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSearchTesterHelper::getSearchRequestReady, + &server, + &NoteStoreServer::onGetSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getSearchAsync( + guid, + ctx); + + NoteStoreGetSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetSearchAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::SHARD_UNAVAILABLE; + userException.parameter = generateRandomString(); + + NoteStoreGetSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSearchRequest, + &helper, + &NoteStoreGetSearchTesterHelper::onGetSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSearchTesterHelper::getSearchRequestReady, + &server, + &NoteStoreServer::onGetSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getSearchAsync( + guid, + ctx); + + NoteStoreGetSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetSearchAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSearchRequest, + &helper, + &NoteStoreGetSearchTesterHelper::onGetSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSearchTesterHelper::getSearchRequestReady, + &server, + &NoteStoreServer::onGetSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getSearchAsync( + guid, + ctx); + + NoteStoreGetSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetSearchAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSearchRequest, + &helper, + &NoteStoreGetSearchTesterHelper::onGetSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSearchTesterHelper::getSearchRequestReady, + &server, + &NoteStoreServer::onGetSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getSearchAsync( + guid, + ctx); + + NoteStoreGetSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetSearchAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSearchRequest, + &helper, + &NoteStoreGetSearchTesterHelper::onGetSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSearchTesterHelper::getSearchRequestReady, + &server, + &NoteStoreServer::onGetSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getSearchAsync( + guid, + ctx); + + NoteStoreGetSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteCreateSearch() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SavedSearch response = generateRandomSavedSearch(); + + NoteStoreCreateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createSearchRequest, + &helper, + &NoteStoreCreateSearchTesterHelper::onCreateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateSearchTesterHelper::createSearchRequestReady, + &server, + &NoteStoreServer::onCreateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + SavedSearch res = noteStore->createSearch( + search, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCreateSearch() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + userException.parameter = generateRandomString(); + + NoteStoreCreateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createSearchRequest, + &helper, + &NoteStoreCreateSearchTesterHelper::onCreateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateSearchTesterHelper::createSearchRequestReady, + &server, + &NoteStoreServer::onCreateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SavedSearch res = noteStore->createSearch( + search, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCreateSearch() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCreateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createSearchRequest, + &helper, + &NoteStoreCreateSearchTesterHelper::onCreateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateSearchTesterHelper::createSearchRequestReady, + &server, + &NoteStoreServer::onCreateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SavedSearch res = noteStore->createSearch( + search, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCreateSearch() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCreateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createSearchRequest, + &helper, + &NoteStoreCreateSearchTesterHelper::onCreateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateSearchTesterHelper::createSearchRequestReady, + &server, + &NoteStoreServer::onCreateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SavedSearch res = noteStore->createSearch( + search, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteCreateSearchAsync() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SavedSearch response = generateRandomSavedSearch(); + + NoteStoreCreateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createSearchRequest, + &helper, + &NoteStoreCreateSearchTesterHelper::onCreateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateSearchTesterHelper::createSearchRequestReady, + &server, + &NoteStoreServer::onCreateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->createSearchAsync( + search, + ctx); + + NoteStoreCreateSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCreateSearchAsync() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + userException.parameter = generateRandomString(); + + NoteStoreCreateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createSearchRequest, + &helper, + &NoteStoreCreateSearchTesterHelper::onCreateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateSearchTesterHelper::createSearchRequestReady, + &server, + &NoteStoreServer::onCreateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createSearchAsync( + search, + ctx); + + NoteStoreCreateSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCreateSearchAsync() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCreateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createSearchRequest, + &helper, + &NoteStoreCreateSearchTesterHelper::onCreateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateSearchTesterHelper::createSearchRequestReady, + &server, + &NoteStoreServer::onCreateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createSearchAsync( + search, + ctx); + + NoteStoreCreateSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCreateSearchAsync() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCreateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> SavedSearch + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createSearchRequest, + &helper, + &NoteStoreCreateSearchTesterHelper::onCreateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateSearchTesterHelper::createSearchRequestReady, + &server, + &NoteStoreServer::onCreateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createSearchAsync( + search, + ctx); + + NoteStoreCreateSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteUpdateSearch() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUpdateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequest, + &helper, + &NoteStoreUpdateSearchTesterHelper::onUpdateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSearchTesterHelper::updateSearchRequestReady, + &server, + &NoteStoreServer::onUpdateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->updateSearch( + search, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateSearch() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreUpdateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequest, + &helper, + &NoteStoreUpdateSearchTesterHelper::onUpdateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSearchTesterHelper::updateSearchRequestReady, + &server, + &NoteStoreServer::onUpdateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateSearch( + search, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateSearch() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::AUTH_EXPIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequest, + &helper, + &NoteStoreUpdateSearchTesterHelper::onUpdateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSearchTesterHelper::updateSearchRequestReady, + &server, + &NoteStoreServer::onUpdateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateSearch( + search, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateSearch() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequest, + &helper, + &NoteStoreUpdateSearchTesterHelper::onUpdateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSearchTesterHelper::updateSearchRequestReady, + &server, + &NoteStoreServer::onUpdateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateSearch( + search, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateSearch() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequest, + &helper, + &NoteStoreUpdateSearchTesterHelper::onUpdateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSearchTesterHelper::updateSearchRequestReady, + &server, + &NoteStoreServer::onUpdateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateSearch( + search, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteUpdateSearchAsync() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUpdateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequest, + &helper, + &NoteStoreUpdateSearchTesterHelper::onUpdateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSearchTesterHelper::updateSearchRequestReady, + &server, + &NoteStoreServer::onUpdateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->updateSearchAsync( + search, + ctx); + + NoteStoreUpdateSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateSearchAsync() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + userException.parameter = generateRandomString(); + + NoteStoreUpdateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequest, + &helper, + &NoteStoreUpdateSearchTesterHelper::onUpdateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSearchTesterHelper::updateSearchRequestReady, + &server, + &NoteStoreServer::onUpdateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateSearchAsync( + search, + ctx); + + NoteStoreUpdateSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateSearchAsync() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_NOT_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequest, + &helper, + &NoteStoreUpdateSearchTesterHelper::onUpdateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSearchTesterHelper::updateSearchRequestReady, + &server, + &NoteStoreServer::onUpdateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateSearchAsync( + search, + ctx); + + NoteStoreUpdateSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateSearchAsync() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequest, + &helper, + &NoteStoreUpdateSearchTesterHelper::onUpdateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSearchTesterHelper::updateSearchRequestReady, + &server, + &NoteStoreServer::onUpdateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateSearchAsync( + search, + ctx); + + NoteStoreUpdateSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateSearchAsync() +{ + SavedSearch search = generateRandomSavedSearch(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateSearchTesterHelper helper( + [&] (const SavedSearch & searchParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(search == searchParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequest, + &helper, + &NoteStoreUpdateSearchTesterHelper::onUpdateSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSearchTesterHelper::updateSearchRequestReady, + &server, + &NoteStoreServer::onUpdateSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateSearchAsync( + search, + ctx); + + NoteStoreUpdateSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteExpungeSearch() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreExpungeSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequest, + &helper, + &NoteStoreExpungeSearchTesterHelper::onExpungeSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeSearchTesterHelper::expungeSearchRequestReady, + &server, + &NoteStoreServer::onExpungeSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->expungeSearch( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInExpungeSearch() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_SHORT; + userException.parameter = generateRandomString(); + + NoteStoreExpungeSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequest, + &helper, + &NoteStoreExpungeSearchTesterHelper::onExpungeSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeSearchTesterHelper::expungeSearchRequestReady, + &server, + &NoteStoreServer::onExpungeSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeSearch( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInExpungeSearch() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreExpungeSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequest, + &helper, + &NoteStoreExpungeSearchTesterHelper::onExpungeSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeSearchTesterHelper::expungeSearchRequestReady, + &server, + &NoteStoreServer::onExpungeSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeSearch( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInExpungeSearch() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreExpungeSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequest, + &helper, + &NoteStoreExpungeSearchTesterHelper::onExpungeSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeSearchTesterHelper::expungeSearchRequestReady, + &server, + &NoteStoreServer::onExpungeSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeSearch( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInExpungeSearch() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreExpungeSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequest, + &helper, + &NoteStoreExpungeSearchTesterHelper::onExpungeSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeSearchTesterHelper::expungeSearchRequestReady, + &server, + &NoteStoreServer::onExpungeSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeSearch( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteExpungeSearchAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreExpungeSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequest, + &helper, + &NoteStoreExpungeSearchTesterHelper::onExpungeSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeSearchTesterHelper::expungeSearchRequestReady, + &server, + &NoteStoreServer::onExpungeSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->expungeSearchAsync( + guid, + ctx); + + NoteStoreExpungeSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInExpungeSearchAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::SHARD_UNAVAILABLE; + userException.parameter = generateRandomString(); + + NoteStoreExpungeSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequest, + &helper, + &NoteStoreExpungeSearchTesterHelper::onExpungeSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeSearchTesterHelper::expungeSearchRequestReady, + &server, + &NoteStoreServer::onExpungeSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeSearchAsync( + guid, + ctx); + + NoteStoreExpungeSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInExpungeSearchAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::RATE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreExpungeSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequest, + &helper, + &NoteStoreExpungeSearchTesterHelper::onExpungeSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeSearchTesterHelper::expungeSearchRequestReady, + &server, + &NoteStoreServer::onExpungeSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeSearchAsync( + guid, + ctx); + + NoteStoreExpungeSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInExpungeSearchAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreExpungeSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequest, + &helper, + &NoteStoreExpungeSearchTesterHelper::onExpungeSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeSearchTesterHelper::expungeSearchRequestReady, + &server, + &NoteStoreServer::onExpungeSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeSearchAsync( + guid, + ctx); + + NoteStoreExpungeSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInExpungeSearchAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreExpungeSearchTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequest, + &helper, + &NoteStoreExpungeSearchTesterHelper::onExpungeSearchRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeSearchTesterHelper::expungeSearchRequestReady, + &server, + &NoteStoreServer::onExpungeSearchRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeSearchRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeSearchAsync( + guid, + ctx); + + NoteStoreExpungeSearchAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeSearchAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeSearchAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteFindNoteOffset() +{ + NoteFilter filter = generateRandomNoteFilter(); + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreFindNoteOffsetTesterHelper helper( + [&] (const NoteFilter & filterParam, + const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequest, + &helper, + &NoteStoreFindNoteOffsetTesterHelper::onFindNoteOffsetRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteOffsetTesterHelper::findNoteOffsetRequestReady, + &server, + &NoteStoreServer::onFindNoteOffsetRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->findNoteOffset( + filter, + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInFindNoteOffset() +{ + NoteFilter filter = generateRandomNoteFilter(); + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNKNOWN; + userException.parameter = generateRandomString(); + + NoteStoreFindNoteOffsetTesterHelper helper( + [&] (const NoteFilter & filterParam, + const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequest, + &helper, + &NoteStoreFindNoteOffsetTesterHelper::onFindNoteOffsetRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteOffsetTesterHelper::findNoteOffsetRequestReady, + &server, + &NoteStoreServer::onFindNoteOffsetRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->findNoteOffset( + filter, + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInFindNoteOffset() +{ + NoteFilter filter = generateRandomNoteFilter(); + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreFindNoteOffsetTesterHelper helper( + [&] (const NoteFilter & filterParam, + const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequest, + &helper, + &NoteStoreFindNoteOffsetTesterHelper::onFindNoteOffsetRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteOffsetTesterHelper::findNoteOffsetRequestReady, + &server, + &NoteStoreServer::onFindNoteOffsetRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->findNoteOffset( + filter, + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInFindNoteOffset() +{ + NoteFilter filter = generateRandomNoteFilter(); + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreFindNoteOffsetTesterHelper helper( + [&] (const NoteFilter & filterParam, + const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequest, + &helper, + &NoteStoreFindNoteOffsetTesterHelper::onFindNoteOffsetRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteOffsetTesterHelper::findNoteOffsetRequestReady, + &server, + &NoteStoreServer::onFindNoteOffsetRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->findNoteOffset( + filter, + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInFindNoteOffset() +{ + NoteFilter filter = generateRandomNoteFilter(); + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreFindNoteOffsetTesterHelper helper( + [&] (const NoteFilter & filterParam, + const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequest, + &helper, + &NoteStoreFindNoteOffsetTesterHelper::onFindNoteOffsetRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteOffsetTesterHelper::findNoteOffsetRequestReady, + &server, + &NoteStoreServer::onFindNoteOffsetRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->findNoteOffset( + filter, + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteFindNoteOffsetAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreFindNoteOffsetTesterHelper helper( + [&] (const NoteFilter & filterParam, + const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequest, + &helper, + &NoteStoreFindNoteOffsetTesterHelper::onFindNoteOffsetRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteOffsetTesterHelper::findNoteOffsetRequestReady, + &server, + &NoteStoreServer::onFindNoteOffsetRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->findNoteOffsetAsync( + filter, + guid, + ctx); + + NoteStoreFindNoteOffsetAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNoteOffsetAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNoteOffsetAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInFindNoteOffsetAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INTERNAL_ERROR; + userException.parameter = generateRandomString(); + + NoteStoreFindNoteOffsetTesterHelper helper( + [&] (const NoteFilter & filterParam, + const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequest, + &helper, + &NoteStoreFindNoteOffsetTesterHelper::onFindNoteOffsetRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteOffsetTesterHelper::findNoteOffsetRequestReady, + &server, + &NoteStoreServer::onFindNoteOffsetRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findNoteOffsetAsync( + filter, + guid, + ctx); + + NoteStoreFindNoteOffsetAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNoteOffsetAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNoteOffsetAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInFindNoteOffsetAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TOO_FEW; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreFindNoteOffsetTesterHelper helper( + [&] (const NoteFilter & filterParam, + const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequest, + &helper, + &NoteStoreFindNoteOffsetTesterHelper::onFindNoteOffsetRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteOffsetTesterHelper::findNoteOffsetRequestReady, + &server, + &NoteStoreServer::onFindNoteOffsetRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findNoteOffsetAsync( + filter, + guid, + ctx); + + NoteStoreFindNoteOffsetAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNoteOffsetAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNoteOffsetAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInFindNoteOffsetAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreFindNoteOffsetTesterHelper helper( + [&] (const NoteFilter & filterParam, + const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequest, + &helper, + &NoteStoreFindNoteOffsetTesterHelper::onFindNoteOffsetRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteOffsetTesterHelper::findNoteOffsetRequestReady, + &server, + &NoteStoreServer::onFindNoteOffsetRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findNoteOffsetAsync( + filter, + guid, + ctx); + + NoteStoreFindNoteOffsetAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNoteOffsetAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNoteOffsetAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInFindNoteOffsetAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreFindNoteOffsetTesterHelper helper( + [&] (const NoteFilter & filterParam, + const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequest, + &helper, + &NoteStoreFindNoteOffsetTesterHelper::onFindNoteOffsetRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteOffsetTesterHelper::findNoteOffsetRequestReady, + &server, + &NoteStoreServer::onFindNoteOffsetRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteOffsetRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findNoteOffsetAsync( + filter, + guid, + ctx); + + NoteStoreFindNoteOffsetAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNoteOffsetAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNoteOffsetAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteFindNotesMetadata() +{ + NoteFilter filter = generateRandomNoteFilter(); + qint32 offset = generateRandomInt32(); + qint32 maxNotes = generateRandomInt32(); + NotesMetadataResultSpec resultSpec = generateRandomNotesMetadataResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + NotesMetadataList response = generateRandomNotesMetadataList(); + + NoteStoreFindNotesMetadataTesterHelper helper( + [&] (const NoteFilter & filterParam, + qint32 offsetParam, + qint32 maxNotesParam, + const NotesMetadataResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> NotesMetadataList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(offset == offsetParam); + Q_ASSERT(maxNotes == maxNotesParam); + Q_ASSERT(resultSpec == resultSpecParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequest, + &helper, + &NoteStoreFindNotesMetadataTesterHelper::onFindNotesMetadataRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNotesMetadataTesterHelper::findNotesMetadataRequestReady, + &server, + &NoteStoreServer::onFindNotesMetadataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + NotesMetadataList res = noteStore->findNotesMetadata( + filter, + offset, + maxNotes, + resultSpec, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInFindNotesMetadata() +{ + NoteFilter filter = generateRandomNoteFilter(); + qint32 offset = generateRandomInt32(); + qint32 maxNotes = generateRandomInt32(); + NotesMetadataResultSpec resultSpec = generateRandomNotesMetadataResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_REGISTERED; + userException.parameter = generateRandomString(); + + NoteStoreFindNotesMetadataTesterHelper helper( + [&] (const NoteFilter & filterParam, + qint32 offsetParam, + qint32 maxNotesParam, + const NotesMetadataResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> NotesMetadataList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(offset == offsetParam); + Q_ASSERT(maxNotes == maxNotesParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequest, + &helper, + &NoteStoreFindNotesMetadataTesterHelper::onFindNotesMetadataRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNotesMetadataTesterHelper::findNotesMetadataRequestReady, + &server, + &NoteStoreServer::onFindNotesMetadataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + NotesMetadataList res = noteStore->findNotesMetadata( + filter, + offset, + maxNotes, + resultSpec, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInFindNotesMetadata() +{ + NoteFilter filter = generateRandomNoteFilter(); + qint32 offset = generateRandomInt32(); + qint32 maxNotes = generateRandomInt32(); + NotesMetadataResultSpec resultSpec = generateRandomNotesMetadataResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DATA_CONFLICT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreFindNotesMetadataTesterHelper helper( + [&] (const NoteFilter & filterParam, + qint32 offsetParam, + qint32 maxNotesParam, + const NotesMetadataResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> NotesMetadataList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(offset == offsetParam); + Q_ASSERT(maxNotes == maxNotesParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequest, + &helper, + &NoteStoreFindNotesMetadataTesterHelper::onFindNotesMetadataRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNotesMetadataTesterHelper::findNotesMetadataRequestReady, + &server, + &NoteStoreServer::onFindNotesMetadataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + NotesMetadataList res = noteStore->findNotesMetadata( + filter, + offset, + maxNotes, + resultSpec, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInFindNotesMetadata() +{ + NoteFilter filter = generateRandomNoteFilter(); + qint32 offset = generateRandomInt32(); + qint32 maxNotes = generateRandomInt32(); + NotesMetadataResultSpec resultSpec = generateRandomNotesMetadataResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreFindNotesMetadataTesterHelper helper( + [&] (const NoteFilter & filterParam, + qint32 offsetParam, + qint32 maxNotesParam, + const NotesMetadataResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> NotesMetadataList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(offset == offsetParam); + Q_ASSERT(maxNotes == maxNotesParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequest, + &helper, + &NoteStoreFindNotesMetadataTesterHelper::onFindNotesMetadataRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNotesMetadataTesterHelper::findNotesMetadataRequestReady, + &server, + &NoteStoreServer::onFindNotesMetadataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + NotesMetadataList res = noteStore->findNotesMetadata( + filter, + offset, + maxNotes, + resultSpec, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInFindNotesMetadata() +{ + NoteFilter filter = generateRandomNoteFilter(); + qint32 offset = generateRandomInt32(); + qint32 maxNotes = generateRandomInt32(); + NotesMetadataResultSpec resultSpec = generateRandomNotesMetadataResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreFindNotesMetadataTesterHelper helper( + [&] (const NoteFilter & filterParam, + qint32 offsetParam, + qint32 maxNotesParam, + const NotesMetadataResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> NotesMetadataList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(offset == offsetParam); + Q_ASSERT(maxNotes == maxNotesParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequest, + &helper, + &NoteStoreFindNotesMetadataTesterHelper::onFindNotesMetadataRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNotesMetadataTesterHelper::findNotesMetadataRequestReady, + &server, + &NoteStoreServer::onFindNotesMetadataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + NotesMetadataList res = noteStore->findNotesMetadata( + filter, + offset, + maxNotes, + resultSpec, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteFindNotesMetadataAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + qint32 offset = generateRandomInt32(); + qint32 maxNotes = generateRandomInt32(); + NotesMetadataResultSpec resultSpec = generateRandomNotesMetadataResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + NotesMetadataList response = generateRandomNotesMetadataList(); + + NoteStoreFindNotesMetadataTesterHelper helper( + [&] (const NoteFilter & filterParam, + qint32 offsetParam, + qint32 maxNotesParam, + const NotesMetadataResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> NotesMetadataList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(offset == offsetParam); + Q_ASSERT(maxNotes == maxNotesParam); + Q_ASSERT(resultSpec == resultSpecParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequest, + &helper, + &NoteStoreFindNotesMetadataTesterHelper::onFindNotesMetadataRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNotesMetadataTesterHelper::findNotesMetadataRequestReady, + &server, + &NoteStoreServer::onFindNotesMetadataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->findNotesMetadataAsync( + filter, + offset, + maxNotes, + resultSpec, + ctx); + + NoteStoreFindNotesMetadataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNotesMetadataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNotesMetadataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInFindNotesMetadataAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + qint32 offset = generateRandomInt32(); + qint32 maxNotes = generateRandomInt32(); + NotesMetadataResultSpec resultSpec = generateRandomNotesMetadataResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + userException.parameter = generateRandomString(); + + NoteStoreFindNotesMetadataTesterHelper helper( + [&] (const NoteFilter & filterParam, + qint32 offsetParam, + qint32 maxNotesParam, + const NotesMetadataResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> NotesMetadataList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(offset == offsetParam); + Q_ASSERT(maxNotes == maxNotesParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequest, + &helper, + &NoteStoreFindNotesMetadataTesterHelper::onFindNotesMetadataRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNotesMetadataTesterHelper::findNotesMetadataRequestReady, + &server, + &NoteStoreServer::onFindNotesMetadataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findNotesMetadataAsync( + filter, + offset, + maxNotes, + resultSpec, + ctx); + + NoteStoreFindNotesMetadataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNotesMetadataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNotesMetadataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInFindNotesMetadataAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + qint32 offset = generateRandomInt32(); + qint32 maxNotes = generateRandomInt32(); + NotesMetadataResultSpec resultSpec = generateRandomNotesMetadataResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::RATE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreFindNotesMetadataTesterHelper helper( + [&] (const NoteFilter & filterParam, + qint32 offsetParam, + qint32 maxNotesParam, + const NotesMetadataResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> NotesMetadataList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(offset == offsetParam); + Q_ASSERT(maxNotes == maxNotesParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequest, + &helper, + &NoteStoreFindNotesMetadataTesterHelper::onFindNotesMetadataRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNotesMetadataTesterHelper::findNotesMetadataRequestReady, + &server, + &NoteStoreServer::onFindNotesMetadataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findNotesMetadataAsync( + filter, + offset, + maxNotes, + resultSpec, + ctx); + + NoteStoreFindNotesMetadataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNotesMetadataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNotesMetadataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInFindNotesMetadataAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + qint32 offset = generateRandomInt32(); + qint32 maxNotes = generateRandomInt32(); + NotesMetadataResultSpec resultSpec = generateRandomNotesMetadataResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreFindNotesMetadataTesterHelper helper( + [&] (const NoteFilter & filterParam, + qint32 offsetParam, + qint32 maxNotesParam, + const NotesMetadataResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> NotesMetadataList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(offset == offsetParam); + Q_ASSERT(maxNotes == maxNotesParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequest, + &helper, + &NoteStoreFindNotesMetadataTesterHelper::onFindNotesMetadataRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNotesMetadataTesterHelper::findNotesMetadataRequestReady, + &server, + &NoteStoreServer::onFindNotesMetadataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findNotesMetadataAsync( + filter, + offset, + maxNotes, + resultSpec, + ctx); + + NoteStoreFindNotesMetadataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNotesMetadataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNotesMetadataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInFindNotesMetadataAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + qint32 offset = generateRandomInt32(); + qint32 maxNotes = generateRandomInt32(); + NotesMetadataResultSpec resultSpec = generateRandomNotesMetadataResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreFindNotesMetadataTesterHelper helper( + [&] (const NoteFilter & filterParam, + qint32 offsetParam, + qint32 maxNotesParam, + const NotesMetadataResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> NotesMetadataList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(offset == offsetParam); + Q_ASSERT(maxNotes == maxNotesParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequest, + &helper, + &NoteStoreFindNotesMetadataTesterHelper::onFindNotesMetadataRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNotesMetadataTesterHelper::findNotesMetadataRequestReady, + &server, + &NoteStoreServer::onFindNotesMetadataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNotesMetadataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findNotesMetadataAsync( + filter, + offset, + maxNotes, + resultSpec, + ctx); + + NoteStoreFindNotesMetadataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNotesMetadataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNotesMetadataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteFindNoteCounts() +{ + NoteFilter filter = generateRandomNoteFilter(); + bool withTrash = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + NoteCollectionCounts response = generateRandomNoteCollectionCounts(); + + NoteStoreFindNoteCountsTesterHelper helper( + [&] (const NoteFilter & filterParam, + bool withTrashParam, + IRequestContextPtr ctxParam) -> NoteCollectionCounts + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(withTrash == withTrashParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequest, + &helper, + &NoteStoreFindNoteCountsTesterHelper::onFindNoteCountsRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteCountsTesterHelper::findNoteCountsRequestReady, + &server, + &NoteStoreServer::onFindNoteCountsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + NoteCollectionCounts res = noteStore->findNoteCounts( + filter, + withTrash, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInFindNoteCounts() +{ + NoteFilter filter = generateRandomNoteFilter(); + bool withTrash = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DATA_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreFindNoteCountsTesterHelper helper( + [&] (const NoteFilter & filterParam, + bool withTrashParam, + IRequestContextPtr ctxParam) -> NoteCollectionCounts + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(withTrash == withTrashParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequest, + &helper, + &NoteStoreFindNoteCountsTesterHelper::onFindNoteCountsRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteCountsTesterHelper::findNoteCountsRequestReady, + &server, + &NoteStoreServer::onFindNoteCountsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + NoteCollectionCounts res = noteStore->findNoteCounts( + filter, + withTrash, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInFindNoteCounts() +{ + NoteFilter filter = generateRandomNoteFilter(); + bool withTrash = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ENML_VALIDATION; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreFindNoteCountsTesterHelper helper( + [&] (const NoteFilter & filterParam, + bool withTrashParam, + IRequestContextPtr ctxParam) -> NoteCollectionCounts + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(withTrash == withTrashParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequest, + &helper, + &NoteStoreFindNoteCountsTesterHelper::onFindNoteCountsRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteCountsTesterHelper::findNoteCountsRequestReady, + &server, + &NoteStoreServer::onFindNoteCountsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + NoteCollectionCounts res = noteStore->findNoteCounts( + filter, + withTrash, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInFindNoteCounts() +{ + NoteFilter filter = generateRandomNoteFilter(); + bool withTrash = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreFindNoteCountsTesterHelper helper( + [&] (const NoteFilter & filterParam, + bool withTrashParam, + IRequestContextPtr ctxParam) -> NoteCollectionCounts + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(withTrash == withTrashParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequest, + &helper, + &NoteStoreFindNoteCountsTesterHelper::onFindNoteCountsRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteCountsTesterHelper::findNoteCountsRequestReady, + &server, + &NoteStoreServer::onFindNoteCountsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + NoteCollectionCounts res = noteStore->findNoteCounts( + filter, + withTrash, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInFindNoteCounts() +{ + NoteFilter filter = generateRandomNoteFilter(); + bool withTrash = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreFindNoteCountsTesterHelper helper( + [&] (const NoteFilter & filterParam, + bool withTrashParam, + IRequestContextPtr ctxParam) -> NoteCollectionCounts + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(withTrash == withTrashParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequest, + &helper, + &NoteStoreFindNoteCountsTesterHelper::onFindNoteCountsRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteCountsTesterHelper::findNoteCountsRequestReady, + &server, + &NoteStoreServer::onFindNoteCountsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + NoteCollectionCounts res = noteStore->findNoteCounts( + filter, + withTrash, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteFindNoteCountsAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + bool withTrash = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + NoteCollectionCounts response = generateRandomNoteCollectionCounts(); + + NoteStoreFindNoteCountsTesterHelper helper( + [&] (const NoteFilter & filterParam, + bool withTrashParam, + IRequestContextPtr ctxParam) -> NoteCollectionCounts + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(withTrash == withTrashParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequest, + &helper, + &NoteStoreFindNoteCountsTesterHelper::onFindNoteCountsRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteCountsTesterHelper::findNoteCountsRequestReady, + &server, + &NoteStoreServer::onFindNoteCountsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->findNoteCountsAsync( + filter, + withTrash, + ctx); + + NoteStoreFindNoteCountsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNoteCountsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNoteCountsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInFindNoteCountsAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + bool withTrash = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DATA_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreFindNoteCountsTesterHelper helper( + [&] (const NoteFilter & filterParam, + bool withTrashParam, + IRequestContextPtr ctxParam) -> NoteCollectionCounts + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(withTrash == withTrashParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequest, + &helper, + &NoteStoreFindNoteCountsTesterHelper::onFindNoteCountsRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteCountsTesterHelper::findNoteCountsRequestReady, + &server, + &NoteStoreServer::onFindNoteCountsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findNoteCountsAsync( + filter, + withTrash, + ctx); + + NoteStoreFindNoteCountsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNoteCountsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNoteCountsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInFindNoteCountsAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + bool withTrash = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreFindNoteCountsTesterHelper helper( + [&] (const NoteFilter & filterParam, + bool withTrashParam, + IRequestContextPtr ctxParam) -> NoteCollectionCounts + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(withTrash == withTrashParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequest, + &helper, + &NoteStoreFindNoteCountsTesterHelper::onFindNoteCountsRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteCountsTesterHelper::findNoteCountsRequestReady, + &server, + &NoteStoreServer::onFindNoteCountsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findNoteCountsAsync( + filter, + withTrash, + ctx); + + NoteStoreFindNoteCountsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNoteCountsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNoteCountsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInFindNoteCountsAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + bool withTrash = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreFindNoteCountsTesterHelper helper( + [&] (const NoteFilter & filterParam, + bool withTrashParam, + IRequestContextPtr ctxParam) -> NoteCollectionCounts + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(withTrash == withTrashParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequest, + &helper, + &NoteStoreFindNoteCountsTesterHelper::onFindNoteCountsRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteCountsTesterHelper::findNoteCountsRequestReady, + &server, + &NoteStoreServer::onFindNoteCountsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findNoteCountsAsync( + filter, + withTrash, + ctx); + + NoteStoreFindNoteCountsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNoteCountsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNoteCountsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInFindNoteCountsAsync() +{ + NoteFilter filter = generateRandomNoteFilter(); + bool withTrash = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreFindNoteCountsTesterHelper helper( + [&] (const NoteFilter & filterParam, + bool withTrashParam, + IRequestContextPtr ctxParam) -> NoteCollectionCounts + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(filter == filterParam); + Q_ASSERT(withTrash == withTrashParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequest, + &helper, + &NoteStoreFindNoteCountsTesterHelper::onFindNoteCountsRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindNoteCountsTesterHelper::findNoteCountsRequestReady, + &server, + &NoteStoreServer::onFindNoteCountsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findNoteCountsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findNoteCountsAsync( + filter, + withTrash, + ctx); + + NoteStoreFindNoteCountsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindNoteCountsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindNoteCountsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetNoteWithResultSpec() +{ + Guid guid = generateRandomString(); + NoteResultSpec resultSpec = generateRandomNoteResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Note response = generateRandomNote(); + + NoteStoreGetNoteWithResultSpecTesterHelper helper( + [&] (const Guid & guidParam, + const NoteResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(resultSpec == resultSpecParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequest, + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::onGetNoteWithResultSpecRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::getNoteWithResultSpecRequestReady, + &server, + &NoteStoreServer::onGetNoteWithResultSpecRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Note res = noteStore->getNoteWithResultSpec( + guid, + resultSpec, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteWithResultSpec() +{ + Guid guid = generateRandomString(); + NoteResultSpec resultSpec = generateRandomNoteResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteWithResultSpecTesterHelper helper( + [&] (const Guid & guidParam, + const NoteResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequest, + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::onGetNoteWithResultSpecRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::getNoteWithResultSpecRequestReady, + &server, + &NoteStoreServer::onGetNoteWithResultSpecRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->getNoteWithResultSpec( + guid, + resultSpec, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteWithResultSpec() +{ + Guid guid = generateRandomString(); + NoteResultSpec resultSpec = generateRandomNoteResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::OPENID_ALREADY_TAKEN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteWithResultSpecTesterHelper helper( + [&] (const Guid & guidParam, + const NoteResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequest, + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::onGetNoteWithResultSpecRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::getNoteWithResultSpecRequestReady, + &server, + &NoteStoreServer::onGetNoteWithResultSpecRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->getNoteWithResultSpec( + guid, + resultSpec, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteWithResultSpec() +{ + Guid guid = generateRandomString(); + NoteResultSpec resultSpec = generateRandomNoteResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteWithResultSpecTesterHelper helper( + [&] (const Guid & guidParam, + const NoteResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequest, + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::onGetNoteWithResultSpecRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::getNoteWithResultSpecRequestReady, + &server, + &NoteStoreServer::onGetNoteWithResultSpecRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->getNoteWithResultSpec( + guid, + resultSpec, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteWithResultSpec() +{ + Guid guid = generateRandomString(); + NoteResultSpec resultSpec = generateRandomNoteResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteWithResultSpecTesterHelper helper( + [&] (const Guid & guidParam, + const NoteResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequest, + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::onGetNoteWithResultSpecRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::getNoteWithResultSpecRequestReady, + &server, + &NoteStoreServer::onGetNoteWithResultSpecRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->getNoteWithResultSpec( + guid, + resultSpec, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetNoteWithResultSpecAsync() +{ + Guid guid = generateRandomString(); + NoteResultSpec resultSpec = generateRandomNoteResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Note response = generateRandomNote(); + + NoteStoreGetNoteWithResultSpecTesterHelper helper( + [&] (const Guid & guidParam, + const NoteResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(resultSpec == resultSpecParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequest, + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::onGetNoteWithResultSpecRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::getNoteWithResultSpecRequestReady, + &server, + &NoteStoreServer::onGetNoteWithResultSpecRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getNoteWithResultSpecAsync( + guid, + resultSpec, + ctx); + + NoteStoreGetNoteWithResultSpecAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteWithResultSpecAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteWithResultSpecAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteWithResultSpecAsync() +{ + Guid guid = generateRandomString(); + NoteResultSpec resultSpec = generateRandomNoteResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_MANY; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteWithResultSpecTesterHelper helper( + [&] (const Guid & guidParam, + const NoteResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequest, + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::onGetNoteWithResultSpecRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::getNoteWithResultSpecRequestReady, + &server, + &NoteStoreServer::onGetNoteWithResultSpecRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteWithResultSpecAsync( + guid, + resultSpec, + ctx); + + NoteStoreGetNoteWithResultSpecAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteWithResultSpecAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteWithResultSpecAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteWithResultSpecAsync() +{ + Guid guid = generateRandomString(); + NoteResultSpec resultSpec = generateRandomNoteResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteWithResultSpecTesterHelper helper( + [&] (const Guid & guidParam, + const NoteResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequest, + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::onGetNoteWithResultSpecRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::getNoteWithResultSpecRequestReady, + &server, + &NoteStoreServer::onGetNoteWithResultSpecRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteWithResultSpecAsync( + guid, + resultSpec, + ctx); + + NoteStoreGetNoteWithResultSpecAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteWithResultSpecAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteWithResultSpecAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteWithResultSpecAsync() +{ + Guid guid = generateRandomString(); + NoteResultSpec resultSpec = generateRandomNoteResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteWithResultSpecTesterHelper helper( + [&] (const Guid & guidParam, + const NoteResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequest, + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::onGetNoteWithResultSpecRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::getNoteWithResultSpecRequestReady, + &server, + &NoteStoreServer::onGetNoteWithResultSpecRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteWithResultSpecAsync( + guid, + resultSpec, + ctx); + + NoteStoreGetNoteWithResultSpecAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteWithResultSpecAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteWithResultSpecAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteWithResultSpecAsync() +{ + Guid guid = generateRandomString(); + NoteResultSpec resultSpec = generateRandomNoteResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteWithResultSpecTesterHelper helper( + [&] (const Guid & guidParam, + const NoteResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequest, + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::onGetNoteWithResultSpecRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteWithResultSpecTesterHelper::getNoteWithResultSpecRequestReady, + &server, + &NoteStoreServer::onGetNoteWithResultSpecRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteWithResultSpecRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteWithResultSpecAsync( + guid, + resultSpec, + ctx); + + NoteStoreGetNoteWithResultSpecAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteWithResultSpecAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteWithResultSpecAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetNote() +{ + Guid guid = generateRandomString(); + bool withContent = generateRandomBool(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Note response = generateRandomNote(); + + NoteStoreGetNoteTesterHelper helper( + [&] (const Guid & guidParam, + bool withContentParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withContent == withContentParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteRequest, + &helper, + &NoteStoreGetNoteTesterHelper::onGetNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTesterHelper::getNoteRequestReady, + &server, + &NoteStoreServer::onGetNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Note res = noteStore->getNote( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNote() +{ + Guid guid = generateRandomString(); + bool withContent = generateRandomBool(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::QUOTA_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteTesterHelper helper( + [&] (const Guid & guidParam, + bool withContentParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withContent == withContentParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteRequest, + &helper, + &NoteStoreGetNoteTesterHelper::onGetNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTesterHelper::getNoteRequestReady, + &server, + &NoteStoreServer::onGetNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->getNote( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNote() +{ + Guid guid = generateRandomString(); + bool withContent = generateRandomBool(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteTesterHelper helper( + [&] (const Guid & guidParam, + bool withContentParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withContent == withContentParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteRequest, + &helper, + &NoteStoreGetNoteTesterHelper::onGetNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTesterHelper::getNoteRequestReady, + &server, + &NoteStoreServer::onGetNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->getNote( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNote() +{ + Guid guid = generateRandomString(); + bool withContent = generateRandomBool(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteTesterHelper helper( + [&] (const Guid & guidParam, + bool withContentParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withContent == withContentParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteRequest, + &helper, + &NoteStoreGetNoteTesterHelper::onGetNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTesterHelper::getNoteRequestReady, + &server, + &NoteStoreServer::onGetNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->getNote( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNote() +{ + Guid guid = generateRandomString(); + bool withContent = generateRandomBool(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteTesterHelper helper( + [&] (const Guid & guidParam, + bool withContentParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withContent == withContentParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteRequest, + &helper, + &NoteStoreGetNoteTesterHelper::onGetNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTesterHelper::getNoteRequestReady, + &server, + &NoteStoreServer::onGetNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->getNote( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetNoteAsync() +{ + Guid guid = generateRandomString(); + bool withContent = generateRandomBool(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Note response = generateRandomNote(); + + NoteStoreGetNoteTesterHelper helper( + [&] (const Guid & guidParam, + bool withContentParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withContent == withContentParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteRequest, + &helper, + &NoteStoreGetNoteTesterHelper::onGetNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTesterHelper::getNoteRequestReady, + &server, + &NoteStoreServer::onGetNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getNoteAsync( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + NoteStoreGetNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteAsync() +{ + Guid guid = generateRandomString(); + bool withContent = generateRandomBool(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_AUTH; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteTesterHelper helper( + [&] (const Guid & guidParam, + bool withContentParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withContent == withContentParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteRequest, + &helper, + &NoteStoreGetNoteTesterHelper::onGetNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTesterHelper::getNoteRequestReady, + &server, + &NoteStoreServer::onGetNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteAsync( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + NoteStoreGetNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteAsync() +{ + Guid guid = generateRandomString(); + bool withContent = generateRandomBool(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteTesterHelper helper( + [&] (const Guid & guidParam, + bool withContentParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withContent == withContentParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteRequest, + &helper, + &NoteStoreGetNoteTesterHelper::onGetNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTesterHelper::getNoteRequestReady, + &server, + &NoteStoreServer::onGetNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteAsync( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + NoteStoreGetNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteAsync() +{ + Guid guid = generateRandomString(); + bool withContent = generateRandomBool(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteTesterHelper helper( + [&] (const Guid & guidParam, + bool withContentParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withContent == withContentParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteRequest, + &helper, + &NoteStoreGetNoteTesterHelper::onGetNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTesterHelper::getNoteRequestReady, + &server, + &NoteStoreServer::onGetNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteAsync( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + NoteStoreGetNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteAsync() +{ + Guid guid = generateRandomString(); + bool withContent = generateRandomBool(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteTesterHelper helper( + [&] (const Guid & guidParam, + bool withContentParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withContent == withContentParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteRequest, + &helper, + &NoteStoreGetNoteTesterHelper::onGetNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTesterHelper::getNoteRequestReady, + &server, + &NoteStoreServer::onGetNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteAsync( + guid, + withContent, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + NoteStoreGetNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetNoteApplicationData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + LazyMap response = generateRandomLazyMap(); + + NoteStoreGetNoteApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequest, + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::onGetNoteApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::getNoteApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + LazyMap res = noteStore->getNoteApplicationData( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteApplicationData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequest, + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::onGetNoteApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::getNoteApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + LazyMap res = noteStore->getNoteApplicationData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteApplicationData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_AUTH; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequest, + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::onGetNoteApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::getNoteApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + LazyMap res = noteStore->getNoteApplicationData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteApplicationData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequest, + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::onGetNoteApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::getNoteApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + LazyMap res = noteStore->getNoteApplicationData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteApplicationData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequest, + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::onGetNoteApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::getNoteApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + LazyMap res = noteStore->getNoteApplicationData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetNoteApplicationDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + LazyMap response = generateRandomLazyMap(); + + NoteStoreGetNoteApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequest, + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::onGetNoteApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::getNoteApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getNoteApplicationDataAsync( + guid, + ctx); + + NoteStoreGetNoteApplicationDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteApplicationDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteApplicationDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteApplicationDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_MANY; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequest, + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::onGetNoteApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::getNoteApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteApplicationDataAsync( + guid, + ctx); + + NoteStoreGetNoteApplicationDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteApplicationDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteApplicationDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteApplicationDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequest, + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::onGetNoteApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::getNoteApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteApplicationDataAsync( + guid, + ctx); + + NoteStoreGetNoteApplicationDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteApplicationDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteApplicationDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteApplicationDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequest, + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::onGetNoteApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::getNoteApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteApplicationDataAsync( + guid, + ctx); + + NoteStoreGetNoteApplicationDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteApplicationDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteApplicationDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteApplicationDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequest, + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::onGetNoteApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataTesterHelper::getNoteApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteApplicationDataAsync( + guid, + ctx); + + NoteStoreGetNoteApplicationDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteApplicationDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteApplicationDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QString response = generateRandomString(); + + NoteStoreGetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequest, + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::onGetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::getNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QString res = noteStore->getNoteApplicationDataEntry( + guid, + key, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_MANY; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequest, + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::onGetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::getNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getNoteApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequest, + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::onGetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::getNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getNoteApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequest, + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::onGetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::getNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getNoteApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequest, + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::onGetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::getNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getNoteApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QString response = generateRandomString(); + + NoteStoreGetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequest, + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::onGetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::getNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getNoteApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequest, + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::onGetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::getNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::SHARD_UNAVAILABLE; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequest, + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::onGetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::getNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequest, + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::onGetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::getNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequest, + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::onGetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteApplicationDataEntryTesterHelper::getNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteSetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreSetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequest, + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::onSetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::setNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->setNoteApplicationDataEntry( + guid, + key, + value, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInSetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNKNOWN; + userException.parameter = generateRandomString(); + + NoteStoreSetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequest, + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::onSetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::setNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->setNoteApplicationDataEntry( + guid, + key, + value, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInSetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreSetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequest, + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::onSetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::setNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->setNoteApplicationDataEntry( + guid, + key, + value, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInSetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreSetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequest, + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::onSetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::setNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->setNoteApplicationDataEntry( + guid, + key, + value, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInSetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreSetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequest, + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::onSetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::setNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->setNoteApplicationDataEntry( + guid, + key, + value, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteSetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreSetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequest, + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::onSetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::setNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->setNoteApplicationDataEntryAsync( + guid, + key, + value, + ctx); + + NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInSetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + userException.parameter = generateRandomString(); + + NoteStoreSetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequest, + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::onSetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::setNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->setNoteApplicationDataEntryAsync( + guid, + key, + value, + ctx); + + NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInSetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::UNKNOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreSetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequest, + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::onSetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::setNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->setNoteApplicationDataEntryAsync( + guid, + key, + value, + ctx); + + NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInSetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreSetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequest, + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::onSetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::setNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->setNoteApplicationDataEntryAsync( + guid, + key, + value, + ctx); + + NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInSetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreSetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequest, + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::onSetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNoteApplicationDataEntryTesterHelper::setNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->setNoteApplicationDataEntryAsync( + guid, + key, + value, + ctx); + + NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteUnsetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUnsetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::onUnsetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::unsetNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->unsetNoteApplicationDataEntry( + guid, + key, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUnsetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + userException.parameter = generateRandomString(); + + NoteStoreUnsetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::onUnsetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::unsetNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->unsetNoteApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUnsetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TAKEN_DOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUnsetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::onUnsetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::unsetNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->unsetNoteApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUnsetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUnsetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::onUnsetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::unsetNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->unsetNoteApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUnsetNoteApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUnsetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::onUnsetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::unsetNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->unsetNoteApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteUnsetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUnsetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::onUnsetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::unsetNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->unsetNoteApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUnsetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + userException.parameter = generateRandomString(); + + NoteStoreUnsetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::onUnsetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::unsetNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->unsetNoteApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUnsetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUnsetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::onUnsetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::unsetNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->unsetNoteApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUnsetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUnsetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::onUnsetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::unsetNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->unsetNoteApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUnsetNoteApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUnsetNoteApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::onUnsetNoteApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetNoteApplicationDataEntryTesterHelper::unsetNoteApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetNoteApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetNoteApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->unsetNoteApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUnsetNoteApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetNoteContent() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QString response = generateRandomString(); + + NoteStoreGetNoteContentTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequest, + &helper, + &NoteStoreGetNoteContentTesterHelper::onGetNoteContentRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteContentTesterHelper::getNoteContentRequestReady, + &server, + &NoteStoreServer::onGetNoteContentRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QString res = noteStore->getNoteContent( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteContent() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ENML_VALIDATION; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteContentTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequest, + &helper, + &NoteStoreGetNoteContentTesterHelper::onGetNoteContentRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteContentTesterHelper::getNoteContentRequestReady, + &server, + &NoteStoreServer::onGetNoteContentRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getNoteContent( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteContent() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteContentTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequest, + &helper, + &NoteStoreGetNoteContentTesterHelper::onGetNoteContentRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteContentTesterHelper::getNoteContentRequestReady, + &server, + &NoteStoreServer::onGetNoteContentRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getNoteContent( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteContent() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteContentTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequest, + &helper, + &NoteStoreGetNoteContentTesterHelper::onGetNoteContentRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteContentTesterHelper::getNoteContentRequestReady, + &server, + &NoteStoreServer::onGetNoteContentRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getNoteContent( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteContent() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteContentTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequest, + &helper, + &NoteStoreGetNoteContentTesterHelper::onGetNoteContentRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteContentTesterHelper::getNoteContentRequestReady, + &server, + &NoteStoreServer::onGetNoteContentRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getNoteContent( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetNoteContentAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QString response = generateRandomString(); + + NoteStoreGetNoteContentTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequest, + &helper, + &NoteStoreGetNoteContentTesterHelper::onGetNoteContentRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteContentTesterHelper::getNoteContentRequestReady, + &server, + &NoteStoreServer::onGetNoteContentRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getNoteContentAsync( + guid, + ctx); + + NoteStoreGetNoteContentAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteContentAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteContentAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteContentAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteContentTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequest, + &helper, + &NoteStoreGetNoteContentTesterHelper::onGetNoteContentRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteContentTesterHelper::getNoteContentRequestReady, + &server, + &NoteStoreServer::onGetNoteContentRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteContentAsync( + guid, + ctx); + + NoteStoreGetNoteContentAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteContentAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteContentAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteContentAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TOO_FEW; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteContentTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequest, + &helper, + &NoteStoreGetNoteContentTesterHelper::onGetNoteContentRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteContentTesterHelper::getNoteContentRequestReady, + &server, + &NoteStoreServer::onGetNoteContentRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteContentAsync( + guid, + ctx); + + NoteStoreGetNoteContentAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteContentAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteContentAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteContentAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteContentTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequest, + &helper, + &NoteStoreGetNoteContentTesterHelper::onGetNoteContentRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteContentTesterHelper::getNoteContentRequestReady, + &server, + &NoteStoreServer::onGetNoteContentRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteContentAsync( + guid, + ctx); + + NoteStoreGetNoteContentAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteContentAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteContentAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteContentAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteContentTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequest, + &helper, + &NoteStoreGetNoteContentTesterHelper::onGetNoteContentRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteContentTesterHelper::getNoteContentRequestReady, + &server, + &NoteStoreServer::onGetNoteContentRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteContentRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteContentAsync( + guid, + ctx); + + NoteStoreGetNoteContentAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteContentAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteContentAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetNoteSearchText() +{ + Guid guid = generateRandomString(); + bool noteOnly = generateRandomBool(); + bool tokenizeForIndexing = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QString response = generateRandomString(); + + NoteStoreGetNoteSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + bool noteOnlyParam, + bool tokenizeForIndexingParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteOnly == noteOnlyParam); + Q_ASSERT(tokenizeForIndexing == tokenizeForIndexingParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequest, + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::onGetNoteSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::getNoteSearchTextRequestReady, + &server, + &NoteStoreServer::onGetNoteSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QString res = noteStore->getNoteSearchText( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteSearchText() +{ + Guid guid = generateRandomString(); + bool noteOnly = generateRandomBool(); + bool tokenizeForIndexing = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_MANY; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + bool noteOnlyParam, + bool tokenizeForIndexingParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteOnly == noteOnlyParam); + Q_ASSERT(tokenizeForIndexing == tokenizeForIndexingParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequest, + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::onGetNoteSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::getNoteSearchTextRequestReady, + &server, + &NoteStoreServer::onGetNoteSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getNoteSearchText( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteSearchText() +{ + Guid guid = generateRandomString(); + bool noteOnly = generateRandomBool(); + bool tokenizeForIndexing = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DATA_CONFLICT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + bool noteOnlyParam, + bool tokenizeForIndexingParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteOnly == noteOnlyParam); + Q_ASSERT(tokenizeForIndexing == tokenizeForIndexingParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequest, + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::onGetNoteSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::getNoteSearchTextRequestReady, + &server, + &NoteStoreServer::onGetNoteSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getNoteSearchText( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteSearchText() +{ + Guid guid = generateRandomString(); + bool noteOnly = generateRandomBool(); + bool tokenizeForIndexing = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + bool noteOnlyParam, + bool tokenizeForIndexingParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteOnly == noteOnlyParam); + Q_ASSERT(tokenizeForIndexing == tokenizeForIndexingParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequest, + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::onGetNoteSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::getNoteSearchTextRequestReady, + &server, + &NoteStoreServer::onGetNoteSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getNoteSearchText( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteSearchText() +{ + Guid guid = generateRandomString(); + bool noteOnly = generateRandomBool(); + bool tokenizeForIndexing = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + bool noteOnlyParam, + bool tokenizeForIndexingParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteOnly == noteOnlyParam); + Q_ASSERT(tokenizeForIndexing == tokenizeForIndexingParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequest, + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::onGetNoteSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::getNoteSearchTextRequestReady, + &server, + &NoteStoreServer::onGetNoteSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getNoteSearchText( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetNoteSearchTextAsync() +{ + Guid guid = generateRandomString(); + bool noteOnly = generateRandomBool(); + bool tokenizeForIndexing = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QString response = generateRandomString(); + + NoteStoreGetNoteSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + bool noteOnlyParam, + bool tokenizeForIndexingParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteOnly == noteOnlyParam); + Q_ASSERT(tokenizeForIndexing == tokenizeForIndexingParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequest, + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::onGetNoteSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::getNoteSearchTextRequestReady, + &server, + &NoteStoreServer::onGetNoteSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getNoteSearchTextAsync( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + + NoteStoreGetNoteSearchTextAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteSearchTextAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteSearchTextAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteSearchTextAsync() +{ + Guid guid = generateRandomString(); + bool noteOnly = generateRandomBool(); + bool tokenizeForIndexing = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_AUTH; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + bool noteOnlyParam, + bool tokenizeForIndexingParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteOnly == noteOnlyParam); + Q_ASSERT(tokenizeForIndexing == tokenizeForIndexingParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequest, + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::onGetNoteSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::getNoteSearchTextRequestReady, + &server, + &NoteStoreServer::onGetNoteSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteSearchTextAsync( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + + NoteStoreGetNoteSearchTextAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteSearchTextAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteSearchTextAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteSearchTextAsync() +{ + Guid guid = generateRandomString(); + bool noteOnly = generateRandomBool(); + bool tokenizeForIndexing = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INTERNAL_ERROR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + bool noteOnlyParam, + bool tokenizeForIndexingParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteOnly == noteOnlyParam); + Q_ASSERT(tokenizeForIndexing == tokenizeForIndexingParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequest, + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::onGetNoteSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::getNoteSearchTextRequestReady, + &server, + &NoteStoreServer::onGetNoteSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteSearchTextAsync( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + + NoteStoreGetNoteSearchTextAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteSearchTextAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteSearchTextAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteSearchTextAsync() +{ + Guid guid = generateRandomString(); + bool noteOnly = generateRandomBool(); + bool tokenizeForIndexing = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + bool noteOnlyParam, + bool tokenizeForIndexingParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteOnly == noteOnlyParam); + Q_ASSERT(tokenizeForIndexing == tokenizeForIndexingParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequest, + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::onGetNoteSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::getNoteSearchTextRequestReady, + &server, + &NoteStoreServer::onGetNoteSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteSearchTextAsync( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + + NoteStoreGetNoteSearchTextAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteSearchTextAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteSearchTextAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteSearchTextAsync() +{ + Guid guid = generateRandomString(); + bool noteOnly = generateRandomBool(); + bool tokenizeForIndexing = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + bool noteOnlyParam, + bool tokenizeForIndexingParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteOnly == noteOnlyParam); + Q_ASSERT(tokenizeForIndexing == tokenizeForIndexingParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequest, + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::onGetNoteSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteSearchTextTesterHelper::getNoteSearchTextRequestReady, + &server, + &NoteStoreServer::onGetNoteSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteSearchTextAsync( + guid, + noteOnly, + tokenizeForIndexing, + ctx); + + NoteStoreGetNoteSearchTextAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteSearchTextAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteSearchTextAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetResourceSearchText() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QString response = generateRandomString(); + + NoteStoreGetResourceSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequest, + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::onGetResourceSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::getResourceSearchTextRequestReady, + &server, + &NoteStoreServer::onGetResourceSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QString res = noteStore->getResourceSearchText( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceSearchText() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequest, + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::onGetResourceSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::getResourceSearchTextRequestReady, + &server, + &NoteStoreServer::onGetResourceSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getResourceSearchText( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceSearchText() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::QUOTA_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequest, + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::onGetResourceSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::getResourceSearchTextRequestReady, + &server, + &NoteStoreServer::onGetResourceSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getResourceSearchText( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceSearchText() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequest, + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::onGetResourceSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::getResourceSearchTextRequestReady, + &server, + &NoteStoreServer::onGetResourceSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getResourceSearchText( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceSearchText() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequest, + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::onGetResourceSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::getResourceSearchTextRequestReady, + &server, + &NoteStoreServer::onGetResourceSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getResourceSearchText( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetResourceSearchTextAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QString response = generateRandomString(); + + NoteStoreGetResourceSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequest, + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::onGetResourceSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::getResourceSearchTextRequestReady, + &server, + &NoteStoreServer::onGetResourceSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getResourceSearchTextAsync( + guid, + ctx); + + NoteStoreGetResourceSearchTextAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceSearchTextAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceSearchTextAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceSearchTextAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::AUTH_EXPIRED; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequest, + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::onGetResourceSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::getResourceSearchTextRequestReady, + &server, + &NoteStoreServer::onGetResourceSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceSearchTextAsync( + guid, + ctx); + + NoteStoreGetResourceSearchTextAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceSearchTextAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceSearchTextAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceSearchTextAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DATA_CONFLICT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequest, + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::onGetResourceSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::getResourceSearchTextRequestReady, + &server, + &NoteStoreServer::onGetResourceSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceSearchTextAsync( + guid, + ctx); + + NoteStoreGetResourceSearchTextAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceSearchTextAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceSearchTextAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceSearchTextAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequest, + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::onGetResourceSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::getResourceSearchTextRequestReady, + &server, + &NoteStoreServer::onGetResourceSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceSearchTextAsync( + guid, + ctx); + + NoteStoreGetResourceSearchTextAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceSearchTextAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceSearchTextAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceSearchTextAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceSearchTextTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequest, + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::onGetResourceSearchTextRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceSearchTextTesterHelper::getResourceSearchTextRequestReady, + &server, + &NoteStoreServer::onGetResourceSearchTextRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceSearchTextRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceSearchTextAsync( + guid, + ctx); + + NoteStoreGetResourceSearchTextAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceSearchTextAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceSearchTextAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetNoteTagNames() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QStringList response; + response << generateRandomString(); + response << generateRandomString(); + response << generateRandomString(); + + NoteStoreGetNoteTagNamesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QStringList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequest, + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::onGetNoteTagNamesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::getNoteTagNamesRequestReady, + &server, + &NoteStoreServer::onGetNoteTagNamesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QStringList res = noteStore->getNoteTagNames( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteTagNames() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteTagNamesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QStringList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequest, + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::onGetNoteTagNamesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::getNoteTagNamesRequestReady, + &server, + &NoteStoreServer::onGetNoteTagNamesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QStringList res = noteStore->getNoteTagNames( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteTagNames() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteTagNamesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QStringList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequest, + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::onGetNoteTagNamesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::getNoteTagNamesRequestReady, + &server, + &NoteStoreServer::onGetNoteTagNamesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QStringList res = noteStore->getNoteTagNames( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteTagNames() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteTagNamesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QStringList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequest, + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::onGetNoteTagNamesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::getNoteTagNamesRequestReady, + &server, + &NoteStoreServer::onGetNoteTagNamesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QStringList res = noteStore->getNoteTagNames( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteTagNames() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteTagNamesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QStringList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequest, + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::onGetNoteTagNamesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::getNoteTagNamesRequestReady, + &server, + &NoteStoreServer::onGetNoteTagNamesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QStringList res = noteStore->getNoteTagNames( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetNoteTagNamesAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QStringList response; + response << generateRandomString(); + response << generateRandomString(); + response << generateRandomString(); + + NoteStoreGetNoteTagNamesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QStringList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequest, + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::onGetNoteTagNamesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::getNoteTagNamesRequestReady, + &server, + &NoteStoreServer::onGetNoteTagNamesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getNoteTagNamesAsync( + guid, + ctx); + + NoteStoreGetNoteTagNamesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteTagNamesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteTagNamesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteTagNamesAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteTagNamesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QStringList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequest, + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::onGetNoteTagNamesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::getNoteTagNamesRequestReady, + &server, + &NoteStoreServer::onGetNoteTagNamesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteTagNamesAsync( + guid, + ctx); + + NoteStoreGetNoteTagNamesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteTagNamesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteTagNamesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteTagNamesAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteTagNamesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QStringList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequest, + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::onGetNoteTagNamesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::getNoteTagNamesRequestReady, + &server, + &NoteStoreServer::onGetNoteTagNamesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteTagNamesAsync( + guid, + ctx); + + NoteStoreGetNoteTagNamesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteTagNamesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteTagNamesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteTagNamesAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteTagNamesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QStringList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequest, + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::onGetNoteTagNamesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::getNoteTagNamesRequestReady, + &server, + &NoteStoreServer::onGetNoteTagNamesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteTagNamesAsync( + guid, + ctx); + + NoteStoreGetNoteTagNamesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteTagNamesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteTagNamesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteTagNamesAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteTagNamesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QStringList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequest, + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::onGetNoteTagNamesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteTagNamesTesterHelper::getNoteTagNamesRequestReady, + &server, + &NoteStoreServer::onGetNoteTagNamesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteTagNamesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteTagNamesAsync( + guid, + ctx); + + NoteStoreGetNoteTagNamesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteTagNamesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteTagNamesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteCreateNote() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Note response = generateRandomNote(); + + NoteStoreCreateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNoteRequest, + &helper, + &NoteStoreCreateNoteTesterHelper::onCreateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNoteTesterHelper::createNoteRequestReady, + &server, + &NoteStoreServer::onCreateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Note res = noteStore->createNote( + note, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCreateNote() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::QUOTA_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreCreateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNoteRequest, + &helper, + &NoteStoreCreateNoteTesterHelper::onCreateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNoteTesterHelper::createNoteRequestReady, + &server, + &NoteStoreServer::onCreateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->createNote( + note, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCreateNote() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_NOT_REGISTERED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCreateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNoteRequest, + &helper, + &NoteStoreCreateNoteTesterHelper::onCreateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNoteTesterHelper::createNoteRequestReady, + &server, + &NoteStoreServer::onCreateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->createNote( + note, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInCreateNote() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreCreateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNoteRequest, + &helper, + &NoteStoreCreateNoteTesterHelper::onCreateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNoteTesterHelper::createNoteRequestReady, + &server, + &NoteStoreServer::onCreateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->createNote( + note, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCreateNote() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCreateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNoteRequest, + &helper, + &NoteStoreCreateNoteTesterHelper::onCreateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNoteTesterHelper::createNoteRequestReady, + &server, + &NoteStoreServer::onCreateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->createNote( + note, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteCreateNoteAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Note response = generateRandomNote(); + + NoteStoreCreateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNoteRequest, + &helper, + &NoteStoreCreateNoteTesterHelper::onCreateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNoteTesterHelper::createNoteRequestReady, + &server, + &NoteStoreServer::onCreateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->createNoteAsync( + note, + ctx); + + NoteStoreCreateNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCreateNoteAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::OPENID_ALREADY_TAKEN; + userException.parameter = generateRandomString(); + + NoteStoreCreateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNoteRequest, + &helper, + &NoteStoreCreateNoteTesterHelper::onCreateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNoteTesterHelper::createNoteRequestReady, + &server, + &NoteStoreServer::onCreateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createNoteAsync( + note, + ctx); + + NoteStoreCreateNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCreateNoteAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCreateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNoteRequest, + &helper, + &NoteStoreCreateNoteTesterHelper::onCreateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNoteTesterHelper::createNoteRequestReady, + &server, + &NoteStoreServer::onCreateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createNoteAsync( + note, + ctx); + + NoteStoreCreateNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInCreateNoteAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreCreateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNoteRequest, + &helper, + &NoteStoreCreateNoteTesterHelper::onCreateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNoteTesterHelper::createNoteRequestReady, + &server, + &NoteStoreServer::onCreateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createNoteAsync( + note, + ctx); + + NoteStoreCreateNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCreateNoteAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCreateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createNoteRequest, + &helper, + &NoteStoreCreateNoteTesterHelper::onCreateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateNoteTesterHelper::createNoteRequestReady, + &server, + &NoteStoreServer::onCreateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createNoteAsync( + note, + ctx); + + NoteStoreCreateNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteUpdateNote() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Note response = generateRandomNote(); + + NoteStoreUpdateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequest, + &helper, + &NoteStoreUpdateNoteTesterHelper::onUpdateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteTesterHelper::updateNoteRequestReady, + &server, + &NoteStoreServer::onUpdateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Note res = noteStore->updateNote( + note, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateNote() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + userException.parameter = generateRandomString(); + + NoteStoreUpdateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequest, + &helper, + &NoteStoreUpdateNoteTesterHelper::onUpdateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteTesterHelper::updateNoteRequestReady, + &server, + &NoteStoreServer::onUpdateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->updateNote( + note, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateNote() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequest, + &helper, + &NoteStoreUpdateNoteTesterHelper::onUpdateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteTesterHelper::updateNoteRequestReady, + &server, + &NoteStoreServer::onUpdateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->updateNote( + note, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateNote() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequest, + &helper, + &NoteStoreUpdateNoteTesterHelper::onUpdateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteTesterHelper::updateNoteRequestReady, + &server, + &NoteStoreServer::onUpdateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->updateNote( + note, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateNote() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequest, + &helper, + &NoteStoreUpdateNoteTesterHelper::onUpdateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteTesterHelper::updateNoteRequestReady, + &server, + &NoteStoreServer::onUpdateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->updateNote( + note, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteUpdateNoteAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Note response = generateRandomNote(); + + NoteStoreUpdateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequest, + &helper, + &NoteStoreUpdateNoteTesterHelper::onUpdateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteTesterHelper::updateNoteRequestReady, + &server, + &NoteStoreServer::onUpdateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->updateNoteAsync( + note, + ctx); + + NoteStoreUpdateNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateNoteAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreUpdateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequest, + &helper, + &NoteStoreUpdateNoteTesterHelper::onUpdateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteTesterHelper::updateNoteRequestReady, + &server, + &NoteStoreServer::onUpdateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateNoteAsync( + note, + ctx); + + NoteStoreUpdateNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateNoteAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ENML_VALIDATION; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequest, + &helper, + &NoteStoreUpdateNoteTesterHelper::onUpdateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteTesterHelper::updateNoteRequestReady, + &server, + &NoteStoreServer::onUpdateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateNoteAsync( + note, + ctx); + + NoteStoreUpdateNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateNoteAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequest, + &helper, + &NoteStoreUpdateNoteTesterHelper::onUpdateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteTesterHelper::updateNoteRequestReady, + &server, + &NoteStoreServer::onUpdateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateNoteAsync( + note, + ctx); + + NoteStoreUpdateNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateNoteAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateNoteTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequest, + &helper, + &NoteStoreUpdateNoteTesterHelper::onUpdateNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteTesterHelper::updateNoteRequestReady, + &server, + &NoteStoreServer::onUpdateNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateNoteAsync( + note, + ctx); + + NoteStoreUpdateNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteDeleteNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreDeleteNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequest, + &helper, + &NoteStoreDeleteNoteTesterHelper::onDeleteNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreDeleteNoteTesterHelper::deleteNoteRequestReady, + &server, + &NoteStoreServer::onDeleteNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->deleteNote( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInDeleteNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_ASSOCIATED; + userException.parameter = generateRandomString(); + + NoteStoreDeleteNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequest, + &helper, + &NoteStoreDeleteNoteTesterHelper::onDeleteNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreDeleteNoteTesterHelper::deleteNoteRequestReady, + &server, + &NoteStoreServer::onDeleteNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->deleteNote( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInDeleteNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreDeleteNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequest, + &helper, + &NoteStoreDeleteNoteTesterHelper::onDeleteNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreDeleteNoteTesterHelper::deleteNoteRequestReady, + &server, + &NoteStoreServer::onDeleteNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->deleteNote( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInDeleteNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreDeleteNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequest, + &helper, + &NoteStoreDeleteNoteTesterHelper::onDeleteNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreDeleteNoteTesterHelper::deleteNoteRequestReady, + &server, + &NoteStoreServer::onDeleteNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->deleteNote( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInDeleteNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreDeleteNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequest, + &helper, + &NoteStoreDeleteNoteTesterHelper::onDeleteNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreDeleteNoteTesterHelper::deleteNoteRequestReady, + &server, + &NoteStoreServer::onDeleteNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->deleteNote( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteDeleteNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreDeleteNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequest, + &helper, + &NoteStoreDeleteNoteTesterHelper::onDeleteNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreDeleteNoteTesterHelper::deleteNoteRequestReady, + &server, + &NoteStoreServer::onDeleteNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->deleteNoteAsync( + guid, + ctx); + + NoteStoreDeleteNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreDeleteNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreDeleteNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInDeleteNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_ASSOCIATED; + userException.parameter = generateRandomString(); + + NoteStoreDeleteNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequest, + &helper, + &NoteStoreDeleteNoteTesterHelper::onDeleteNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreDeleteNoteTesterHelper::deleteNoteRequestReady, + &server, + &NoteStoreServer::onDeleteNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->deleteNoteAsync( + guid, + ctx); + + NoteStoreDeleteNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreDeleteNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreDeleteNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInDeleteNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreDeleteNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequest, + &helper, + &NoteStoreDeleteNoteTesterHelper::onDeleteNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreDeleteNoteTesterHelper::deleteNoteRequestReady, + &server, + &NoteStoreServer::onDeleteNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->deleteNoteAsync( + guid, + ctx); + + NoteStoreDeleteNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreDeleteNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreDeleteNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInDeleteNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreDeleteNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequest, + &helper, + &NoteStoreDeleteNoteTesterHelper::onDeleteNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreDeleteNoteTesterHelper::deleteNoteRequestReady, + &server, + &NoteStoreServer::onDeleteNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->deleteNoteAsync( + guid, + ctx); + + NoteStoreDeleteNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreDeleteNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreDeleteNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInDeleteNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreDeleteNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequest, + &helper, + &NoteStoreDeleteNoteTesterHelper::onDeleteNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreDeleteNoteTesterHelper::deleteNoteRequestReady, + &server, + &NoteStoreServer::onDeleteNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::deleteNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->deleteNoteAsync( + guid, + ctx); + + NoteStoreDeleteNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreDeleteNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreDeleteNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteExpungeNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreExpungeNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequest, + &helper, + &NoteStoreExpungeNoteTesterHelper::onExpungeNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNoteTesterHelper::expungeNoteRequestReady, + &server, + &NoteStoreServer::onExpungeNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->expungeNote( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInExpungeNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreExpungeNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequest, + &helper, + &NoteStoreExpungeNoteTesterHelper::onExpungeNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNoteTesterHelper::expungeNoteRequestReady, + &server, + &NoteStoreServer::onExpungeNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeNote( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInExpungeNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::OPENID_ALREADY_TAKEN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreExpungeNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequest, + &helper, + &NoteStoreExpungeNoteTesterHelper::onExpungeNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNoteTesterHelper::expungeNoteRequestReady, + &server, + &NoteStoreServer::onExpungeNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeNote( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInExpungeNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreExpungeNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequest, + &helper, + &NoteStoreExpungeNoteTesterHelper::onExpungeNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNoteTesterHelper::expungeNoteRequestReady, + &server, + &NoteStoreServer::onExpungeNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeNote( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInExpungeNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreExpungeNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequest, + &helper, + &NoteStoreExpungeNoteTesterHelper::onExpungeNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNoteTesterHelper::expungeNoteRequestReady, + &server, + &NoteStoreServer::onExpungeNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeNote( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteExpungeNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreExpungeNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequest, + &helper, + &NoteStoreExpungeNoteTesterHelper::onExpungeNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNoteTesterHelper::expungeNoteRequestReady, + &server, + &NoteStoreServer::onExpungeNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->expungeNoteAsync( + guid, + ctx); + + NoteStoreExpungeNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInExpungeNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + userException.parameter = generateRandomString(); + + NoteStoreExpungeNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequest, + &helper, + &NoteStoreExpungeNoteTesterHelper::onExpungeNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNoteTesterHelper::expungeNoteRequestReady, + &server, + &NoteStoreServer::onExpungeNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeNoteAsync( + guid, + ctx); + + NoteStoreExpungeNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInExpungeNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreExpungeNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequest, + &helper, + &NoteStoreExpungeNoteTesterHelper::onExpungeNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNoteTesterHelper::expungeNoteRequestReady, + &server, + &NoteStoreServer::onExpungeNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeNoteAsync( + guid, + ctx); + + NoteStoreExpungeNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInExpungeNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreExpungeNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequest, + &helper, + &NoteStoreExpungeNoteTesterHelper::onExpungeNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNoteTesterHelper::expungeNoteRequestReady, + &server, + &NoteStoreServer::onExpungeNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeNoteAsync( + guid, + ctx); + + NoteStoreExpungeNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInExpungeNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreExpungeNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequest, + &helper, + &NoteStoreExpungeNoteTesterHelper::onExpungeNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeNoteTesterHelper::expungeNoteRequestReady, + &server, + &NoteStoreServer::onExpungeNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeNoteAsync( + guid, + ctx); + + NoteStoreExpungeNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteCopyNote() +{ + Guid noteGuid = generateRandomString(); + Guid toNotebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Note response = generateRandomNote(); + + NoteStoreCopyNoteTesterHelper helper( + [&] (const Guid & noteGuidParam, + const Guid & toNotebookGuidParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(toNotebookGuid == toNotebookGuidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequest, + &helper, + &NoteStoreCopyNoteTesterHelper::onCopyNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCopyNoteTesterHelper::copyNoteRequestReady, + &server, + &NoteStoreServer::onCopyNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Note res = noteStore->copyNote( + noteGuid, + toNotebookGuid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCopyNote() +{ + Guid noteGuid = generateRandomString(); + Guid toNotebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + userException.parameter = generateRandomString(); + + NoteStoreCopyNoteTesterHelper helper( + [&] (const Guid & noteGuidParam, + const Guid & toNotebookGuidParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(toNotebookGuid == toNotebookGuidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequest, + &helper, + &NoteStoreCopyNoteTesterHelper::onCopyNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCopyNoteTesterHelper::copyNoteRequestReady, + &server, + &NoteStoreServer::onCopyNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->copyNote( + noteGuid, + toNotebookGuid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCopyNote() +{ + Guid noteGuid = generateRandomString(); + Guid toNotebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::OPENID_ALREADY_TAKEN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCopyNoteTesterHelper helper( + [&] (const Guid & noteGuidParam, + const Guid & toNotebookGuidParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(toNotebookGuid == toNotebookGuidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequest, + &helper, + &NoteStoreCopyNoteTesterHelper::onCopyNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCopyNoteTesterHelper::copyNoteRequestReady, + &server, + &NoteStoreServer::onCopyNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->copyNote( + noteGuid, + toNotebookGuid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInCopyNote() +{ + Guid noteGuid = generateRandomString(); + Guid toNotebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreCopyNoteTesterHelper helper( + [&] (const Guid & noteGuidParam, + const Guid & toNotebookGuidParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(toNotebookGuid == toNotebookGuidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequest, + &helper, + &NoteStoreCopyNoteTesterHelper::onCopyNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCopyNoteTesterHelper::copyNoteRequestReady, + &server, + &NoteStoreServer::onCopyNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->copyNote( + noteGuid, + toNotebookGuid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCopyNote() +{ + Guid noteGuid = generateRandomString(); + Guid toNotebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCopyNoteTesterHelper helper( + [&] (const Guid & noteGuidParam, + const Guid & toNotebookGuidParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(toNotebookGuid == toNotebookGuidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequest, + &helper, + &NoteStoreCopyNoteTesterHelper::onCopyNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCopyNoteTesterHelper::copyNoteRequestReady, + &server, + &NoteStoreServer::onCopyNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->copyNote( + noteGuid, + toNotebookGuid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteCopyNoteAsync() +{ + Guid noteGuid = generateRandomString(); + Guid toNotebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Note response = generateRandomNote(); + + NoteStoreCopyNoteTesterHelper helper( + [&] (const Guid & noteGuidParam, + const Guid & toNotebookGuidParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(toNotebookGuid == toNotebookGuidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequest, + &helper, + &NoteStoreCopyNoteTesterHelper::onCopyNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCopyNoteTesterHelper::copyNoteRequestReady, + &server, + &NoteStoreServer::onCopyNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->copyNoteAsync( + noteGuid, + toNotebookGuid, + ctx); + + NoteStoreCopyNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCopyNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCopyNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCopyNoteAsync() +{ + Guid noteGuid = generateRandomString(); + Guid toNotebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + userException.parameter = generateRandomString(); + + NoteStoreCopyNoteTesterHelper helper( + [&] (const Guid & noteGuidParam, + const Guid & toNotebookGuidParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(toNotebookGuid == toNotebookGuidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequest, + &helper, + &NoteStoreCopyNoteTesterHelper::onCopyNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCopyNoteTesterHelper::copyNoteRequestReady, + &server, + &NoteStoreServer::onCopyNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->copyNoteAsync( + noteGuid, + toNotebookGuid, + ctx); + + NoteStoreCopyNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCopyNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCopyNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCopyNoteAsync() +{ + Guid noteGuid = generateRandomString(); + Guid toNotebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCopyNoteTesterHelper helper( + [&] (const Guid & noteGuidParam, + const Guid & toNotebookGuidParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(toNotebookGuid == toNotebookGuidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequest, + &helper, + &NoteStoreCopyNoteTesterHelper::onCopyNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCopyNoteTesterHelper::copyNoteRequestReady, + &server, + &NoteStoreServer::onCopyNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->copyNoteAsync( + noteGuid, + toNotebookGuid, + ctx); + + NoteStoreCopyNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCopyNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCopyNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInCopyNoteAsync() +{ + Guid noteGuid = generateRandomString(); + Guid toNotebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreCopyNoteTesterHelper helper( + [&] (const Guid & noteGuidParam, + const Guid & toNotebookGuidParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(toNotebookGuid == toNotebookGuidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequest, + &helper, + &NoteStoreCopyNoteTesterHelper::onCopyNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCopyNoteTesterHelper::copyNoteRequestReady, + &server, + &NoteStoreServer::onCopyNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->copyNoteAsync( + noteGuid, + toNotebookGuid, + ctx); + + NoteStoreCopyNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCopyNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCopyNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCopyNoteAsync() +{ + Guid noteGuid = generateRandomString(); + Guid toNotebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCopyNoteTesterHelper helper( + [&] (const Guid & noteGuidParam, + const Guid & toNotebookGuidParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(toNotebookGuid == toNotebookGuidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequest, + &helper, + &NoteStoreCopyNoteTesterHelper::onCopyNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreCopyNoteTesterHelper::copyNoteRequestReady, + &server, + &NoteStoreServer::onCopyNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::copyNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->copyNoteAsync( + noteGuid, + toNotebookGuid, + ctx); + + NoteStoreCopyNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCopyNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCopyNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteListNoteVersions() +{ + Guid noteGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomNoteVersionId(); + response << generateRandomNoteVersionId(); + response << generateRandomNoteVersionId(); + + NoteStoreListNoteVersionsTesterHelper helper( + [&] (const Guid & noteGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequest, + &helper, + &NoteStoreListNoteVersionsTesterHelper::onListNoteVersionsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNoteVersionsTesterHelper::listNoteVersionsRequestReady, + &server, + &NoteStoreServer::onListNoteVersionsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QList res = noteStore->listNoteVersions( + noteGuid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListNoteVersions() +{ + Guid noteGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + userException.parameter = generateRandomString(); + + NoteStoreListNoteVersionsTesterHelper helper( + [&] (const Guid & noteGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequest, + &helper, + &NoteStoreListNoteVersionsTesterHelper::onListNoteVersionsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNoteVersionsTesterHelper::listNoteVersionsRequestReady, + &server, + &NoteStoreServer::onListNoteVersionsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listNoteVersions( + noteGuid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListNoteVersions() +{ + Guid noteGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::AUTH_EXPIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListNoteVersionsTesterHelper helper( + [&] (const Guid & noteGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequest, + &helper, + &NoteStoreListNoteVersionsTesterHelper::onListNoteVersionsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNoteVersionsTesterHelper::listNoteVersionsRequestReady, + &server, + &NoteStoreServer::onListNoteVersionsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listNoteVersions( + noteGuid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInListNoteVersions() +{ + Guid noteGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreListNoteVersionsTesterHelper helper( + [&] (const Guid & noteGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequest, + &helper, + &NoteStoreListNoteVersionsTesterHelper::onListNoteVersionsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNoteVersionsTesterHelper::listNoteVersionsRequestReady, + &server, + &NoteStoreServer::onListNoteVersionsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listNoteVersions( + noteGuid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListNoteVersions() +{ + Guid noteGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListNoteVersionsTesterHelper helper( + [&] (const Guid & noteGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequest, + &helper, + &NoteStoreListNoteVersionsTesterHelper::onListNoteVersionsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNoteVersionsTesterHelper::listNoteVersionsRequestReady, + &server, + &NoteStoreServer::onListNoteVersionsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listNoteVersions( + noteGuid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteListNoteVersionsAsync() +{ + Guid noteGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomNoteVersionId(); + response << generateRandomNoteVersionId(); + response << generateRandomNoteVersionId(); + + NoteStoreListNoteVersionsTesterHelper helper( + [&] (const Guid & noteGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequest, + &helper, + &NoteStoreListNoteVersionsTesterHelper::onListNoteVersionsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNoteVersionsTesterHelper::listNoteVersionsRequestReady, + &server, + &NoteStoreServer::onListNoteVersionsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->listNoteVersionsAsync( + noteGuid, + ctx); + + NoteStoreListNoteVersionsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListNoteVersionsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListNoteVersionsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListNoteVersionsAsync() +{ + Guid noteGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_LONG; + userException.parameter = generateRandomString(); + + NoteStoreListNoteVersionsTesterHelper helper( + [&] (const Guid & noteGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequest, + &helper, + &NoteStoreListNoteVersionsTesterHelper::onListNoteVersionsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNoteVersionsTesterHelper::listNoteVersionsRequestReady, + &server, + &NoteStoreServer::onListNoteVersionsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listNoteVersionsAsync( + noteGuid, + ctx); + + NoteStoreListNoteVersionsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListNoteVersionsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListNoteVersionsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListNoteVersionsAsync() +{ + Guid noteGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TAKEN_DOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListNoteVersionsTesterHelper helper( + [&] (const Guid & noteGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequest, + &helper, + &NoteStoreListNoteVersionsTesterHelper::onListNoteVersionsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNoteVersionsTesterHelper::listNoteVersionsRequestReady, + &server, + &NoteStoreServer::onListNoteVersionsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listNoteVersionsAsync( + noteGuid, + ctx); + + NoteStoreListNoteVersionsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListNoteVersionsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListNoteVersionsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInListNoteVersionsAsync() +{ + Guid noteGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreListNoteVersionsTesterHelper helper( + [&] (const Guid & noteGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequest, + &helper, + &NoteStoreListNoteVersionsTesterHelper::onListNoteVersionsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNoteVersionsTesterHelper::listNoteVersionsRequestReady, + &server, + &NoteStoreServer::onListNoteVersionsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listNoteVersionsAsync( + noteGuid, + ctx); + + NoteStoreListNoteVersionsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListNoteVersionsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListNoteVersionsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListNoteVersionsAsync() +{ + Guid noteGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListNoteVersionsTesterHelper helper( + [&] (const Guid & noteGuidParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequest, + &helper, + &NoteStoreListNoteVersionsTesterHelper::onListNoteVersionsRequestReceived); + QObject::connect( + &helper, + &NoteStoreListNoteVersionsTesterHelper::listNoteVersionsRequestReady, + &server, + &NoteStoreServer::onListNoteVersionsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listNoteVersionsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listNoteVersionsAsync( + noteGuid, + ctx); + + NoteStoreListNoteVersionsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListNoteVersionsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListNoteVersionsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetNoteVersion() +{ + Guid noteGuid = generateRandomString(); + qint32 updateSequenceNum = generateRandomInt32(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Note response = generateRandomNote(); + + NoteStoreGetNoteVersionTesterHelper helper( + [&] (const Guid & noteGuidParam, + qint32 updateSequenceNumParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(updateSequenceNum == updateSequenceNumParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequest, + &helper, + &NoteStoreGetNoteVersionTesterHelper::onGetNoteVersionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteVersionTesterHelper::getNoteVersionRequestReady, + &server, + &NoteStoreServer::onGetNoteVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Note res = noteStore->getNoteVersion( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteVersion() +{ + Guid noteGuid = generateRandomString(); + qint32 updateSequenceNum = generateRandomInt32(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_FEW; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteVersionTesterHelper helper( + [&] (const Guid & noteGuidParam, + qint32 updateSequenceNumParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(updateSequenceNum == updateSequenceNumParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequest, + &helper, + &NoteStoreGetNoteVersionTesterHelper::onGetNoteVersionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteVersionTesterHelper::getNoteVersionRequestReady, + &server, + &NoteStoreServer::onGetNoteVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->getNoteVersion( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteVersion() +{ + Guid noteGuid = generateRandomString(); + qint32 updateSequenceNum = generateRandomInt32(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::OPENID_ALREADY_TAKEN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteVersionTesterHelper helper( + [&] (const Guid & noteGuidParam, + qint32 updateSequenceNumParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(updateSequenceNum == updateSequenceNumParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequest, + &helper, + &NoteStoreGetNoteVersionTesterHelper::onGetNoteVersionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteVersionTesterHelper::getNoteVersionRequestReady, + &server, + &NoteStoreServer::onGetNoteVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->getNoteVersion( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteVersion() +{ + Guid noteGuid = generateRandomString(); + qint32 updateSequenceNum = generateRandomInt32(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteVersionTesterHelper helper( + [&] (const Guid & noteGuidParam, + qint32 updateSequenceNumParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(updateSequenceNum == updateSequenceNumParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequest, + &helper, + &NoteStoreGetNoteVersionTesterHelper::onGetNoteVersionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteVersionTesterHelper::getNoteVersionRequestReady, + &server, + &NoteStoreServer::onGetNoteVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->getNoteVersion( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteVersion() +{ + Guid noteGuid = generateRandomString(); + qint32 updateSequenceNum = generateRandomInt32(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteVersionTesterHelper helper( + [&] (const Guid & noteGuidParam, + qint32 updateSequenceNumParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(updateSequenceNum == updateSequenceNumParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequest, + &helper, + &NoteStoreGetNoteVersionTesterHelper::onGetNoteVersionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteVersionTesterHelper::getNoteVersionRequestReady, + &server, + &NoteStoreServer::onGetNoteVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Note res = noteStore->getNoteVersion( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetNoteVersionAsync() +{ + Guid noteGuid = generateRandomString(); + qint32 updateSequenceNum = generateRandomInt32(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Note response = generateRandomNote(); + + NoteStoreGetNoteVersionTesterHelper helper( + [&] (const Guid & noteGuidParam, + qint32 updateSequenceNumParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(updateSequenceNum == updateSequenceNumParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequest, + &helper, + &NoteStoreGetNoteVersionTesterHelper::onGetNoteVersionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteVersionTesterHelper::getNoteVersionRequestReady, + &server, + &NoteStoreServer::onGetNoteVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getNoteVersionAsync( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + NoteStoreGetNoteVersionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteVersionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteVersionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNoteVersionAsync() +{ + Guid noteGuid = generateRandomString(); + qint32 updateSequenceNum = generateRandomInt32(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + userException.parameter = generateRandomString(); + + NoteStoreGetNoteVersionTesterHelper helper( + [&] (const Guid & noteGuidParam, + qint32 updateSequenceNumParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(updateSequenceNum == updateSequenceNumParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequest, + &helper, + &NoteStoreGetNoteVersionTesterHelper::onGetNoteVersionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteVersionTesterHelper::getNoteVersionRequestReady, + &server, + &NoteStoreServer::onGetNoteVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteVersionAsync( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + NoteStoreGetNoteVersionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteVersionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteVersionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNoteVersionAsync() +{ + Guid noteGuid = generateRandomString(); + qint32 updateSequenceNum = generateRandomInt32(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DATA_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNoteVersionTesterHelper helper( + [&] (const Guid & noteGuidParam, + qint32 updateSequenceNumParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(updateSequenceNum == updateSequenceNumParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequest, + &helper, + &NoteStoreGetNoteVersionTesterHelper::onGetNoteVersionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteVersionTesterHelper::getNoteVersionRequestReady, + &server, + &NoteStoreServer::onGetNoteVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteVersionAsync( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + NoteStoreGetNoteVersionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteVersionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteVersionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNoteVersionAsync() +{ + Guid noteGuid = generateRandomString(); + qint32 updateSequenceNum = generateRandomInt32(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNoteVersionTesterHelper helper( + [&] (const Guid & noteGuidParam, + qint32 updateSequenceNumParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(updateSequenceNum == updateSequenceNumParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequest, + &helper, + &NoteStoreGetNoteVersionTesterHelper::onGetNoteVersionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteVersionTesterHelper::getNoteVersionRequestReady, + &server, + &NoteStoreServer::onGetNoteVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteVersionAsync( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + NoteStoreGetNoteVersionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteVersionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteVersionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNoteVersionAsync() +{ + Guid noteGuid = generateRandomString(); + qint32 updateSequenceNum = generateRandomInt32(); + bool withResourcesData = generateRandomBool(); + bool withResourcesRecognition = generateRandomBool(); + bool withResourcesAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNoteVersionTesterHelper helper( + [&] (const Guid & noteGuidParam, + qint32 updateSequenceNumParam, + bool withResourcesDataParam, + bool withResourcesRecognitionParam, + bool withResourcesAlternateDataParam, + IRequestContextPtr ctxParam) -> Note + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(updateSequenceNum == updateSequenceNumParam); + Q_ASSERT(withResourcesData == withResourcesDataParam); + Q_ASSERT(withResourcesRecognition == withResourcesRecognitionParam); + Q_ASSERT(withResourcesAlternateData == withResourcesAlternateDataParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequest, + &helper, + &NoteStoreGetNoteVersionTesterHelper::onGetNoteVersionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNoteVersionTesterHelper::getNoteVersionRequestReady, + &server, + &NoteStoreServer::onGetNoteVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNoteVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNoteVersionAsync( + noteGuid, + updateSequenceNum, + withResourcesData, + withResourcesRecognition, + withResourcesAlternateData, + ctx); + + NoteStoreGetNoteVersionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNoteVersionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNoteVersionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetResource() +{ + Guid guid = generateRandomString(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAttributes = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Resource response = generateRandomResource(); + + NoteStoreGetResourceTesterHelper helper( + [&] (const Guid & guidParam, + bool withDataParam, + bool withRecognitionParam, + bool withAttributesParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAttributes == withAttributesParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRequest, + &helper, + &NoteStoreGetResourceTesterHelper::onGetResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceTesterHelper::getResourceRequestReady, + &server, + &NoteStoreServer::onGetResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Resource res = noteStore->getResource( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResource() +{ + Guid guid = generateRandomString(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAttributes = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceTesterHelper helper( + [&] (const Guid & guidParam, + bool withDataParam, + bool withRecognitionParam, + bool withAttributesParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAttributes == withAttributesParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRequest, + &helper, + &NoteStoreGetResourceTesterHelper::onGetResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceTesterHelper::getResourceRequestReady, + &server, + &NoteStoreServer::onGetResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Resource res = noteStore->getResource( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResource() +{ + Guid guid = generateRandomString(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAttributes = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_AUTH; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceTesterHelper helper( + [&] (const Guid & guidParam, + bool withDataParam, + bool withRecognitionParam, + bool withAttributesParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAttributes == withAttributesParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRequest, + &helper, + &NoteStoreGetResourceTesterHelper::onGetResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceTesterHelper::getResourceRequestReady, + &server, + &NoteStoreServer::onGetResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Resource res = noteStore->getResource( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResource() +{ + Guid guid = generateRandomString(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAttributes = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceTesterHelper helper( + [&] (const Guid & guidParam, + bool withDataParam, + bool withRecognitionParam, + bool withAttributesParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAttributes == withAttributesParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRequest, + &helper, + &NoteStoreGetResourceTesterHelper::onGetResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceTesterHelper::getResourceRequestReady, + &server, + &NoteStoreServer::onGetResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Resource res = noteStore->getResource( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResource() +{ + Guid guid = generateRandomString(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAttributes = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceTesterHelper helper( + [&] (const Guid & guidParam, + bool withDataParam, + bool withRecognitionParam, + bool withAttributesParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAttributes == withAttributesParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRequest, + &helper, + &NoteStoreGetResourceTesterHelper::onGetResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceTesterHelper::getResourceRequestReady, + &server, + &NoteStoreServer::onGetResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Resource res = noteStore->getResource( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetResourceAsync() +{ + Guid guid = generateRandomString(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAttributes = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Resource response = generateRandomResource(); + + NoteStoreGetResourceTesterHelper helper( + [&] (const Guid & guidParam, + bool withDataParam, + bool withRecognitionParam, + bool withAttributesParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAttributes == withAttributesParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRequest, + &helper, + &NoteStoreGetResourceTesterHelper::onGetResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceTesterHelper::getResourceRequestReady, + &server, + &NoteStoreServer::onGetResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getResourceAsync( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + + NoteStoreGetResourceAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceAsync() +{ + Guid guid = generateRandomString(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAttributes = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_REGISTERED; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceTesterHelper helper( + [&] (const Guid & guidParam, + bool withDataParam, + bool withRecognitionParam, + bool withAttributesParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAttributes == withAttributesParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRequest, + &helper, + &NoteStoreGetResourceTesterHelper::onGetResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceTesterHelper::getResourceRequestReady, + &server, + &NoteStoreServer::onGetResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceAsync( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + + NoteStoreGetResourceAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceAsync() +{ + Guid guid = generateRandomString(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAttributes = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceTesterHelper helper( + [&] (const Guid & guidParam, + bool withDataParam, + bool withRecognitionParam, + bool withAttributesParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAttributes == withAttributesParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRequest, + &helper, + &NoteStoreGetResourceTesterHelper::onGetResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceTesterHelper::getResourceRequestReady, + &server, + &NoteStoreServer::onGetResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceAsync( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + + NoteStoreGetResourceAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceAsync() +{ + Guid guid = generateRandomString(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAttributes = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceTesterHelper helper( + [&] (const Guid & guidParam, + bool withDataParam, + bool withRecognitionParam, + bool withAttributesParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAttributes == withAttributesParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRequest, + &helper, + &NoteStoreGetResourceTesterHelper::onGetResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceTesterHelper::getResourceRequestReady, + &server, + &NoteStoreServer::onGetResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceAsync( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + + NoteStoreGetResourceAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceAsync() +{ + Guid guid = generateRandomString(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAttributes = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceTesterHelper helper( + [&] (const Guid & guidParam, + bool withDataParam, + bool withRecognitionParam, + bool withAttributesParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAttributes == withAttributesParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRequest, + &helper, + &NoteStoreGetResourceTesterHelper::onGetResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceTesterHelper::getResourceRequestReady, + &server, + &NoteStoreServer::onGetResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceAsync( + guid, + withData, + withRecognition, + withAttributes, + withAlternateData, + ctx); + + NoteStoreGetResourceAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetResourceApplicationData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + LazyMap response = generateRandomLazyMap(); + + NoteStoreGetResourceApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequest, + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::onGetResourceApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::getResourceApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + LazyMap res = noteStore->getResourceApplicationData( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceApplicationData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequest, + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::onGetResourceApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::getResourceApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + LazyMap res = noteStore->getResourceApplicationData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceApplicationData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequest, + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::onGetResourceApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::getResourceApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + LazyMap res = noteStore->getResourceApplicationData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceApplicationData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequest, + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::onGetResourceApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::getResourceApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + LazyMap res = noteStore->getResourceApplicationData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceApplicationData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequest, + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::onGetResourceApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::getResourceApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + LazyMap res = noteStore->getResourceApplicationData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetResourceApplicationDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + LazyMap response = generateRandomLazyMap(); + + NoteStoreGetResourceApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequest, + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::onGetResourceApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::getResourceApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getResourceApplicationDataAsync( + guid, + ctx); + + NoteStoreGetResourceApplicationDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceApplicationDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceApplicationDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceApplicationDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequest, + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::onGetResourceApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::getResourceApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceApplicationDataAsync( + guid, + ctx); + + NoteStoreGetResourceApplicationDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceApplicationDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceApplicationDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceApplicationDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TOO_FEW; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequest, + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::onGetResourceApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::getResourceApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceApplicationDataAsync( + guid, + ctx); + + NoteStoreGetResourceApplicationDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceApplicationDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceApplicationDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceApplicationDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequest, + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::onGetResourceApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::getResourceApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceApplicationDataAsync( + guid, + ctx); + + NoteStoreGetResourceApplicationDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceApplicationDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceApplicationDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceApplicationDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceApplicationDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> LazyMap + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequest, + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::onGetResourceApplicationDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataTesterHelper::getResourceApplicationDataRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceApplicationDataAsync( + guid, + ctx); + + NoteStoreGetResourceApplicationDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceApplicationDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceApplicationDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QString response = generateRandomString(); + + NoteStoreGetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequest, + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::onGetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::getResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QString res = noteStore->getResourceApplicationDataEntry( + guid, + key, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DATA_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequest, + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::onGetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::getResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getResourceApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequest, + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::onGetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::getResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getResourceApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequest, + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::onGetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::getResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getResourceApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequest, + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::onGetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::getResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->getResourceApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QString response = generateRandomString(); + + NoteStoreGetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequest, + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::onGetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::getResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getResourceApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_REGISTERED; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequest, + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::onGetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::getResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::SHARD_UNAVAILABLE; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequest, + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::onGetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::getResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequest, + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::onGetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::getResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequest, + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::onGetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceApplicationDataEntryTesterHelper::getResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onGetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteSetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreSetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequest, + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::onSetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::setResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->setResourceApplicationDataEntry( + guid, + key, + value, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInSetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_FEW; + userException.parameter = generateRandomString(); + + NoteStoreSetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequest, + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::onSetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::setResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->setResourceApplicationDataEntry( + guid, + key, + value, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInSetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INTERNAL_ERROR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreSetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequest, + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::onSetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::setResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->setResourceApplicationDataEntry( + guid, + key, + value, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInSetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreSetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequest, + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::onSetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::setResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->setResourceApplicationDataEntry( + guid, + key, + value, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInSetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreSetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequest, + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::onSetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::setResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->setResourceApplicationDataEntry( + guid, + key, + value, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteSetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreSetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequest, + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::onSetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::setResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->setResourceApplicationDataEntryAsync( + guid, + key, + value, + ctx); + + NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInSetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_SHORT; + userException.parameter = generateRandomString(); + + NoteStoreSetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequest, + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::onSetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::setResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->setResourceApplicationDataEntryAsync( + guid, + key, + value, + ctx); + + NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInSetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::RATE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreSetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequest, + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::onSetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::setResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->setResourceApplicationDataEntryAsync( + guid, + key, + value, + ctx); + + NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInSetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreSetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequest, + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::onSetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::setResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->setResourceApplicationDataEntryAsync( + guid, + key, + value, + ctx); + + NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInSetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + QString value = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreSetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + const QString & valueParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + Q_ASSERT(value == valueParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequest, + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::onSetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetResourceApplicationDataEntryTesterHelper::setResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onSetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->setResourceApplicationDataEntryAsync( + guid, + key, + value, + ctx); + + NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteUnsetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUnsetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::onUnsetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::unsetResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->unsetResourceApplicationDataEntry( + guid, + key, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUnsetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + userException.parameter = generateRandomString(); + + NoteStoreUnsetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::onUnsetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::unsetResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->unsetResourceApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUnsetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::UNKNOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUnsetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::onUnsetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::unsetResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->unsetResourceApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUnsetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUnsetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::onUnsetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::unsetResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->unsetResourceApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUnsetResourceApplicationDataEntry() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUnsetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::onUnsetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::unsetResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->unsetResourceApplicationDataEntry( + guid, + key, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteUnsetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUnsetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::onUnsetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::unsetResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->unsetResourceApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUnsetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::OPENID_ALREADY_TAKEN; + userException.parameter = generateRandomString(); + + NoteStoreUnsetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::onUnsetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::unsetResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->unsetResourceApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUnsetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_AUTH; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUnsetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::onUnsetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::unsetResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->unsetResourceApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUnsetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUnsetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::onUnsetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::unsetResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->unsetResourceApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUnsetResourceApplicationDataEntryAsync() +{ + Guid guid = generateRandomString(); + QString key = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUnsetResourceApplicationDataEntryTesterHelper helper( + [&] (const Guid & guidParam, + const QString & keyParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + Q_ASSERT(key == keyParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequest, + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::onUnsetResourceApplicationDataEntryRequestReceived); + QObject::connect( + &helper, + &NoteStoreUnsetResourceApplicationDataEntryTesterHelper::unsetResourceApplicationDataEntryRequestReady, + &server, + &NoteStoreServer::onUnsetResourceApplicationDataEntryRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::unsetResourceApplicationDataEntryRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->unsetResourceApplicationDataEntryAsync( + guid, + key, + ctx); + + NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUnsetResourceApplicationDataEntryAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteUpdateResource() +{ + Resource resource = generateRandomResource(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUpdateResourceTesterHelper helper( + [&] (const Resource & resourceParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(resource == resourceParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequest, + &helper, + &NoteStoreUpdateResourceTesterHelper::onUpdateResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateResourceTesterHelper::updateResourceRequestReady, + &server, + &NoteStoreServer::onUpdateResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->updateResource( + resource, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateResource() +{ + Resource resource = generateRandomResource(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreUpdateResourceTesterHelper helper( + [&] (const Resource & resourceParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(resource == resourceParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequest, + &helper, + &NoteStoreUpdateResourceTesterHelper::onUpdateResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateResourceTesterHelper::updateResourceRequestReady, + &server, + &NoteStoreServer::onUpdateResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateResource( + resource, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateResource() +{ + Resource resource = generateRandomResource(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateResourceTesterHelper helper( + [&] (const Resource & resourceParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(resource == resourceParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequest, + &helper, + &NoteStoreUpdateResourceTesterHelper::onUpdateResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateResourceTesterHelper::updateResourceRequestReady, + &server, + &NoteStoreServer::onUpdateResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateResource( + resource, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateResource() +{ + Resource resource = generateRandomResource(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateResourceTesterHelper helper( + [&] (const Resource & resourceParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(resource == resourceParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequest, + &helper, + &NoteStoreUpdateResourceTesterHelper::onUpdateResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateResourceTesterHelper::updateResourceRequestReady, + &server, + &NoteStoreServer::onUpdateResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateResource( + resource, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateResource() +{ + Resource resource = generateRandomResource(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateResourceTesterHelper helper( + [&] (const Resource & resourceParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(resource == resourceParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequest, + &helper, + &NoteStoreUpdateResourceTesterHelper::onUpdateResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateResourceTesterHelper::updateResourceRequestReady, + &server, + &NoteStoreServer::onUpdateResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateResource( + resource, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteUpdateResourceAsync() +{ + Resource resource = generateRandomResource(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUpdateResourceTesterHelper helper( + [&] (const Resource & resourceParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(resource == resourceParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequest, + &helper, + &NoteStoreUpdateResourceTesterHelper::onUpdateResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateResourceTesterHelper::updateResourceRequestReady, + &server, + &NoteStoreServer::onUpdateResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->updateResourceAsync( + resource, + ctx); + + NoteStoreUpdateResourceAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateResourceAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateResourceAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateResourceAsync() +{ + Resource resource = generateRandomResource(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreUpdateResourceTesterHelper helper( + [&] (const Resource & resourceParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(resource == resourceParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequest, + &helper, + &NoteStoreUpdateResourceTesterHelper::onUpdateResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateResourceTesterHelper::updateResourceRequestReady, + &server, + &NoteStoreServer::onUpdateResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateResourceAsync( + resource, + ctx); + + NoteStoreUpdateResourceAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateResourceAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateResourceAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateResourceAsync() +{ + Resource resource = generateRandomResource(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::AUTH_EXPIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateResourceTesterHelper helper( + [&] (const Resource & resourceParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(resource == resourceParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequest, + &helper, + &NoteStoreUpdateResourceTesterHelper::onUpdateResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateResourceTesterHelper::updateResourceRequestReady, + &server, + &NoteStoreServer::onUpdateResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateResourceAsync( + resource, + ctx); + + NoteStoreUpdateResourceAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateResourceAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateResourceAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateResourceAsync() +{ + Resource resource = generateRandomResource(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateResourceTesterHelper helper( + [&] (const Resource & resourceParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(resource == resourceParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequest, + &helper, + &NoteStoreUpdateResourceTesterHelper::onUpdateResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateResourceTesterHelper::updateResourceRequestReady, + &server, + &NoteStoreServer::onUpdateResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateResourceAsync( + resource, + ctx); + + NoteStoreUpdateResourceAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateResourceAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateResourceAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateResourceAsync() +{ + Resource resource = generateRandomResource(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateResourceTesterHelper helper( + [&] (const Resource & resourceParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(resource == resourceParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequest, + &helper, + &NoteStoreUpdateResourceTesterHelper::onUpdateResourceRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateResourceTesterHelper::updateResourceRequestReady, + &server, + &NoteStoreServer::onUpdateResourceRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateResourceRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateResourceAsync( + resource, + ctx); + + NoteStoreUpdateResourceAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateResourceAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateResourceAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetResourceData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QByteArray response = generateRandomString().toUtf8(); + + NoteStoreGetResourceDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequest, + &helper, + &NoteStoreGetResourceDataTesterHelper::onGetResourceDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceDataTesterHelper::getResourceDataRequestReady, + &server, + &NoteStoreServer::onGetResourceDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QByteArray res = noteStore->getResourceData( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_FEW; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequest, + &helper, + &NoteStoreGetResourceDataTesterHelper::onGetResourceDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceDataTesterHelper::getResourceDataRequestReady, + &server, + &NoteStoreServer::onGetResourceDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QByteArray res = noteStore->getResourceData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INTERNAL_ERROR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequest, + &helper, + &NoteStoreGetResourceDataTesterHelper::onGetResourceDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceDataTesterHelper::getResourceDataRequestReady, + &server, + &NoteStoreServer::onGetResourceDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QByteArray res = noteStore->getResourceData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequest, + &helper, + &NoteStoreGetResourceDataTesterHelper::onGetResourceDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceDataTesterHelper::getResourceDataRequestReady, + &server, + &NoteStoreServer::onGetResourceDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QByteArray res = noteStore->getResourceData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequest, + &helper, + &NoteStoreGetResourceDataTesterHelper::onGetResourceDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceDataTesterHelper::getResourceDataRequestReady, + &server, + &NoteStoreServer::onGetResourceDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QByteArray res = noteStore->getResourceData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetResourceDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QByteArray response = generateRandomString().toUtf8(); + + NoteStoreGetResourceDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequest, + &helper, + &NoteStoreGetResourceDataTesterHelper::onGetResourceDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceDataTesterHelper::getResourceDataRequestReady, + &server, + &NoteStoreServer::onGetResourceDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getResourceDataAsync( + guid, + ctx); + + NoteStoreGetResourceDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequest, + &helper, + &NoteStoreGetResourceDataTesterHelper::onGetResourceDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceDataTesterHelper::getResourceDataRequestReady, + &server, + &NoteStoreServer::onGetResourceDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceDataAsync( + guid, + ctx); + + NoteStoreGetResourceDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LEN_TOO_SHORT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequest, + &helper, + &NoteStoreGetResourceDataTesterHelper::onGetResourceDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceDataTesterHelper::getResourceDataRequestReady, + &server, + &NoteStoreServer::onGetResourceDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceDataAsync( + guid, + ctx); + + NoteStoreGetResourceDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequest, + &helper, + &NoteStoreGetResourceDataTesterHelper::onGetResourceDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceDataTesterHelper::getResourceDataRequestReady, + &server, + &NoteStoreServer::onGetResourceDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceDataAsync( + guid, + ctx); + + NoteStoreGetResourceDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequest, + &helper, + &NoteStoreGetResourceDataTesterHelper::onGetResourceDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceDataTesterHelper::getResourceDataRequestReady, + &server, + &NoteStoreServer::onGetResourceDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceDataAsync( + guid, + ctx); + + NoteStoreGetResourceDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetResourceByHash() +{ + Guid noteGuid = generateRandomString(); + QByteArray contentHash = generateRandomString().toUtf8(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Resource response = generateRandomResource(); + + NoteStoreGetResourceByHashTesterHelper helper( + [&] (const Guid & noteGuidParam, + QByteArray contentHashParam, + bool withDataParam, + bool withRecognitionParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(contentHash == contentHashParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequest, + &helper, + &NoteStoreGetResourceByHashTesterHelper::onGetResourceByHashRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceByHashTesterHelper::getResourceByHashRequestReady, + &server, + &NoteStoreServer::onGetResourceByHashRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Resource res = noteStore->getResourceByHash( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceByHash() +{ + Guid noteGuid = generateRandomString(); + QByteArray contentHash = generateRandomString().toUtf8(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_REGISTERED; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceByHashTesterHelper helper( + [&] (const Guid & noteGuidParam, + QByteArray contentHashParam, + bool withDataParam, + bool withRecognitionParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(contentHash == contentHashParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequest, + &helper, + &NoteStoreGetResourceByHashTesterHelper::onGetResourceByHashRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceByHashTesterHelper::getResourceByHashRequestReady, + &server, + &NoteStoreServer::onGetResourceByHashRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Resource res = noteStore->getResourceByHash( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceByHash() +{ + Guid noteGuid = generateRandomString(); + QByteArray contentHash = generateRandomString().toUtf8(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_AUTH; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceByHashTesterHelper helper( + [&] (const Guid & noteGuidParam, + QByteArray contentHashParam, + bool withDataParam, + bool withRecognitionParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(contentHash == contentHashParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequest, + &helper, + &NoteStoreGetResourceByHashTesterHelper::onGetResourceByHashRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceByHashTesterHelper::getResourceByHashRequestReady, + &server, + &NoteStoreServer::onGetResourceByHashRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Resource res = noteStore->getResourceByHash( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceByHash() +{ + Guid noteGuid = generateRandomString(); + QByteArray contentHash = generateRandomString().toUtf8(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceByHashTesterHelper helper( + [&] (const Guid & noteGuidParam, + QByteArray contentHashParam, + bool withDataParam, + bool withRecognitionParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(contentHash == contentHashParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequest, + &helper, + &NoteStoreGetResourceByHashTesterHelper::onGetResourceByHashRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceByHashTesterHelper::getResourceByHashRequestReady, + &server, + &NoteStoreServer::onGetResourceByHashRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Resource res = noteStore->getResourceByHash( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceByHash() +{ + Guid noteGuid = generateRandomString(); + QByteArray contentHash = generateRandomString().toUtf8(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceByHashTesterHelper helper( + [&] (const Guid & noteGuidParam, + QByteArray contentHashParam, + bool withDataParam, + bool withRecognitionParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(contentHash == contentHashParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequest, + &helper, + &NoteStoreGetResourceByHashTesterHelper::onGetResourceByHashRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceByHashTesterHelper::getResourceByHashRequestReady, + &server, + &NoteStoreServer::onGetResourceByHashRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Resource res = noteStore->getResourceByHash( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetResourceByHashAsync() +{ + Guid noteGuid = generateRandomString(); + QByteArray contentHash = generateRandomString().toUtf8(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Resource response = generateRandomResource(); + + NoteStoreGetResourceByHashTesterHelper helper( + [&] (const Guid & noteGuidParam, + QByteArray contentHashParam, + bool withDataParam, + bool withRecognitionParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(contentHash == contentHashParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequest, + &helper, + &NoteStoreGetResourceByHashTesterHelper::onGetResourceByHashRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceByHashTesterHelper::getResourceByHashRequestReady, + &server, + &NoteStoreServer::onGetResourceByHashRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getResourceByHashAsync( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + + NoteStoreGetResourceByHashAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceByHashAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceByHashAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceByHashAsync() +{ + Guid noteGuid = generateRandomString(); + QByteArray contentHash = generateRandomString().toUtf8(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNKNOWN; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceByHashTesterHelper helper( + [&] (const Guid & noteGuidParam, + QByteArray contentHashParam, + bool withDataParam, + bool withRecognitionParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(contentHash == contentHashParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequest, + &helper, + &NoteStoreGetResourceByHashTesterHelper::onGetResourceByHashRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceByHashTesterHelper::getResourceByHashRequestReady, + &server, + &NoteStoreServer::onGetResourceByHashRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceByHashAsync( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + + NoteStoreGetResourceByHashAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceByHashAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceByHashAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceByHashAsync() +{ + Guid noteGuid = generateRandomString(); + QByteArray contentHash = generateRandomString().toUtf8(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceByHashTesterHelper helper( + [&] (const Guid & noteGuidParam, + QByteArray contentHashParam, + bool withDataParam, + bool withRecognitionParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(contentHash == contentHashParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequest, + &helper, + &NoteStoreGetResourceByHashTesterHelper::onGetResourceByHashRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceByHashTesterHelper::getResourceByHashRequestReady, + &server, + &NoteStoreServer::onGetResourceByHashRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceByHashAsync( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + + NoteStoreGetResourceByHashAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceByHashAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceByHashAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceByHashAsync() +{ + Guid noteGuid = generateRandomString(); + QByteArray contentHash = generateRandomString().toUtf8(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceByHashTesterHelper helper( + [&] (const Guid & noteGuidParam, + QByteArray contentHashParam, + bool withDataParam, + bool withRecognitionParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(contentHash == contentHashParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequest, + &helper, + &NoteStoreGetResourceByHashTesterHelper::onGetResourceByHashRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceByHashTesterHelper::getResourceByHashRequestReady, + &server, + &NoteStoreServer::onGetResourceByHashRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceByHashAsync( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + + NoteStoreGetResourceByHashAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceByHashAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceByHashAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceByHashAsync() +{ + Guid noteGuid = generateRandomString(); + QByteArray contentHash = generateRandomString().toUtf8(); + bool withData = generateRandomBool(); + bool withRecognition = generateRandomBool(); + bool withAlternateData = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceByHashTesterHelper helper( + [&] (const Guid & noteGuidParam, + QByteArray contentHashParam, + bool withDataParam, + bool withRecognitionParam, + bool withAlternateDataParam, + IRequestContextPtr ctxParam) -> Resource + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(noteGuid == noteGuidParam); + Q_ASSERT(contentHash == contentHashParam); + Q_ASSERT(withData == withDataParam); + Q_ASSERT(withRecognition == withRecognitionParam); + Q_ASSERT(withAlternateData == withAlternateDataParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequest, + &helper, + &NoteStoreGetResourceByHashTesterHelper::onGetResourceByHashRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceByHashTesterHelper::getResourceByHashRequestReady, + &server, + &NoteStoreServer::onGetResourceByHashRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceByHashRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceByHashAsync( + noteGuid, + contentHash, + withData, + withRecognition, + withAlternateData, + ctx); + + NoteStoreGetResourceByHashAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceByHashAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceByHashAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetResourceRecognition() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QByteArray response = generateRandomString().toUtf8(); + + NoteStoreGetResourceRecognitionTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequest, + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::onGetResourceRecognitionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::getResourceRecognitionRequestReady, + &server, + &NoteStoreServer::onGetResourceRecognitionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QByteArray res = noteStore->getResourceRecognition( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceRecognition() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceRecognitionTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequest, + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::onGetResourceRecognitionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::getResourceRecognitionRequestReady, + &server, + &NoteStoreServer::onGetResourceRecognitionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QByteArray res = noteStore->getResourceRecognition( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceRecognition() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::AUTH_EXPIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceRecognitionTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequest, + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::onGetResourceRecognitionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::getResourceRecognitionRequestReady, + &server, + &NoteStoreServer::onGetResourceRecognitionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QByteArray res = noteStore->getResourceRecognition( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceRecognition() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceRecognitionTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequest, + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::onGetResourceRecognitionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::getResourceRecognitionRequestReady, + &server, + &NoteStoreServer::onGetResourceRecognitionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QByteArray res = noteStore->getResourceRecognition( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceRecognition() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceRecognitionTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequest, + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::onGetResourceRecognitionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::getResourceRecognitionRequestReady, + &server, + &NoteStoreServer::onGetResourceRecognitionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QByteArray res = noteStore->getResourceRecognition( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetResourceRecognitionAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QByteArray response = generateRandomString().toUtf8(); + + NoteStoreGetResourceRecognitionTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequest, + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::onGetResourceRecognitionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::getResourceRecognitionRequestReady, + &server, + &NoteStoreServer::onGetResourceRecognitionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getResourceRecognitionAsync( + guid, + ctx); + + NoteStoreGetResourceRecognitionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceRecognitionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceRecognitionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceRecognitionAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_SHORT; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceRecognitionTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequest, + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::onGetResourceRecognitionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::getResourceRecognitionRequestReady, + &server, + &NoteStoreServer::onGetResourceRecognitionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceRecognitionAsync( + guid, + ctx); + + NoteStoreGetResourceRecognitionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceRecognitionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceRecognitionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceRecognitionAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceRecognitionTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequest, + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::onGetResourceRecognitionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::getResourceRecognitionRequestReady, + &server, + &NoteStoreServer::onGetResourceRecognitionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceRecognitionAsync( + guid, + ctx); + + NoteStoreGetResourceRecognitionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceRecognitionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceRecognitionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceRecognitionAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceRecognitionTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequest, + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::onGetResourceRecognitionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::getResourceRecognitionRequestReady, + &server, + &NoteStoreServer::onGetResourceRecognitionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceRecognitionAsync( + guid, + ctx); + + NoteStoreGetResourceRecognitionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceRecognitionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceRecognitionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceRecognitionAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceRecognitionTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequest, + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::onGetResourceRecognitionRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceRecognitionTesterHelper::getResourceRecognitionRequestReady, + &server, + &NoteStoreServer::onGetResourceRecognitionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceRecognitionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceRecognitionAsync( + guid, + ctx); + + NoteStoreGetResourceRecognitionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceRecognitionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceRecognitionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetResourceAlternateData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QByteArray response = generateRandomString().toUtf8(); + + NoteStoreGetResourceAlternateDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequest, + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::onGetResourceAlternateDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::getResourceAlternateDataRequestReady, + &server, + &NoteStoreServer::onGetResourceAlternateDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QByteArray res = noteStore->getResourceAlternateData( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceAlternateData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ENML_VALIDATION; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceAlternateDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequest, + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::onGetResourceAlternateDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::getResourceAlternateDataRequestReady, + &server, + &NoteStoreServer::onGetResourceAlternateDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QByteArray res = noteStore->getResourceAlternateData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceAlternateData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceAlternateDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequest, + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::onGetResourceAlternateDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::getResourceAlternateDataRequestReady, + &server, + &NoteStoreServer::onGetResourceAlternateDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QByteArray res = noteStore->getResourceAlternateData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceAlternateData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceAlternateDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequest, + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::onGetResourceAlternateDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::getResourceAlternateDataRequestReady, + &server, + &NoteStoreServer::onGetResourceAlternateDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QByteArray res = noteStore->getResourceAlternateData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceAlternateData() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceAlternateDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequest, + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::onGetResourceAlternateDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::getResourceAlternateDataRequestReady, + &server, + &NoteStoreServer::onGetResourceAlternateDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QByteArray res = noteStore->getResourceAlternateData( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetResourceAlternateDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QByteArray response = generateRandomString().toUtf8(); + + NoteStoreGetResourceAlternateDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequest, + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::onGetResourceAlternateDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::getResourceAlternateDataRequestReady, + &server, + &NoteStoreServer::onGetResourceAlternateDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getResourceAlternateDataAsync( + guid, + ctx); + + NoteStoreGetResourceAlternateDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAlternateDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAlternateDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceAlternateDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_SHORT; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceAlternateDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequest, + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::onGetResourceAlternateDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::getResourceAlternateDataRequestReady, + &server, + &NoteStoreServer::onGetResourceAlternateDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceAlternateDataAsync( + guid, + ctx); + + NoteStoreGetResourceAlternateDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAlternateDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAlternateDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceAlternateDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceAlternateDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequest, + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::onGetResourceAlternateDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::getResourceAlternateDataRequestReady, + &server, + &NoteStoreServer::onGetResourceAlternateDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceAlternateDataAsync( + guid, + ctx); + + NoteStoreGetResourceAlternateDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAlternateDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAlternateDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceAlternateDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceAlternateDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequest, + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::onGetResourceAlternateDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::getResourceAlternateDataRequestReady, + &server, + &NoteStoreServer::onGetResourceAlternateDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceAlternateDataAsync( + guid, + ctx); + + NoteStoreGetResourceAlternateDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAlternateDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAlternateDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceAlternateDataAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceAlternateDataTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QByteArray + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequest, + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::onGetResourceAlternateDataRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAlternateDataTesterHelper::getResourceAlternateDataRequestReady, + &server, + &NoteStoreServer::onGetResourceAlternateDataRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAlternateDataRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceAlternateDataAsync( + guid, + ctx); + + NoteStoreGetResourceAlternateDataAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAlternateDataAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAlternateDataAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetResourceAttributes() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + ResourceAttributes response = generateRandomResourceAttributes(); + + NoteStoreGetResourceAttributesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> ResourceAttributes + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequest, + &helper, + &NoteStoreGetResourceAttributesTesterHelper::onGetResourceAttributesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAttributesTesterHelper::getResourceAttributesRequestReady, + &server, + &NoteStoreServer::onGetResourceAttributesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + ResourceAttributes res = noteStore->getResourceAttributes( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceAttributes() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_ASSOCIATED; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceAttributesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> ResourceAttributes + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequest, + &helper, + &NoteStoreGetResourceAttributesTesterHelper::onGetResourceAttributesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAttributesTesterHelper::getResourceAttributesRequestReady, + &server, + &NoteStoreServer::onGetResourceAttributesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + ResourceAttributes res = noteStore->getResourceAttributes( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceAttributes() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::OPENID_ALREADY_TAKEN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceAttributesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> ResourceAttributes + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequest, + &helper, + &NoteStoreGetResourceAttributesTesterHelper::onGetResourceAttributesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAttributesTesterHelper::getResourceAttributesRequestReady, + &server, + &NoteStoreServer::onGetResourceAttributesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + ResourceAttributes res = noteStore->getResourceAttributes( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceAttributes() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceAttributesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> ResourceAttributes + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequest, + &helper, + &NoteStoreGetResourceAttributesTesterHelper::onGetResourceAttributesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAttributesTesterHelper::getResourceAttributesRequestReady, + &server, + &NoteStoreServer::onGetResourceAttributesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + ResourceAttributes res = noteStore->getResourceAttributes( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceAttributes() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceAttributesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> ResourceAttributes + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequest, + &helper, + &NoteStoreGetResourceAttributesTesterHelper::onGetResourceAttributesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAttributesTesterHelper::getResourceAttributesRequestReady, + &server, + &NoteStoreServer::onGetResourceAttributesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + ResourceAttributes res = noteStore->getResourceAttributes( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetResourceAttributesAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + ResourceAttributes response = generateRandomResourceAttributes(); + + NoteStoreGetResourceAttributesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> ResourceAttributes + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequest, + &helper, + &NoteStoreGetResourceAttributesTesterHelper::onGetResourceAttributesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAttributesTesterHelper::getResourceAttributesRequestReady, + &server, + &NoteStoreServer::onGetResourceAttributesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getResourceAttributesAsync( + guid, + ctx); + + NoteStoreGetResourceAttributesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAttributesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAttributesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetResourceAttributesAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DATA_CONFLICT; + userException.parameter = generateRandomString(); + + NoteStoreGetResourceAttributesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> ResourceAttributes + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequest, + &helper, + &NoteStoreGetResourceAttributesTesterHelper::onGetResourceAttributesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAttributesTesterHelper::getResourceAttributesRequestReady, + &server, + &NoteStoreServer::onGetResourceAttributesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceAttributesAsync( + guid, + ctx); + + NoteStoreGetResourceAttributesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAttributesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAttributesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetResourceAttributesAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DATA_CONFLICT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetResourceAttributesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> ResourceAttributes + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequest, + &helper, + &NoteStoreGetResourceAttributesTesterHelper::onGetResourceAttributesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAttributesTesterHelper::getResourceAttributesRequestReady, + &server, + &NoteStoreServer::onGetResourceAttributesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceAttributesAsync( + guid, + ctx); + + NoteStoreGetResourceAttributesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAttributesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAttributesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetResourceAttributesAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetResourceAttributesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> ResourceAttributes + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequest, + &helper, + &NoteStoreGetResourceAttributesTesterHelper::onGetResourceAttributesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAttributesTesterHelper::getResourceAttributesRequestReady, + &server, + &NoteStoreServer::onGetResourceAttributesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceAttributesAsync( + guid, + ctx); + + NoteStoreGetResourceAttributesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAttributesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAttributesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetResourceAttributesAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetResourceAttributesTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> ResourceAttributes + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequest, + &helper, + &NoteStoreGetResourceAttributesTesterHelper::onGetResourceAttributesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetResourceAttributesTesterHelper::getResourceAttributesRequestReady, + &server, + &NoteStoreServer::onGetResourceAttributesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getResourceAttributesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getResourceAttributesAsync( + guid, + ctx); + + NoteStoreGetResourceAttributesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetResourceAttributesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetResourceAttributesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetPublicNotebook() +{ + UserID userId = generateRandomInt32(); + QString publicUri = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + Notebook response = generateRandomNotebook(); + + NoteStoreGetPublicNotebookTesterHelper helper( + [&] (const UserID & userIdParam, + const QString & publicUriParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(userId == userIdParam); + Q_ASSERT(publicUri == publicUriParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequest, + &helper, + &NoteStoreGetPublicNotebookTesterHelper::onGetPublicNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetPublicNotebookTesterHelper::getPublicNotebookRequestReady, + &server, + &NoteStoreServer::onGetPublicNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Notebook res = noteStore->getPublicNotebook( + userId, + publicUri, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetPublicNotebook() +{ + UserID userId = generateRandomInt32(); + QString publicUri = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_NOT_REGISTERED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetPublicNotebookTesterHelper helper( + [&] (const UserID & userIdParam, + const QString & publicUriParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(userId == userIdParam); + Q_ASSERT(publicUri == publicUriParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequest, + &helper, + &NoteStoreGetPublicNotebookTesterHelper::onGetPublicNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetPublicNotebookTesterHelper::getPublicNotebookRequestReady, + &server, + &NoteStoreServer::onGetPublicNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->getPublicNotebook( + userId, + publicUri, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetPublicNotebook() +{ + UserID userId = generateRandomInt32(); + QString publicUri = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetPublicNotebookTesterHelper helper( + [&] (const UserID & userIdParam, + const QString & publicUriParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(userId == userIdParam); + Q_ASSERT(publicUri == publicUriParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequest, + &helper, + &NoteStoreGetPublicNotebookTesterHelper::onGetPublicNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetPublicNotebookTesterHelper::getPublicNotebookRequestReady, + &server, + &NoteStoreServer::onGetPublicNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->getPublicNotebook( + userId, + publicUri, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetPublicNotebook() +{ + UserID userId = generateRandomInt32(); + QString publicUri = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetPublicNotebookTesterHelper helper( + [&] (const UserID & userIdParam, + const QString & publicUriParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(userId == userIdParam); + Q_ASSERT(publicUri == publicUriParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequest, + &helper, + &NoteStoreGetPublicNotebookTesterHelper::onGetPublicNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetPublicNotebookTesterHelper::getPublicNotebookRequestReady, + &server, + &NoteStoreServer::onGetPublicNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->getPublicNotebook( + userId, + publicUri, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetPublicNotebookAsync() +{ + UserID userId = generateRandomInt32(); + QString publicUri = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + Notebook response = generateRandomNotebook(); + + NoteStoreGetPublicNotebookTesterHelper helper( + [&] (const UserID & userIdParam, + const QString & publicUriParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(userId == userIdParam); + Q_ASSERT(publicUri == publicUriParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequest, + &helper, + &NoteStoreGetPublicNotebookTesterHelper::onGetPublicNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetPublicNotebookTesterHelper::getPublicNotebookRequestReady, + &server, + &NoteStoreServer::onGetPublicNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getPublicNotebookAsync( + userId, + publicUri, + ctx); + + NoteStoreGetPublicNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetPublicNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetPublicNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetPublicNotebookAsync() +{ + UserID userId = generateRandomInt32(); + QString publicUri = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetPublicNotebookTesterHelper helper( + [&] (const UserID & userIdParam, + const QString & publicUriParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(userId == userIdParam); + Q_ASSERT(publicUri == publicUriParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequest, + &helper, + &NoteStoreGetPublicNotebookTesterHelper::onGetPublicNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetPublicNotebookTesterHelper::getPublicNotebookRequestReady, + &server, + &NoteStoreServer::onGetPublicNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getPublicNotebookAsync( + userId, + publicUri, + ctx); + + NoteStoreGetPublicNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetPublicNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetPublicNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetPublicNotebookAsync() +{ + UserID userId = generateRandomInt32(); + QString publicUri = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetPublicNotebookTesterHelper helper( + [&] (const UserID & userIdParam, + const QString & publicUriParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(userId == userIdParam); + Q_ASSERT(publicUri == publicUriParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequest, + &helper, + &NoteStoreGetPublicNotebookTesterHelper::onGetPublicNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetPublicNotebookTesterHelper::getPublicNotebookRequestReady, + &server, + &NoteStoreServer::onGetPublicNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getPublicNotebookAsync( + userId, + publicUri, + ctx); + + NoteStoreGetPublicNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetPublicNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetPublicNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetPublicNotebookAsync() +{ + UserID userId = generateRandomInt32(); + QString publicUri = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetPublicNotebookTesterHelper helper( + [&] (const UserID & userIdParam, + const QString & publicUriParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(userId == userIdParam); + Q_ASSERT(publicUri == publicUriParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequest, + &helper, + &NoteStoreGetPublicNotebookTesterHelper::onGetPublicNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetPublicNotebookTesterHelper::getPublicNotebookRequestReady, + &server, + &NoteStoreServer::onGetPublicNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getPublicNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getPublicNotebookAsync( + userId, + publicUri, + ctx); + + NoteStoreGetPublicNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetPublicNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetPublicNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteShareNotebook() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + QString message = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SharedNotebook response = generateRandomSharedNotebook(); + + NoteStoreShareNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + const QString & messageParam, + IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + Q_ASSERT(message == messageParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequest, + &helper, + &NoteStoreShareNotebookTesterHelper::onShareNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNotebookTesterHelper::shareNotebookRequestReady, + &server, + &NoteStoreServer::onShareNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + SharedNotebook res = noteStore->shareNotebook( + sharedNotebook, + message, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInShareNotebook() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + QString message = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_SHORT; + userException.parameter = generateRandomString(); + + NoteStoreShareNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + const QString & messageParam, + IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + Q_ASSERT(message == messageParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequest, + &helper, + &NoteStoreShareNotebookTesterHelper::onShareNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNotebookTesterHelper::shareNotebookRequestReady, + &server, + &NoteStoreServer::onShareNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SharedNotebook res = noteStore->shareNotebook( + sharedNotebook, + message, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInShareNotebook() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + QString message = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreShareNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + const QString & messageParam, + IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + Q_ASSERT(message == messageParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequest, + &helper, + &NoteStoreShareNotebookTesterHelper::onShareNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNotebookTesterHelper::shareNotebookRequestReady, + &server, + &NoteStoreServer::onShareNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SharedNotebook res = noteStore->shareNotebook( + sharedNotebook, + message, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInShareNotebook() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + QString message = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreShareNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + const QString & messageParam, + IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + Q_ASSERT(message == messageParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequest, + &helper, + &NoteStoreShareNotebookTesterHelper::onShareNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNotebookTesterHelper::shareNotebookRequestReady, + &server, + &NoteStoreServer::onShareNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SharedNotebook res = noteStore->shareNotebook( + sharedNotebook, + message, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInShareNotebook() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + QString message = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreShareNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + const QString & messageParam, + IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + Q_ASSERT(message == messageParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequest, + &helper, + &NoteStoreShareNotebookTesterHelper::onShareNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNotebookTesterHelper::shareNotebookRequestReady, + &server, + &NoteStoreServer::onShareNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SharedNotebook res = noteStore->shareNotebook( + sharedNotebook, + message, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteShareNotebookAsync() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + QString message = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SharedNotebook response = generateRandomSharedNotebook(); + + NoteStoreShareNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + const QString & messageParam, + IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + Q_ASSERT(message == messageParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequest, + &helper, + &NoteStoreShareNotebookTesterHelper::onShareNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNotebookTesterHelper::shareNotebookRequestReady, + &server, + &NoteStoreServer::onShareNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->shareNotebookAsync( + sharedNotebook, + message, + ctx); + + NoteStoreShareNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreShareNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreShareNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInShareNotebookAsync() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + QString message = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::QUOTA_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreShareNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + const QString & messageParam, + IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + Q_ASSERT(message == messageParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequest, + &helper, + &NoteStoreShareNotebookTesterHelper::onShareNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNotebookTesterHelper::shareNotebookRequestReady, + &server, + &NoteStoreServer::onShareNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->shareNotebookAsync( + sharedNotebook, + message, + ctx); + + NoteStoreShareNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreShareNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreShareNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInShareNotebookAsync() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + QString message = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreShareNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + const QString & messageParam, + IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + Q_ASSERT(message == messageParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequest, + &helper, + &NoteStoreShareNotebookTesterHelper::onShareNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNotebookTesterHelper::shareNotebookRequestReady, + &server, + &NoteStoreServer::onShareNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->shareNotebookAsync( + sharedNotebook, + message, + ctx); + + NoteStoreShareNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreShareNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreShareNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInShareNotebookAsync() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + QString message = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreShareNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + const QString & messageParam, + IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + Q_ASSERT(message == messageParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequest, + &helper, + &NoteStoreShareNotebookTesterHelper::onShareNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNotebookTesterHelper::shareNotebookRequestReady, + &server, + &NoteStoreServer::onShareNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->shareNotebookAsync( + sharedNotebook, + message, + ctx); + + NoteStoreShareNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreShareNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreShareNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInShareNotebookAsync() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + QString message = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreShareNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + const QString & messageParam, + IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + Q_ASSERT(message == messageParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequest, + &helper, + &NoteStoreShareNotebookTesterHelper::onShareNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNotebookTesterHelper::shareNotebookRequestReady, + &server, + &NoteStoreServer::onShareNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->shareNotebookAsync( + sharedNotebook, + message, + ctx); + + NoteStoreShareNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreShareNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreShareNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteCreateOrUpdateNotebookShares() +{ + NotebookShareTemplate shareTemplate = generateRandomNotebookShareTemplate(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + CreateOrUpdateNotebookSharesResult response = generateRandomCreateOrUpdateNotebookSharesResult(); + + NoteStoreCreateOrUpdateNotebookSharesTesterHelper helper( + [&] (const NotebookShareTemplate & shareTemplateParam, + IRequestContextPtr ctxParam) -> CreateOrUpdateNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(shareTemplate == shareTemplateParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequest, + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::onCreateOrUpdateNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::createOrUpdateNotebookSharesRequestReady, + &server, + &NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + CreateOrUpdateNotebookSharesResult res = noteStore->createOrUpdateNotebookShares( + shareTemplate, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCreateOrUpdateNotebookShares() +{ + NotebookShareTemplate shareTemplate = generateRandomNotebookShareTemplate(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + userException.parameter = generateRandomString(); + + NoteStoreCreateOrUpdateNotebookSharesTesterHelper helper( + [&] (const NotebookShareTemplate & shareTemplateParam, + IRequestContextPtr ctxParam) -> CreateOrUpdateNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(shareTemplate == shareTemplateParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequest, + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::onCreateOrUpdateNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::createOrUpdateNotebookSharesRequestReady, + &server, + &NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + CreateOrUpdateNotebookSharesResult res = noteStore->createOrUpdateNotebookShares( + shareTemplate, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInCreateOrUpdateNotebookShares() +{ + NotebookShareTemplate shareTemplate = generateRandomNotebookShareTemplate(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreCreateOrUpdateNotebookSharesTesterHelper helper( + [&] (const NotebookShareTemplate & shareTemplateParam, + IRequestContextPtr ctxParam) -> CreateOrUpdateNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(shareTemplate == shareTemplateParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequest, + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::onCreateOrUpdateNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::createOrUpdateNotebookSharesRequestReady, + &server, + &NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + CreateOrUpdateNotebookSharesResult res = noteStore->createOrUpdateNotebookShares( + shareTemplate, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCreateOrUpdateNotebookShares() +{ + NotebookShareTemplate shareTemplate = generateRandomNotebookShareTemplate(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::SHARD_UNAVAILABLE; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCreateOrUpdateNotebookSharesTesterHelper helper( + [&] (const NotebookShareTemplate & shareTemplateParam, + IRequestContextPtr ctxParam) -> CreateOrUpdateNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(shareTemplate == shareTemplateParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequest, + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::onCreateOrUpdateNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::createOrUpdateNotebookSharesRequestReady, + &server, + &NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + CreateOrUpdateNotebookSharesResult res = noteStore->createOrUpdateNotebookShares( + shareTemplate, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMInvalidContactsExceptionInCreateOrUpdateNotebookShares() +{ + NotebookShareTemplate shareTemplate = generateRandomNotebookShareTemplate(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto invalidContactsException = EDAMInvalidContactsException(); + invalidContactsException.contacts << generateRandomContact(); + invalidContactsException.contacts << generateRandomContact(); + invalidContactsException.contacts << generateRandomContact(); + invalidContactsException.parameter = generateRandomString(); + invalidContactsException.reasons = QList(); + invalidContactsException.reasons.ref() << EDAMInvalidContactReason::DUPLICATE_CONTACT; + invalidContactsException.reasons.ref() << EDAMInvalidContactReason::NO_CONNECTION; + invalidContactsException.reasons.ref() << EDAMInvalidContactReason::NO_CONNECTION; + + NoteStoreCreateOrUpdateNotebookSharesTesterHelper helper( + [&] (const NotebookShareTemplate & shareTemplateParam, + IRequestContextPtr ctxParam) -> CreateOrUpdateNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(shareTemplate == shareTemplateParam); + throw invalidContactsException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequest, + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::onCreateOrUpdateNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::createOrUpdateNotebookSharesRequestReady, + &server, + &NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + CreateOrUpdateNotebookSharesResult res = noteStore->createOrUpdateNotebookShares( + shareTemplate, + ctx); + Q_UNUSED(res) + } + catch(const EDAMInvalidContactsException & e) + { + caughtException = true; + QVERIFY(e == invalidContactsException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCreateOrUpdateNotebookShares() +{ + NotebookShareTemplate shareTemplate = generateRandomNotebookShareTemplate(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCreateOrUpdateNotebookSharesTesterHelper helper( + [&] (const NotebookShareTemplate & shareTemplateParam, + IRequestContextPtr ctxParam) -> CreateOrUpdateNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(shareTemplate == shareTemplateParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequest, + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::onCreateOrUpdateNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::createOrUpdateNotebookSharesRequestReady, + &server, + &NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + CreateOrUpdateNotebookSharesResult res = noteStore->createOrUpdateNotebookShares( + shareTemplate, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteCreateOrUpdateNotebookSharesAsync() +{ + NotebookShareTemplate shareTemplate = generateRandomNotebookShareTemplate(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + CreateOrUpdateNotebookSharesResult response = generateRandomCreateOrUpdateNotebookSharesResult(); + + NoteStoreCreateOrUpdateNotebookSharesTesterHelper helper( + [&] (const NotebookShareTemplate & shareTemplateParam, + IRequestContextPtr ctxParam) -> CreateOrUpdateNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(shareTemplate == shareTemplateParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequest, + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::onCreateOrUpdateNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::createOrUpdateNotebookSharesRequestReady, + &server, + &NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->createOrUpdateNotebookSharesAsync( + shareTemplate, + ctx); + + NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCreateOrUpdateNotebookSharesAsync() +{ + NotebookShareTemplate shareTemplate = generateRandomNotebookShareTemplate(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DATA_CONFLICT; + userException.parameter = generateRandomString(); + + NoteStoreCreateOrUpdateNotebookSharesTesterHelper helper( + [&] (const NotebookShareTemplate & shareTemplateParam, + IRequestContextPtr ctxParam) -> CreateOrUpdateNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(shareTemplate == shareTemplateParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequest, + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::onCreateOrUpdateNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::createOrUpdateNotebookSharesRequestReady, + &server, + &NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createOrUpdateNotebookSharesAsync( + shareTemplate, + ctx); + + NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInCreateOrUpdateNotebookSharesAsync() +{ + NotebookShareTemplate shareTemplate = generateRandomNotebookShareTemplate(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreCreateOrUpdateNotebookSharesTesterHelper helper( + [&] (const NotebookShareTemplate & shareTemplateParam, + IRequestContextPtr ctxParam) -> CreateOrUpdateNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(shareTemplate == shareTemplateParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequest, + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::onCreateOrUpdateNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::createOrUpdateNotebookSharesRequestReady, + &server, + &NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createOrUpdateNotebookSharesAsync( + shareTemplate, + ctx); + + NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCreateOrUpdateNotebookSharesAsync() +{ + NotebookShareTemplate shareTemplate = generateRandomNotebookShareTemplate(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TAKEN_DOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCreateOrUpdateNotebookSharesTesterHelper helper( + [&] (const NotebookShareTemplate & shareTemplateParam, + IRequestContextPtr ctxParam) -> CreateOrUpdateNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(shareTemplate == shareTemplateParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequest, + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::onCreateOrUpdateNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::createOrUpdateNotebookSharesRequestReady, + &server, + &NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createOrUpdateNotebookSharesAsync( + shareTemplate, + ctx); + + NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMInvalidContactsExceptionInCreateOrUpdateNotebookSharesAsync() +{ + NotebookShareTemplate shareTemplate = generateRandomNotebookShareTemplate(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto invalidContactsException = EDAMInvalidContactsException(); + invalidContactsException.contacts << generateRandomContact(); + invalidContactsException.contacts << generateRandomContact(); + invalidContactsException.contacts << generateRandomContact(); + invalidContactsException.parameter = generateRandomString(); + invalidContactsException.reasons = QList(); + invalidContactsException.reasons.ref() << EDAMInvalidContactReason::DUPLICATE_CONTACT; + invalidContactsException.reasons.ref() << EDAMInvalidContactReason::BAD_ADDRESS; + invalidContactsException.reasons.ref() << EDAMInvalidContactReason::DUPLICATE_CONTACT; + + NoteStoreCreateOrUpdateNotebookSharesTesterHelper helper( + [&] (const NotebookShareTemplate & shareTemplateParam, + IRequestContextPtr ctxParam) -> CreateOrUpdateNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(shareTemplate == shareTemplateParam); + throw invalidContactsException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequest, + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::onCreateOrUpdateNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::createOrUpdateNotebookSharesRequestReady, + &server, + &NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createOrUpdateNotebookSharesAsync( + shareTemplate, + ctx); + + NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMInvalidContactsException & e) + { + caughtException = true; + QVERIFY(e == invalidContactsException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCreateOrUpdateNotebookSharesAsync() +{ + NotebookShareTemplate shareTemplate = generateRandomNotebookShareTemplate(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCreateOrUpdateNotebookSharesTesterHelper helper( + [&] (const NotebookShareTemplate & shareTemplateParam, + IRequestContextPtr ctxParam) -> CreateOrUpdateNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(shareTemplate == shareTemplateParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequest, + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::onCreateOrUpdateNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateOrUpdateNotebookSharesTesterHelper::createOrUpdateNotebookSharesRequestReady, + &server, + &NoteStoreServer::onCreateOrUpdateNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createOrUpdateNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createOrUpdateNotebookSharesAsync( + shareTemplate, + ctx); + + NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateOrUpdateNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteUpdateSharedNotebook() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUpdateSharedNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequest, + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::onUpdateSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::updateSharedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->updateSharedNotebook( + sharedNotebook, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateSharedNotebook() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INTERNAL_ERROR; + userException.parameter = generateRandomString(); + + NoteStoreUpdateSharedNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequest, + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::onUpdateSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::updateSharedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateSharedNotebook( + sharedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateSharedNotebook() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateSharedNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequest, + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::onUpdateSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::updateSharedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateSharedNotebook( + sharedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateSharedNotebook() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::QUOTA_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateSharedNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequest, + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::onUpdateSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::updateSharedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateSharedNotebook( + sharedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateSharedNotebook() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateSharedNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequest, + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::onUpdateSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::updateSharedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateSharedNotebook( + sharedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteUpdateSharedNotebookAsync() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUpdateSharedNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequest, + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::onUpdateSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::updateSharedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->updateSharedNotebookAsync( + sharedNotebook, + ctx); + + NoteStoreUpdateSharedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateSharedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateSharedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateSharedNotebookAsync() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreUpdateSharedNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequest, + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::onUpdateSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::updateSharedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateSharedNotebookAsync( + sharedNotebook, + ctx); + + NoteStoreUpdateSharedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateSharedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateSharedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateSharedNotebookAsync() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateSharedNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequest, + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::onUpdateSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::updateSharedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateSharedNotebookAsync( + sharedNotebook, + ctx); + + NoteStoreUpdateSharedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateSharedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateSharedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateSharedNotebookAsync() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateSharedNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequest, + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::onUpdateSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::updateSharedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateSharedNotebookAsync( + sharedNotebook, + ctx); + + NoteStoreUpdateSharedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateSharedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateSharedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateSharedNotebookAsync() +{ + SharedNotebook sharedNotebook = generateRandomSharedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateSharedNotebookTesterHelper helper( + [&] (const SharedNotebook & sharedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(sharedNotebook == sharedNotebookParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequest, + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::onUpdateSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateSharedNotebookTesterHelper::updateSharedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateSharedNotebookAsync( + sharedNotebook, + ctx); + + NoteStoreUpdateSharedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateSharedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateSharedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteSetNotebookRecipientSettings() +{ + QString notebookGuid = generateRandomString(); + NotebookRecipientSettings recipientSettings = generateRandomNotebookRecipientSettings(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Notebook response = generateRandomNotebook(); + + NoteStoreSetNotebookRecipientSettingsTesterHelper helper( + [&] (const QString & notebookGuidParam, + const NotebookRecipientSettings & recipientSettingsParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + Q_ASSERT(recipientSettings == recipientSettingsParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequest, + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::onSetNotebookRecipientSettingsRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::setNotebookRecipientSettingsRequestReady, + &server, + &NoteStoreServer::onSetNotebookRecipientSettingsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + Notebook res = noteStore->setNotebookRecipientSettings( + notebookGuid, + recipientSettings, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInSetNotebookRecipientSettings() +{ + QString notebookGuid = generateRandomString(); + NotebookRecipientSettings recipientSettings = generateRandomNotebookRecipientSettings(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_FEW; + userException.parameter = generateRandomString(); + + NoteStoreSetNotebookRecipientSettingsTesterHelper helper( + [&] (const QString & notebookGuidParam, + const NotebookRecipientSettings & recipientSettingsParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + Q_ASSERT(recipientSettings == recipientSettingsParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequest, + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::onSetNotebookRecipientSettingsRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::setNotebookRecipientSettingsRequestReady, + &server, + &NoteStoreServer::onSetNotebookRecipientSettingsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->setNotebookRecipientSettings( + notebookGuid, + recipientSettings, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInSetNotebookRecipientSettings() +{ + QString notebookGuid = generateRandomString(); + NotebookRecipientSettings recipientSettings = generateRandomNotebookRecipientSettings(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreSetNotebookRecipientSettingsTesterHelper helper( + [&] (const QString & notebookGuidParam, + const NotebookRecipientSettings & recipientSettingsParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + Q_ASSERT(recipientSettings == recipientSettingsParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequest, + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::onSetNotebookRecipientSettingsRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::setNotebookRecipientSettingsRequestReady, + &server, + &NoteStoreServer::onSetNotebookRecipientSettingsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->setNotebookRecipientSettings( + notebookGuid, + recipientSettings, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInSetNotebookRecipientSettings() +{ + QString notebookGuid = generateRandomString(); + NotebookRecipientSettings recipientSettings = generateRandomNotebookRecipientSettings(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_NOT_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreSetNotebookRecipientSettingsTesterHelper helper( + [&] (const QString & notebookGuidParam, + const NotebookRecipientSettings & recipientSettingsParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + Q_ASSERT(recipientSettings == recipientSettingsParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequest, + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::onSetNotebookRecipientSettingsRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::setNotebookRecipientSettingsRequestReady, + &server, + &NoteStoreServer::onSetNotebookRecipientSettingsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->setNotebookRecipientSettings( + notebookGuid, + recipientSettings, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInSetNotebookRecipientSettings() +{ + QString notebookGuid = generateRandomString(); + NotebookRecipientSettings recipientSettings = generateRandomNotebookRecipientSettings(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreSetNotebookRecipientSettingsTesterHelper helper( + [&] (const QString & notebookGuidParam, + const NotebookRecipientSettings & recipientSettingsParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + Q_ASSERT(recipientSettings == recipientSettingsParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequest, + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::onSetNotebookRecipientSettingsRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::setNotebookRecipientSettingsRequestReady, + &server, + &NoteStoreServer::onSetNotebookRecipientSettingsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + Notebook res = noteStore->setNotebookRecipientSettings( + notebookGuid, + recipientSettings, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteSetNotebookRecipientSettingsAsync() +{ + QString notebookGuid = generateRandomString(); + NotebookRecipientSettings recipientSettings = generateRandomNotebookRecipientSettings(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + Notebook response = generateRandomNotebook(); + + NoteStoreSetNotebookRecipientSettingsTesterHelper helper( + [&] (const QString & notebookGuidParam, + const NotebookRecipientSettings & recipientSettingsParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + Q_ASSERT(recipientSettings == recipientSettingsParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequest, + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::onSetNotebookRecipientSettingsRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::setNotebookRecipientSettingsRequestReady, + &server, + &NoteStoreServer::onSetNotebookRecipientSettingsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->setNotebookRecipientSettingsAsync( + notebookGuid, + recipientSettings, + ctx); + + NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInSetNotebookRecipientSettingsAsync() +{ + QString notebookGuid = generateRandomString(); + NotebookRecipientSettings recipientSettings = generateRandomNotebookRecipientSettings(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNKNOWN; + userException.parameter = generateRandomString(); + + NoteStoreSetNotebookRecipientSettingsTesterHelper helper( + [&] (const QString & notebookGuidParam, + const NotebookRecipientSettings & recipientSettingsParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + Q_ASSERT(recipientSettings == recipientSettingsParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequest, + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::onSetNotebookRecipientSettingsRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::setNotebookRecipientSettingsRequestReady, + &server, + &NoteStoreServer::onSetNotebookRecipientSettingsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->setNotebookRecipientSettingsAsync( + notebookGuid, + recipientSettings, + ctx); + + NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInSetNotebookRecipientSettingsAsync() +{ + QString notebookGuid = generateRandomString(); + NotebookRecipientSettings recipientSettings = generateRandomNotebookRecipientSettings(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreSetNotebookRecipientSettingsTesterHelper helper( + [&] (const QString & notebookGuidParam, + const NotebookRecipientSettings & recipientSettingsParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + Q_ASSERT(recipientSettings == recipientSettingsParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequest, + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::onSetNotebookRecipientSettingsRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::setNotebookRecipientSettingsRequestReady, + &server, + &NoteStoreServer::onSetNotebookRecipientSettingsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->setNotebookRecipientSettingsAsync( + notebookGuid, + recipientSettings, + ctx); + + NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInSetNotebookRecipientSettingsAsync() +{ + QString notebookGuid = generateRandomString(); + NotebookRecipientSettings recipientSettings = generateRandomNotebookRecipientSettings(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_NOT_REGISTERED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreSetNotebookRecipientSettingsTesterHelper helper( + [&] (const QString & notebookGuidParam, + const NotebookRecipientSettings & recipientSettingsParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + Q_ASSERT(recipientSettings == recipientSettingsParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequest, + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::onSetNotebookRecipientSettingsRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::setNotebookRecipientSettingsRequestReady, + &server, + &NoteStoreServer::onSetNotebookRecipientSettingsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->setNotebookRecipientSettingsAsync( + notebookGuid, + recipientSettings, + ctx); + + NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInSetNotebookRecipientSettingsAsync() +{ + QString notebookGuid = generateRandomString(); + NotebookRecipientSettings recipientSettings = generateRandomNotebookRecipientSettings(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreSetNotebookRecipientSettingsTesterHelper helper( + [&] (const QString & notebookGuidParam, + const NotebookRecipientSettings & recipientSettingsParam, + IRequestContextPtr ctxParam) -> Notebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + Q_ASSERT(recipientSettings == recipientSettingsParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequest, + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::onSetNotebookRecipientSettingsRequestReceived); + QObject::connect( + &helper, + &NoteStoreSetNotebookRecipientSettingsTesterHelper::setNotebookRecipientSettingsRequestReady, + &server, + &NoteStoreServer::onSetNotebookRecipientSettingsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::setNotebookRecipientSettingsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->setNotebookRecipientSettingsAsync( + notebookGuid, + recipientSettings, + ctx); + + NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreSetNotebookRecipientSettingsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteListSharedNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomSharedNotebook(); + response << generateRandomSharedNotebook(); + response << generateRandomSharedNotebook(); + + NoteStoreListSharedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequest, + &helper, + &NoteStoreListSharedNotebooksTesterHelper::onListSharedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSharedNotebooksTesterHelper::listSharedNotebooksRequestReady, + &server, + &NoteStoreServer::onListSharedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QList res = noteStore->listSharedNotebooks( + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListSharedNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_REGISTERED; + userException.parameter = generateRandomString(); + + NoteStoreListSharedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequest, + &helper, + &NoteStoreListSharedNotebooksTesterHelper::onListSharedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSharedNotebooksTesterHelper::listSharedNotebooksRequestReady, + &server, + &NoteStoreServer::onListSharedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listSharedNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInListSharedNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreListSharedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequest, + &helper, + &NoteStoreListSharedNotebooksTesterHelper::onListSharedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSharedNotebooksTesterHelper::listSharedNotebooksRequestReady, + &server, + &NoteStoreServer::onListSharedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listSharedNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListSharedNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListSharedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequest, + &helper, + &NoteStoreListSharedNotebooksTesterHelper::onListSharedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSharedNotebooksTesterHelper::listSharedNotebooksRequestReady, + &server, + &NoteStoreServer::onListSharedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listSharedNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListSharedNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListSharedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequest, + &helper, + &NoteStoreListSharedNotebooksTesterHelper::onListSharedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSharedNotebooksTesterHelper::listSharedNotebooksRequestReady, + &server, + &NoteStoreServer::onListSharedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listSharedNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteListSharedNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomSharedNotebook(); + response << generateRandomSharedNotebook(); + response << generateRandomSharedNotebook(); + + NoteStoreListSharedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequest, + &helper, + &NoteStoreListSharedNotebooksTesterHelper::onListSharedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSharedNotebooksTesterHelper::listSharedNotebooksRequestReady, + &server, + &NoteStoreServer::onListSharedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->listSharedNotebooksAsync( + ctx); + + NoteStoreListSharedNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListSharedNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListSharedNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListSharedNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::QUOTA_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreListSharedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequest, + &helper, + &NoteStoreListSharedNotebooksTesterHelper::onListSharedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSharedNotebooksTesterHelper::listSharedNotebooksRequestReady, + &server, + &NoteStoreServer::onListSharedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listSharedNotebooksAsync( + ctx); + + NoteStoreListSharedNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListSharedNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListSharedNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInListSharedNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreListSharedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequest, + &helper, + &NoteStoreListSharedNotebooksTesterHelper::onListSharedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSharedNotebooksTesterHelper::listSharedNotebooksRequestReady, + &server, + &NoteStoreServer::onListSharedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listSharedNotebooksAsync( + ctx); + + NoteStoreListSharedNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListSharedNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListSharedNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListSharedNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListSharedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequest, + &helper, + &NoteStoreListSharedNotebooksTesterHelper::onListSharedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSharedNotebooksTesterHelper::listSharedNotebooksRequestReady, + &server, + &NoteStoreServer::onListSharedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listSharedNotebooksAsync( + ctx); + + NoteStoreListSharedNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListSharedNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListSharedNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListSharedNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListSharedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequest, + &helper, + &NoteStoreListSharedNotebooksTesterHelper::onListSharedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListSharedNotebooksTesterHelper::listSharedNotebooksRequestReady, + &server, + &NoteStoreServer::onListSharedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listSharedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listSharedNotebooksAsync( + ctx); + + NoteStoreListSharedNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListSharedNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListSharedNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteCreateLinkedNotebook() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + LinkedNotebook response = generateRandomLinkedNotebook(); + + NoteStoreCreateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> LinkedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequest, + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::onCreateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::createLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onCreateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + LinkedNotebook res = noteStore->createLinkedNotebook( + linkedNotebook, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCreateLinkedNotebook() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + userException.parameter = generateRandomString(); + + NoteStoreCreateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> LinkedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequest, + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::onCreateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::createLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onCreateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + LinkedNotebook res = noteStore->createLinkedNotebook( + linkedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInCreateLinkedNotebook() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreCreateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> LinkedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequest, + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::onCreateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::createLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onCreateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + LinkedNotebook res = noteStore->createLinkedNotebook( + linkedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCreateLinkedNotebook() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TOO_MANY; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCreateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> LinkedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequest, + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::onCreateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::createLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onCreateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + LinkedNotebook res = noteStore->createLinkedNotebook( + linkedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCreateLinkedNotebook() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCreateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> LinkedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequest, + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::onCreateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::createLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onCreateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + LinkedNotebook res = noteStore->createLinkedNotebook( + linkedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteCreateLinkedNotebookAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + LinkedNotebook response = generateRandomLinkedNotebook(); + + NoteStoreCreateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> LinkedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequest, + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::onCreateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::createLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onCreateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->createLinkedNotebookAsync( + linkedNotebook, + ctx); + + NoteStoreCreateLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInCreateLinkedNotebookAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_LONG; + userException.parameter = generateRandomString(); + + NoteStoreCreateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> LinkedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequest, + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::onCreateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::createLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onCreateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createLinkedNotebookAsync( + linkedNotebook, + ctx); + + NoteStoreCreateLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInCreateLinkedNotebookAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreCreateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> LinkedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequest, + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::onCreateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::createLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onCreateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createLinkedNotebookAsync( + linkedNotebook, + ctx); + + NoteStoreCreateLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInCreateLinkedNotebookAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreCreateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> LinkedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequest, + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::onCreateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::createLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onCreateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createLinkedNotebookAsync( + linkedNotebook, + ctx); + + NoteStoreCreateLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInCreateLinkedNotebookAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreCreateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> LinkedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequest, + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::onCreateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreCreateLinkedNotebookTesterHelper::createLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onCreateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::createLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->createLinkedNotebookAsync( + linkedNotebook, + ctx); + + NoteStoreCreateLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreCreateLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreCreateLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteUpdateLinkedNotebook() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUpdateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequest, + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::onUpdateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::updateLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->updateLinkedNotebook( + linkedNotebook, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateLinkedNotebook() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::OPENID_ALREADY_TAKEN; + userException.parameter = generateRandomString(); + + NoteStoreUpdateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequest, + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::onUpdateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::updateLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateLinkedNotebook( + linkedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateLinkedNotebook() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequest, + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::onUpdateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::updateLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateLinkedNotebook( + linkedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateLinkedNotebook() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequest, + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::onUpdateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::updateLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateLinkedNotebook( + linkedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateLinkedNotebook() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequest, + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::onUpdateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::updateLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->updateLinkedNotebook( + linkedNotebook, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteUpdateLinkedNotebookAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreUpdateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequest, + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::onUpdateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::updateLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->updateLinkedNotebookAsync( + linkedNotebook, + ctx); + + NoteStoreUpdateLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateLinkedNotebookAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + userException.parameter = generateRandomString(); + + NoteStoreUpdateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequest, + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::onUpdateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::updateLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateLinkedNotebookAsync( + linkedNotebook, + ctx); + + NoteStoreUpdateLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateLinkedNotebookAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequest, + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::onUpdateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::updateLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateLinkedNotebookAsync( + linkedNotebook, + ctx); + + NoteStoreUpdateLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateLinkedNotebookAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::SHARD_UNAVAILABLE; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequest, + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::onUpdateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::updateLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateLinkedNotebookAsync( + linkedNotebook, + ctx); + + NoteStoreUpdateLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateLinkedNotebookAsync() +{ + LinkedNotebook linkedNotebook = generateRandomLinkedNotebook(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateLinkedNotebookTesterHelper helper( + [&] (const LinkedNotebook & linkedNotebookParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(linkedNotebook == linkedNotebookParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequest, + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::onUpdateLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateLinkedNotebookTesterHelper::updateLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onUpdateLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateLinkedNotebookAsync( + linkedNotebook, + ctx); + + NoteStoreUpdateLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteListLinkedNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomLinkedNotebook(); + response << generateRandomLinkedNotebook(); + response << generateRandomLinkedNotebook(); + + NoteStoreListLinkedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequest, + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::onListLinkedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::listLinkedNotebooksRequestReady, + &server, + &NoteStoreServer::onListLinkedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QList res = noteStore->listLinkedNotebooks( + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListLinkedNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_FEW; + userException.parameter = generateRandomString(); + + NoteStoreListLinkedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequest, + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::onListLinkedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::listLinkedNotebooksRequestReady, + &server, + &NoteStoreServer::onListLinkedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listLinkedNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInListLinkedNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreListLinkedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequest, + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::onListLinkedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::listLinkedNotebooksRequestReady, + &server, + &NoteStoreServer::onListLinkedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listLinkedNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListLinkedNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LEN_TOO_LONG; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListLinkedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequest, + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::onListLinkedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::listLinkedNotebooksRequestReady, + &server, + &NoteStoreServer::onListLinkedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listLinkedNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListLinkedNotebooks() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListLinkedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequest, + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::onListLinkedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::listLinkedNotebooksRequestReady, + &server, + &NoteStoreServer::onListLinkedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = noteStore->listLinkedNotebooks( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteListLinkedNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomLinkedNotebook(); + response << generateRandomLinkedNotebook(); + response << generateRandomLinkedNotebook(); + + NoteStoreListLinkedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequest, + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::onListLinkedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::listLinkedNotebooksRequestReady, + &server, + &NoteStoreServer::onListLinkedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->listLinkedNotebooksAsync( + ctx); + + NoteStoreListLinkedNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListLinkedNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListLinkedNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInListLinkedNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + userException.parameter = generateRandomString(); + + NoteStoreListLinkedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequest, + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::onListLinkedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::listLinkedNotebooksRequestReady, + &server, + &NoteStoreServer::onListLinkedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listLinkedNotebooksAsync( + ctx); + + NoteStoreListLinkedNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListLinkedNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListLinkedNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInListLinkedNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreListLinkedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequest, + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::onListLinkedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::listLinkedNotebooksRequestReady, + &server, + &NoteStoreServer::onListLinkedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listLinkedNotebooksAsync( + ctx); + + NoteStoreListLinkedNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListLinkedNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListLinkedNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInListLinkedNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DATA_CONFLICT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreListLinkedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequest, + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::onListLinkedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::listLinkedNotebooksRequestReady, + &server, + &NoteStoreServer::onListLinkedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listLinkedNotebooksAsync( + ctx); + + NoteStoreListLinkedNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListLinkedNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListLinkedNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInListLinkedNotebooksAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreListLinkedNotebooksTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequest, + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::onListLinkedNotebooksRequestReceived); + QObject::connect( + &helper, + &NoteStoreListLinkedNotebooksTesterHelper::listLinkedNotebooksRequestReady, + &server, + &NoteStoreServer::onListLinkedNotebooksRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::listLinkedNotebooksRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->listLinkedNotebooksAsync( + ctx); + + NoteStoreListLinkedNotebooksAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreListLinkedNotebooksAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreListLinkedNotebooksAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteExpungeLinkedNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreExpungeLinkedNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequest, + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::onExpungeLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::expungeLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + qint32 res = noteStore->expungeLinkedNotebook( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInExpungeLinkedNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::SHARD_UNAVAILABLE; + userException.parameter = generateRandomString(); + + NoteStoreExpungeLinkedNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequest, + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::onExpungeLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::expungeLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeLinkedNotebook( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInExpungeLinkedNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreExpungeLinkedNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequest, + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::onExpungeLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::expungeLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeLinkedNotebook( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInExpungeLinkedNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ENML_VALIDATION; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreExpungeLinkedNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequest, + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::onExpungeLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::expungeLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeLinkedNotebook( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInExpungeLinkedNotebook() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreExpungeLinkedNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequest, + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::onExpungeLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::expungeLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + qint32 res = noteStore->expungeLinkedNotebook( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteExpungeLinkedNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + qint32 response = generateRandomInt32(); + + NoteStoreExpungeLinkedNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequest, + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::onExpungeLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::expungeLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->expungeLinkedNotebookAsync( + guid, + ctx); + + NoteStoreExpungeLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInExpungeLinkedNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::RATE_LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreExpungeLinkedNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequest, + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::onExpungeLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::expungeLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeLinkedNotebookAsync( + guid, + ctx); + + NoteStoreExpungeLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInExpungeLinkedNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreExpungeLinkedNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequest, + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::onExpungeLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::expungeLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeLinkedNotebookAsync( + guid, + ctx); + + NoteStoreExpungeLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInExpungeLinkedNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreExpungeLinkedNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequest, + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::onExpungeLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::expungeLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeLinkedNotebookAsync( + guid, + ctx); + + NoteStoreExpungeLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInExpungeLinkedNotebookAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreExpungeLinkedNotebookTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> qint32 + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequest, + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::onExpungeLinkedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreExpungeLinkedNotebookTesterHelper::expungeLinkedNotebookRequestReady, + &server, + &NoteStoreServer::onExpungeLinkedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::expungeLinkedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->expungeLinkedNotebookAsync( + guid, + ctx); + + NoteStoreExpungeLinkedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreExpungeLinkedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreExpungeLinkedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteAuthenticateToSharedNotebook() +{ + QString shareKeyOrGlobalId = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + AuthenticationResult response = generateRandomAuthenticationResult(); + + NoteStoreAuthenticateToSharedNotebookTesterHelper helper( + [&] (const QString & shareKeyOrGlobalIdParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(shareKeyOrGlobalId == shareKeyOrGlobalIdParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequest, + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::onAuthenticateToSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::authenticateToSharedNotebookRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AuthenticationResult res = noteStore->authenticateToSharedNotebook( + shareKeyOrGlobalId, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInAuthenticateToSharedNotebook() +{ + QString shareKeyOrGlobalId = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + userException.parameter = generateRandomString(); + + NoteStoreAuthenticateToSharedNotebookTesterHelper helper( + [&] (const QString & shareKeyOrGlobalIdParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(shareKeyOrGlobalId == shareKeyOrGlobalIdParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequest, + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::onAuthenticateToSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::authenticateToSharedNotebookRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = noteStore->authenticateToSharedNotebook( + shareKeyOrGlobalId, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInAuthenticateToSharedNotebook() +{ + QString shareKeyOrGlobalId = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreAuthenticateToSharedNotebookTesterHelper helper( + [&] (const QString & shareKeyOrGlobalIdParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(shareKeyOrGlobalId == shareKeyOrGlobalIdParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequest, + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::onAuthenticateToSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::authenticateToSharedNotebookRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = noteStore->authenticateToSharedNotebook( + shareKeyOrGlobalId, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInAuthenticateToSharedNotebook() +{ + QString shareKeyOrGlobalId = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_NOT_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreAuthenticateToSharedNotebookTesterHelper helper( + [&] (const QString & shareKeyOrGlobalIdParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(shareKeyOrGlobalId == shareKeyOrGlobalIdParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequest, + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::onAuthenticateToSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::authenticateToSharedNotebookRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = noteStore->authenticateToSharedNotebook( + shareKeyOrGlobalId, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInAuthenticateToSharedNotebook() +{ + QString shareKeyOrGlobalId = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreAuthenticateToSharedNotebookTesterHelper helper( + [&] (const QString & shareKeyOrGlobalIdParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(shareKeyOrGlobalId == shareKeyOrGlobalIdParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequest, + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::onAuthenticateToSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::authenticateToSharedNotebookRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = noteStore->authenticateToSharedNotebook( + shareKeyOrGlobalId, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteAuthenticateToSharedNotebookAsync() +{ + QString shareKeyOrGlobalId = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + AuthenticationResult response = generateRandomAuthenticationResult(); + + NoteStoreAuthenticateToSharedNotebookTesterHelper helper( + [&] (const QString & shareKeyOrGlobalIdParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(shareKeyOrGlobalId == shareKeyOrGlobalIdParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequest, + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::onAuthenticateToSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::authenticateToSharedNotebookRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->authenticateToSharedNotebookAsync( + shareKeyOrGlobalId, + ctx); + + NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInAuthenticateToSharedNotebookAsync() +{ + QString shareKeyOrGlobalId = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreAuthenticateToSharedNotebookTesterHelper helper( + [&] (const QString & shareKeyOrGlobalIdParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(shareKeyOrGlobalId == shareKeyOrGlobalIdParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequest, + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::onAuthenticateToSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::authenticateToSharedNotebookRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->authenticateToSharedNotebookAsync( + shareKeyOrGlobalId, + ctx); + + NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInAuthenticateToSharedNotebookAsync() +{ + QString shareKeyOrGlobalId = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreAuthenticateToSharedNotebookTesterHelper helper( + [&] (const QString & shareKeyOrGlobalIdParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(shareKeyOrGlobalId == shareKeyOrGlobalIdParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequest, + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::onAuthenticateToSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::authenticateToSharedNotebookRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->authenticateToSharedNotebookAsync( + shareKeyOrGlobalId, + ctx); + + NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInAuthenticateToSharedNotebookAsync() +{ + QString shareKeyOrGlobalId = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreAuthenticateToSharedNotebookTesterHelper helper( + [&] (const QString & shareKeyOrGlobalIdParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(shareKeyOrGlobalId == shareKeyOrGlobalIdParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequest, + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::onAuthenticateToSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::authenticateToSharedNotebookRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->authenticateToSharedNotebookAsync( + shareKeyOrGlobalId, + ctx); + + NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInAuthenticateToSharedNotebookAsync() +{ + QString shareKeyOrGlobalId = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreAuthenticateToSharedNotebookTesterHelper helper( + [&] (const QString & shareKeyOrGlobalIdParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(shareKeyOrGlobalId == shareKeyOrGlobalIdParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequest, + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::onAuthenticateToSharedNotebookRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNotebookTesterHelper::authenticateToSharedNotebookRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNotebookRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNotebookRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->authenticateToSharedNotebookAsync( + shareKeyOrGlobalId, + ctx); + + NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreAuthenticateToSharedNotebookAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetSharedNotebookByAuth() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SharedNotebook response = generateRandomSharedNotebook(); + + NoteStoreGetSharedNotebookByAuthTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequest, + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::onGetSharedNotebookByAuthRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::getSharedNotebookByAuthRequestReady, + &server, + &NoteStoreServer::onGetSharedNotebookByAuthRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + SharedNotebook res = noteStore->getSharedNotebookByAuth( + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetSharedNotebookByAuth() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + userException.parameter = generateRandomString(); + + NoteStoreGetSharedNotebookByAuthTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequest, + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::onGetSharedNotebookByAuthRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::getSharedNotebookByAuthRequestReady, + &server, + &NoteStoreServer::onGetSharedNotebookByAuthRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SharedNotebook res = noteStore->getSharedNotebookByAuth( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetSharedNotebookByAuth() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetSharedNotebookByAuthTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequest, + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::onGetSharedNotebookByAuthRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::getSharedNotebookByAuthRequestReady, + &server, + &NoteStoreServer::onGetSharedNotebookByAuthRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SharedNotebook res = noteStore->getSharedNotebookByAuth( + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetSharedNotebookByAuth() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ENML_VALIDATION; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetSharedNotebookByAuthTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequest, + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::onGetSharedNotebookByAuthRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::getSharedNotebookByAuthRequestReady, + &server, + &NoteStoreServer::onGetSharedNotebookByAuthRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SharedNotebook res = noteStore->getSharedNotebookByAuth( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetSharedNotebookByAuth() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetSharedNotebookByAuthTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequest, + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::onGetSharedNotebookByAuthRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::getSharedNotebookByAuthRequestReady, + &server, + &NoteStoreServer::onGetSharedNotebookByAuthRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + SharedNotebook res = noteStore->getSharedNotebookByAuth( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetSharedNotebookByAuthAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + SharedNotebook response = generateRandomSharedNotebook(); + + NoteStoreGetSharedNotebookByAuthTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequest, + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::onGetSharedNotebookByAuthRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::getSharedNotebookByAuthRequestReady, + &server, + &NoteStoreServer::onGetSharedNotebookByAuthRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getSharedNotebookByAuthAsync( + ctx); + + NoteStoreGetSharedNotebookByAuthAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSharedNotebookByAuthAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSharedNotebookByAuthAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetSharedNotebookByAuthAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_SHORT; + userException.parameter = generateRandomString(); + + NoteStoreGetSharedNotebookByAuthTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequest, + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::onGetSharedNotebookByAuthRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::getSharedNotebookByAuthRequestReady, + &server, + &NoteStoreServer::onGetSharedNotebookByAuthRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getSharedNotebookByAuthAsync( + ctx); + + NoteStoreGetSharedNotebookByAuthAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSharedNotebookByAuthAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSharedNotebookByAuthAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetSharedNotebookByAuthAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetSharedNotebookByAuthTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequest, + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::onGetSharedNotebookByAuthRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::getSharedNotebookByAuthRequestReady, + &server, + &NoteStoreServer::onGetSharedNotebookByAuthRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getSharedNotebookByAuthAsync( + ctx); + + NoteStoreGetSharedNotebookByAuthAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSharedNotebookByAuthAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSharedNotebookByAuthAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetSharedNotebookByAuthAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::UNKNOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetSharedNotebookByAuthTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequest, + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::onGetSharedNotebookByAuthRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::getSharedNotebookByAuthRequestReady, + &server, + &NoteStoreServer::onGetSharedNotebookByAuthRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getSharedNotebookByAuthAsync( + ctx); + + NoteStoreGetSharedNotebookByAuthAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSharedNotebookByAuthAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSharedNotebookByAuthAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetSharedNotebookByAuthAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetSharedNotebookByAuthTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> SharedNotebook + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequest, + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::onGetSharedNotebookByAuthRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetSharedNotebookByAuthTesterHelper::getSharedNotebookByAuthRequestReady, + &server, + &NoteStoreServer::onGetSharedNotebookByAuthRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getSharedNotebookByAuthRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getSharedNotebookByAuthAsync( + ctx); + + NoteStoreGetSharedNotebookByAuthAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetSharedNotebookByAuthAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetSharedNotebookByAuthAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteEmailNote() +{ + NoteEmailParameters parameters = generateRandomNoteEmailParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + NoteStoreEmailNoteTesterHelper helper( + [&] (const NoteEmailParameters & parametersParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + return; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequest, + &helper, + &NoteStoreEmailNoteTesterHelper::onEmailNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreEmailNoteTesterHelper::emailNoteRequestReady, + &server, + &NoteStoreServer::onEmailNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + noteStore->emailNote( + parameters, + ctx); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInEmailNote() +{ + NoteEmailParameters parameters = generateRandomNoteEmailParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreEmailNoteTesterHelper helper( + [&] (const NoteEmailParameters & parametersParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequest, + &helper, + &NoteStoreEmailNoteTesterHelper::onEmailNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreEmailNoteTesterHelper::emailNoteRequestReady, + &server, + &NoteStoreServer::onEmailNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + noteStore->emailNote( + parameters, + ctx); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInEmailNote() +{ + NoteEmailParameters parameters = generateRandomNoteEmailParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreEmailNoteTesterHelper helper( + [&] (const NoteEmailParameters & parametersParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequest, + &helper, + &NoteStoreEmailNoteTesterHelper::onEmailNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreEmailNoteTesterHelper::emailNoteRequestReady, + &server, + &NoteStoreServer::onEmailNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + noteStore->emailNote( + parameters, + ctx); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInEmailNote() +{ + NoteEmailParameters parameters = generateRandomNoteEmailParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_NOT_REGISTERED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreEmailNoteTesterHelper helper( + [&] (const NoteEmailParameters & parametersParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequest, + &helper, + &NoteStoreEmailNoteTesterHelper::onEmailNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreEmailNoteTesterHelper::emailNoteRequestReady, + &server, + &NoteStoreServer::onEmailNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + noteStore->emailNote( + parameters, + ctx); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInEmailNote() +{ + NoteEmailParameters parameters = generateRandomNoteEmailParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreEmailNoteTesterHelper helper( + [&] (const NoteEmailParameters & parametersParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequest, + &helper, + &NoteStoreEmailNoteTesterHelper::onEmailNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreEmailNoteTesterHelper::emailNoteRequestReady, + &server, + &NoteStoreServer::onEmailNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + noteStore->emailNote( + parameters, + ctx); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteEmailNoteAsync() +{ + NoteEmailParameters parameters = generateRandomNoteEmailParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + NoteStoreEmailNoteTesterHelper helper( + [&] (const NoteEmailParameters & parametersParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + return; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequest, + &helper, + &NoteStoreEmailNoteTesterHelper::onEmailNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreEmailNoteTesterHelper::emailNoteRequestReady, + &server, + &NoteStoreServer::onEmailNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->emailNoteAsync( + parameters, + ctx); + + NoteStoreEmailNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreEmailNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreEmailNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInEmailNoteAsync() +{ + NoteEmailParameters parameters = generateRandomNoteEmailParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::AUTH_EXPIRED; + userException.parameter = generateRandomString(); + + NoteStoreEmailNoteTesterHelper helper( + [&] (const NoteEmailParameters & parametersParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequest, + &helper, + &NoteStoreEmailNoteTesterHelper::onEmailNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreEmailNoteTesterHelper::emailNoteRequestReady, + &server, + &NoteStoreServer::onEmailNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->emailNoteAsync( + parameters, + ctx); + + NoteStoreEmailNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreEmailNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreEmailNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInEmailNoteAsync() +{ + NoteEmailParameters parameters = generateRandomNoteEmailParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreEmailNoteTesterHelper helper( + [&] (const NoteEmailParameters & parametersParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequest, + &helper, + &NoteStoreEmailNoteTesterHelper::onEmailNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreEmailNoteTesterHelper::emailNoteRequestReady, + &server, + &NoteStoreServer::onEmailNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->emailNoteAsync( + parameters, + ctx); + + NoteStoreEmailNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreEmailNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreEmailNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInEmailNoteAsync() +{ + NoteEmailParameters parameters = generateRandomNoteEmailParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BAD_DATA_FORMAT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreEmailNoteTesterHelper helper( + [&] (const NoteEmailParameters & parametersParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequest, + &helper, + &NoteStoreEmailNoteTesterHelper::onEmailNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreEmailNoteTesterHelper::emailNoteRequestReady, + &server, + &NoteStoreServer::onEmailNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->emailNoteAsync( + parameters, + ctx); + + NoteStoreEmailNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreEmailNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreEmailNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInEmailNoteAsync() +{ + NoteEmailParameters parameters = generateRandomNoteEmailParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreEmailNoteTesterHelper helper( + [&] (const NoteEmailParameters & parametersParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequest, + &helper, + &NoteStoreEmailNoteTesterHelper::onEmailNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreEmailNoteTesterHelper::emailNoteRequestReady, + &server, + &NoteStoreServer::onEmailNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::emailNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->emailNoteAsync( + parameters, + ctx); + + NoteStoreEmailNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreEmailNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreEmailNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteShareNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QString response = generateRandomString(); + + NoteStoreShareNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequest, + &helper, + &NoteStoreShareNoteTesterHelper::onShareNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNoteTesterHelper::shareNoteRequestReady, + &server, + &NoteStoreServer::onShareNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QString res = noteStore->shareNote( + guid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInShareNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreShareNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequest, + &helper, + &NoteStoreShareNoteTesterHelper::onShareNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNoteTesterHelper::shareNoteRequestReady, + &server, + &NoteStoreServer::onShareNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->shareNote( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInShareNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreShareNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequest, + &helper, + &NoteStoreShareNoteTesterHelper::onShareNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNoteTesterHelper::shareNoteRequestReady, + &server, + &NoteStoreServer::onShareNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->shareNote( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInShareNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TOO_MANY; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreShareNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequest, + &helper, + &NoteStoreShareNoteTesterHelper::onShareNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNoteTesterHelper::shareNoteRequestReady, + &server, + &NoteStoreServer::onShareNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->shareNote( + guid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInShareNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreShareNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequest, + &helper, + &NoteStoreShareNoteTesterHelper::onShareNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNoteTesterHelper::shareNoteRequestReady, + &server, + &NoteStoreServer::onShareNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QString res = noteStore->shareNote( + guid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteShareNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QString response = generateRandomString(); + + NoteStoreShareNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequest, + &helper, + &NoteStoreShareNoteTesterHelper::onShareNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNoteTesterHelper::shareNoteRequestReady, + &server, + &NoteStoreServer::onShareNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->shareNoteAsync( + guid, + ctx); + + NoteStoreShareNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreShareNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreShareNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInShareNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreShareNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequest, + &helper, + &NoteStoreShareNoteTesterHelper::onShareNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNoteTesterHelper::shareNoteRequestReady, + &server, + &NoteStoreServer::onShareNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->shareNoteAsync( + guid, + ctx); + + NoteStoreShareNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreShareNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreShareNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInShareNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreShareNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequest, + &helper, + &NoteStoreShareNoteTesterHelper::onShareNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNoteTesterHelper::shareNoteRequestReady, + &server, + &NoteStoreServer::onShareNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->shareNoteAsync( + guid, + ctx); + + NoteStoreShareNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreShareNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreShareNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInShareNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_AUTH; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreShareNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequest, + &helper, + &NoteStoreShareNoteTesterHelper::onShareNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNoteTesterHelper::shareNoteRequestReady, + &server, + &NoteStoreServer::onShareNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->shareNoteAsync( + guid, + ctx); + + NoteStoreShareNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreShareNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreShareNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInShareNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreShareNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> QString + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequest, + &helper, + &NoteStoreShareNoteTesterHelper::onShareNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreShareNoteTesterHelper::shareNoteRequestReady, + &server, + &NoteStoreServer::onShareNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::shareNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->shareNoteAsync( + guid, + ctx); + + NoteStoreShareNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreShareNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreShareNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteStopSharingNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + NoteStoreStopSharingNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequest, + &helper, + &NoteStoreStopSharingNoteTesterHelper::onStopSharingNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreStopSharingNoteTesterHelper::stopSharingNoteRequestReady, + &server, + &NoteStoreServer::onStopSharingNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + noteStore->stopSharingNote( + guid, + ctx); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInStopSharingNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + userException.parameter = generateRandomString(); + + NoteStoreStopSharingNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequest, + &helper, + &NoteStoreStopSharingNoteTesterHelper::onStopSharingNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreStopSharingNoteTesterHelper::stopSharingNoteRequestReady, + &server, + &NoteStoreServer::onStopSharingNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + noteStore->stopSharingNote( + guid, + ctx); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInStopSharingNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreStopSharingNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequest, + &helper, + &NoteStoreStopSharingNoteTesterHelper::onStopSharingNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreStopSharingNoteTesterHelper::stopSharingNoteRequestReady, + &server, + &NoteStoreServer::onStopSharingNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + noteStore->stopSharingNote( + guid, + ctx); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInStopSharingNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TAKEN_DOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreStopSharingNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequest, + &helper, + &NoteStoreStopSharingNoteTesterHelper::onStopSharingNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreStopSharingNoteTesterHelper::stopSharingNoteRequestReady, + &server, + &NoteStoreServer::onStopSharingNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + noteStore->stopSharingNote( + guid, + ctx); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInStopSharingNote() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreStopSharingNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequest, + &helper, + &NoteStoreStopSharingNoteTesterHelper::onStopSharingNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreStopSharingNoteTesterHelper::stopSharingNoteRequestReady, + &server, + &NoteStoreServer::onStopSharingNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + noteStore->stopSharingNote( + guid, + ctx); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteStopSharingNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + NoteStoreStopSharingNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + return; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequest, + &helper, + &NoteStoreStopSharingNoteTesterHelper::onStopSharingNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreStopSharingNoteTesterHelper::stopSharingNoteRequestReady, + &server, + &NoteStoreServer::onStopSharingNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->stopSharingNoteAsync( + guid, + ctx); + + NoteStoreStopSharingNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreStopSharingNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreStopSharingNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInStopSharingNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::RATE_LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreStopSharingNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequest, + &helper, + &NoteStoreStopSharingNoteTesterHelper::onStopSharingNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreStopSharingNoteTesterHelper::stopSharingNoteRequestReady, + &server, + &NoteStoreServer::onStopSharingNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->stopSharingNoteAsync( + guid, + ctx); + + NoteStoreStopSharingNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreStopSharingNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreStopSharingNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInStopSharingNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreStopSharingNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequest, + &helper, + &NoteStoreStopSharingNoteTesterHelper::onStopSharingNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreStopSharingNoteTesterHelper::stopSharingNoteRequestReady, + &server, + &NoteStoreServer::onStopSharingNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->stopSharingNoteAsync( + guid, + ctx); + + NoteStoreStopSharingNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreStopSharingNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreStopSharingNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInStopSharingNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_NOT_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreStopSharingNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequest, + &helper, + &NoteStoreStopSharingNoteTesterHelper::onStopSharingNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreStopSharingNoteTesterHelper::stopSharingNoteRequestReady, + &server, + &NoteStoreServer::onStopSharingNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->stopSharingNoteAsync( + guid, + ctx); + + NoteStoreStopSharingNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreStopSharingNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreStopSharingNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInStopSharingNoteAsync() +{ + Guid guid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreStopSharingNoteTesterHelper helper( + [&] (const Guid & guidParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(guid == guidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequest, + &helper, + &NoteStoreStopSharingNoteTesterHelper::onStopSharingNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreStopSharingNoteTesterHelper::stopSharingNoteRequestReady, + &server, + &NoteStoreServer::onStopSharingNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::stopSharingNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->stopSharingNoteAsync( + guid, + ctx); + + NoteStoreStopSharingNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreStopSharingNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreStopSharingNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteAuthenticateToSharedNote() +{ + QString guid = generateRandomString(); + QString noteKey = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + AuthenticationResult response = generateRandomAuthenticationResult(); + + NoteStoreAuthenticateToSharedNoteTesterHelper helper( + [&] (const QString & guidParam, + const QString & noteKeyParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteKey == noteKeyParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequest, + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::onAuthenticateToSharedNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::authenticateToSharedNoteRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AuthenticationResult res = noteStore->authenticateToSharedNote( + guid, + noteKey, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInAuthenticateToSharedNote() +{ + QString guid = generateRandomString(); + QString noteKey = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_FEW; + userException.parameter = generateRandomString(); + + NoteStoreAuthenticateToSharedNoteTesterHelper helper( + [&] (const QString & guidParam, + const QString & noteKeyParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteKey == noteKeyParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequest, + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::onAuthenticateToSharedNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::authenticateToSharedNoteRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = noteStore->authenticateToSharedNote( + guid, + noteKey, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInAuthenticateToSharedNote() +{ + QString guid = generateRandomString(); + QString noteKey = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreAuthenticateToSharedNoteTesterHelper helper( + [&] (const QString & guidParam, + const QString & noteKeyParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteKey == noteKeyParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequest, + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::onAuthenticateToSharedNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::authenticateToSharedNoteRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = noteStore->authenticateToSharedNote( + guid, + noteKey, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInAuthenticateToSharedNote() +{ + QString guid = generateRandomString(); + QString noteKey = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::RATE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreAuthenticateToSharedNoteTesterHelper helper( + [&] (const QString & guidParam, + const QString & noteKeyParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteKey == noteKeyParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequest, + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::onAuthenticateToSharedNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::authenticateToSharedNoteRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = noteStore->authenticateToSharedNote( + guid, + noteKey, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInAuthenticateToSharedNote() +{ + QString guid = generateRandomString(); + QString noteKey = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreAuthenticateToSharedNoteTesterHelper helper( + [&] (const QString & guidParam, + const QString & noteKeyParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteKey == noteKeyParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequest, + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::onAuthenticateToSharedNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::authenticateToSharedNoteRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = noteStore->authenticateToSharedNote( + guid, + noteKey, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteAuthenticateToSharedNoteAsync() +{ + QString guid = generateRandomString(); + QString noteKey = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + AuthenticationResult response = generateRandomAuthenticationResult(); + + NoteStoreAuthenticateToSharedNoteTesterHelper helper( + [&] (const QString & guidParam, + const QString & noteKeyParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteKey == noteKeyParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequest, + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::onAuthenticateToSharedNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::authenticateToSharedNoteRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->authenticateToSharedNoteAsync( + guid, + noteKey, + ctx); + + NoteStoreAuthenticateToSharedNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreAuthenticateToSharedNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreAuthenticateToSharedNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInAuthenticateToSharedNoteAsync() +{ + QString guid = generateRandomString(); + QString noteKey = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::QUOTA_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreAuthenticateToSharedNoteTesterHelper helper( + [&] (const QString & guidParam, + const QString & noteKeyParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteKey == noteKeyParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequest, + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::onAuthenticateToSharedNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::authenticateToSharedNoteRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->authenticateToSharedNoteAsync( + guid, + noteKey, + ctx); + + NoteStoreAuthenticateToSharedNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreAuthenticateToSharedNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreAuthenticateToSharedNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInAuthenticateToSharedNoteAsync() +{ + QString guid = generateRandomString(); + QString noteKey = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreAuthenticateToSharedNoteTesterHelper helper( + [&] (const QString & guidParam, + const QString & noteKeyParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteKey == noteKeyParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequest, + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::onAuthenticateToSharedNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::authenticateToSharedNoteRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->authenticateToSharedNoteAsync( + guid, + noteKey, + ctx); + + NoteStoreAuthenticateToSharedNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreAuthenticateToSharedNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreAuthenticateToSharedNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInAuthenticateToSharedNoteAsync() +{ + QString guid = generateRandomString(); + QString noteKey = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::UNKNOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreAuthenticateToSharedNoteTesterHelper helper( + [&] (const QString & guidParam, + const QString & noteKeyParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteKey == noteKeyParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequest, + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::onAuthenticateToSharedNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::authenticateToSharedNoteRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->authenticateToSharedNoteAsync( + guid, + noteKey, + ctx); + + NoteStoreAuthenticateToSharedNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreAuthenticateToSharedNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreAuthenticateToSharedNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInAuthenticateToSharedNoteAsync() +{ + QString guid = generateRandomString(); + QString noteKey = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreAuthenticateToSharedNoteTesterHelper helper( + [&] (const QString & guidParam, + const QString & noteKeyParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(guid == guidParam); + Q_ASSERT(noteKey == noteKeyParam); + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequest, + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::onAuthenticateToSharedNoteRequestReceived); + QObject::connect( + &helper, + &NoteStoreAuthenticateToSharedNoteTesterHelper::authenticateToSharedNoteRequestReady, + &server, + &NoteStoreServer::onAuthenticateToSharedNoteRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::authenticateToSharedNoteRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->authenticateToSharedNoteAsync( + guid, + noteKey, + ctx); + + NoteStoreAuthenticateToSharedNoteAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreAuthenticateToSharedNoteAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreAuthenticateToSharedNoteAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteFindRelated() +{ + RelatedQuery query = generateRandomRelatedQuery(); + RelatedResultSpec resultSpec = generateRandomRelatedResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + RelatedResult response = generateRandomRelatedResult(); + + NoteStoreFindRelatedTesterHelper helper( + [&] (const RelatedQuery & queryParam, + const RelatedResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> RelatedResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(query == queryParam); + Q_ASSERT(resultSpec == resultSpecParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequest, + &helper, + &NoteStoreFindRelatedTesterHelper::onFindRelatedRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindRelatedTesterHelper::findRelatedRequestReady, + &server, + &NoteStoreServer::onFindRelatedRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + RelatedResult res = noteStore->findRelated( + query, + resultSpec, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInFindRelated() +{ + RelatedQuery query = generateRandomRelatedQuery(); + RelatedResultSpec resultSpec = generateRandomRelatedResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INTERNAL_ERROR; + userException.parameter = generateRandomString(); + + NoteStoreFindRelatedTesterHelper helper( + [&] (const RelatedQuery & queryParam, + const RelatedResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> RelatedResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(query == queryParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequest, + &helper, + &NoteStoreFindRelatedTesterHelper::onFindRelatedRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindRelatedTesterHelper::findRelatedRequestReady, + &server, + &NoteStoreServer::onFindRelatedRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + RelatedResult res = noteStore->findRelated( + query, + resultSpec, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInFindRelated() +{ + RelatedQuery query = generateRandomRelatedQuery(); + RelatedResultSpec resultSpec = generateRandomRelatedResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LEN_TOO_LONG; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreFindRelatedTesterHelper helper( + [&] (const RelatedQuery & queryParam, + const RelatedResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> RelatedResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(query == queryParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequest, + &helper, + &NoteStoreFindRelatedTesterHelper::onFindRelatedRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindRelatedTesterHelper::findRelatedRequestReady, + &server, + &NoteStoreServer::onFindRelatedRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + RelatedResult res = noteStore->findRelated( + query, + resultSpec, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInFindRelated() +{ + RelatedQuery query = generateRandomRelatedQuery(); + RelatedResultSpec resultSpec = generateRandomRelatedResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreFindRelatedTesterHelper helper( + [&] (const RelatedQuery & queryParam, + const RelatedResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> RelatedResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(query == queryParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequest, + &helper, + &NoteStoreFindRelatedTesterHelper::onFindRelatedRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindRelatedTesterHelper::findRelatedRequestReady, + &server, + &NoteStoreServer::onFindRelatedRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + RelatedResult res = noteStore->findRelated( + query, + resultSpec, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInFindRelated() +{ + RelatedQuery query = generateRandomRelatedQuery(); + RelatedResultSpec resultSpec = generateRandomRelatedResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreFindRelatedTesterHelper helper( + [&] (const RelatedQuery & queryParam, + const RelatedResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> RelatedResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(query == queryParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequest, + &helper, + &NoteStoreFindRelatedTesterHelper::onFindRelatedRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindRelatedTesterHelper::findRelatedRequestReady, + &server, + &NoteStoreServer::onFindRelatedRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + RelatedResult res = noteStore->findRelated( + query, + resultSpec, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteFindRelatedAsync() +{ + RelatedQuery query = generateRandomRelatedQuery(); + RelatedResultSpec resultSpec = generateRandomRelatedResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + RelatedResult response = generateRandomRelatedResult(); + + NoteStoreFindRelatedTesterHelper helper( + [&] (const RelatedQuery & queryParam, + const RelatedResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> RelatedResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(query == queryParam); + Q_ASSERT(resultSpec == resultSpecParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequest, + &helper, + &NoteStoreFindRelatedTesterHelper::onFindRelatedRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindRelatedTesterHelper::findRelatedRequestReady, + &server, + &NoteStoreServer::onFindRelatedRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->findRelatedAsync( + query, + resultSpec, + ctx); + + NoteStoreFindRelatedAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindRelatedAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindRelatedAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInFindRelatedAsync() +{ + RelatedQuery query = generateRandomRelatedQuery(); + RelatedResultSpec resultSpec = generateRandomRelatedResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DATA_CONFLICT; + userException.parameter = generateRandomString(); + + NoteStoreFindRelatedTesterHelper helper( + [&] (const RelatedQuery & queryParam, + const RelatedResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> RelatedResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(query == queryParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequest, + &helper, + &NoteStoreFindRelatedTesterHelper::onFindRelatedRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindRelatedTesterHelper::findRelatedRequestReady, + &server, + &NoteStoreServer::onFindRelatedRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findRelatedAsync( + query, + resultSpec, + ctx); + + NoteStoreFindRelatedAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindRelatedAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindRelatedAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInFindRelatedAsync() +{ + RelatedQuery query = generateRandomRelatedQuery(); + RelatedResultSpec resultSpec = generateRandomRelatedResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ACCOUNT_CLEAR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreFindRelatedTesterHelper helper( + [&] (const RelatedQuery & queryParam, + const RelatedResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> RelatedResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(query == queryParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequest, + &helper, + &NoteStoreFindRelatedTesterHelper::onFindRelatedRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindRelatedTesterHelper::findRelatedRequestReady, + &server, + &NoteStoreServer::onFindRelatedRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findRelatedAsync( + query, + resultSpec, + ctx); + + NoteStoreFindRelatedAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindRelatedAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindRelatedAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInFindRelatedAsync() +{ + RelatedQuery query = generateRandomRelatedQuery(); + RelatedResultSpec resultSpec = generateRandomRelatedResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreFindRelatedTesterHelper helper( + [&] (const RelatedQuery & queryParam, + const RelatedResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> RelatedResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(query == queryParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequest, + &helper, + &NoteStoreFindRelatedTesterHelper::onFindRelatedRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindRelatedTesterHelper::findRelatedRequestReady, + &server, + &NoteStoreServer::onFindRelatedRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findRelatedAsync( + query, + resultSpec, + ctx); + + NoteStoreFindRelatedAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindRelatedAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindRelatedAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInFindRelatedAsync() +{ + RelatedQuery query = generateRandomRelatedQuery(); + RelatedResultSpec resultSpec = generateRandomRelatedResultSpec(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreFindRelatedTesterHelper helper( + [&] (const RelatedQuery & queryParam, + const RelatedResultSpec & resultSpecParam, + IRequestContextPtr ctxParam) -> RelatedResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(query == queryParam); + Q_ASSERT(resultSpec == resultSpecParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequest, + &helper, + &NoteStoreFindRelatedTesterHelper::onFindRelatedRequestReceived); + QObject::connect( + &helper, + &NoteStoreFindRelatedTesterHelper::findRelatedRequestReady, + &server, + &NoteStoreServer::onFindRelatedRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::findRelatedRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->findRelatedAsync( + query, + resultSpec, + ctx); + + NoteStoreFindRelatedAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreFindRelatedAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreFindRelatedAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteUpdateNoteIfUsnMatches() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + UpdateNoteIfUsnMatchesResult response = generateRandomUpdateNoteIfUsnMatchesResult(); + + NoteStoreUpdateNoteIfUsnMatchesTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> UpdateNoteIfUsnMatchesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequest, + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::onUpdateNoteIfUsnMatchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::updateNoteIfUsnMatchesRequestReady, + &server, + &NoteStoreServer::onUpdateNoteIfUsnMatchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + UpdateNoteIfUsnMatchesResult res = noteStore->updateNoteIfUsnMatches( + note, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateNoteIfUsnMatches() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_AUTH; + userException.parameter = generateRandomString(); + + NoteStoreUpdateNoteIfUsnMatchesTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> UpdateNoteIfUsnMatchesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequest, + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::onUpdateNoteIfUsnMatchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::updateNoteIfUsnMatchesRequestReady, + &server, + &NoteStoreServer::onUpdateNoteIfUsnMatchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + UpdateNoteIfUsnMatchesResult res = noteStore->updateNoteIfUsnMatches( + note, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateNoteIfUsnMatches() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateNoteIfUsnMatchesTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> UpdateNoteIfUsnMatchesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequest, + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::onUpdateNoteIfUsnMatchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::updateNoteIfUsnMatchesRequestReady, + &server, + &NoteStoreServer::onUpdateNoteIfUsnMatchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + UpdateNoteIfUsnMatchesResult res = noteStore->updateNoteIfUsnMatches( + note, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateNoteIfUsnMatches() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::SHARD_UNAVAILABLE; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateNoteIfUsnMatchesTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> UpdateNoteIfUsnMatchesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequest, + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::onUpdateNoteIfUsnMatchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::updateNoteIfUsnMatchesRequestReady, + &server, + &NoteStoreServer::onUpdateNoteIfUsnMatchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + UpdateNoteIfUsnMatchesResult res = noteStore->updateNoteIfUsnMatches( + note, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateNoteIfUsnMatches() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateNoteIfUsnMatchesTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> UpdateNoteIfUsnMatchesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequest, + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::onUpdateNoteIfUsnMatchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::updateNoteIfUsnMatchesRequestReady, + &server, + &NoteStoreServer::onUpdateNoteIfUsnMatchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + UpdateNoteIfUsnMatchesResult res = noteStore->updateNoteIfUsnMatches( + note, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteUpdateNoteIfUsnMatchesAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + UpdateNoteIfUsnMatchesResult response = generateRandomUpdateNoteIfUsnMatchesResult(); + + NoteStoreUpdateNoteIfUsnMatchesTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> UpdateNoteIfUsnMatchesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequest, + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::onUpdateNoteIfUsnMatchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::updateNoteIfUsnMatchesRequestReady, + &server, + &NoteStoreServer::onUpdateNoteIfUsnMatchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->updateNoteIfUsnMatchesAsync( + note, + ctx); + + NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInUpdateNoteIfUsnMatchesAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED; + userException.parameter = generateRandomString(); + + NoteStoreUpdateNoteIfUsnMatchesTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> UpdateNoteIfUsnMatchesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequest, + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::onUpdateNoteIfUsnMatchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::updateNoteIfUsnMatchesRequestReady, + &server, + &NoteStoreServer::onUpdateNoteIfUsnMatchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateNoteIfUsnMatchesAsync( + note, + ctx); + + NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateNoteIfUsnMatchesAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreUpdateNoteIfUsnMatchesTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> UpdateNoteIfUsnMatchesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequest, + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::onUpdateNoteIfUsnMatchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::updateNoteIfUsnMatchesRequestReady, + &server, + &NoteStoreServer::onUpdateNoteIfUsnMatchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateNoteIfUsnMatchesAsync( + note, + ctx); + + NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInUpdateNoteIfUsnMatchesAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LEN_TOO_LONG; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreUpdateNoteIfUsnMatchesTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> UpdateNoteIfUsnMatchesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequest, + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::onUpdateNoteIfUsnMatchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::updateNoteIfUsnMatchesRequestReady, + &server, + &NoteStoreServer::onUpdateNoteIfUsnMatchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateNoteIfUsnMatchesAsync( + note, + ctx); + + NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInUpdateNoteIfUsnMatchesAsync() +{ + Note note = generateRandomNote(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreUpdateNoteIfUsnMatchesTesterHelper helper( + [&] (const Note & noteParam, + IRequestContextPtr ctxParam) -> UpdateNoteIfUsnMatchesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(note == noteParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequest, + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::onUpdateNoteIfUsnMatchesRequestReceived); + QObject::connect( + &helper, + &NoteStoreUpdateNoteIfUsnMatchesTesterHelper::updateNoteIfUsnMatchesRequestReady, + &server, + &NoteStoreServer::onUpdateNoteIfUsnMatchesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::updateNoteIfUsnMatchesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->updateNoteIfUsnMatchesAsync( + note, + ctx); + + NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreUpdateNoteIfUsnMatchesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteManageNotebookShares() +{ + ManageNotebookSharesParameters parameters = generateRandomManageNotebookSharesParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + ManageNotebookSharesResult response = generateRandomManageNotebookSharesResult(); + + NoteStoreManageNotebookSharesTesterHelper helper( + [&] (const ManageNotebookSharesParameters & parametersParam, + IRequestContextPtr ctxParam) -> ManageNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequest, + &helper, + &NoteStoreManageNotebookSharesTesterHelper::onManageNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreManageNotebookSharesTesterHelper::manageNotebookSharesRequestReady, + &server, + &NoteStoreServer::onManageNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + ManageNotebookSharesResult res = noteStore->manageNotebookShares( + parameters, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInManageNotebookShares() +{ + ManageNotebookSharesParameters parameters = generateRandomManageNotebookSharesParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_AUTH; + userException.parameter = generateRandomString(); + + NoteStoreManageNotebookSharesTesterHelper helper( + [&] (const ManageNotebookSharesParameters & parametersParam, + IRequestContextPtr ctxParam) -> ManageNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequest, + &helper, + &NoteStoreManageNotebookSharesTesterHelper::onManageNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreManageNotebookSharesTesterHelper::manageNotebookSharesRequestReady, + &server, + &NoteStoreServer::onManageNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + ManageNotebookSharesResult res = noteStore->manageNotebookShares( + parameters, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInManageNotebookShares() +{ + ManageNotebookSharesParameters parameters = generateRandomManageNotebookSharesParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreManageNotebookSharesTesterHelper helper( + [&] (const ManageNotebookSharesParameters & parametersParam, + IRequestContextPtr ctxParam) -> ManageNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequest, + &helper, + &NoteStoreManageNotebookSharesTesterHelper::onManageNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreManageNotebookSharesTesterHelper::manageNotebookSharesRequestReady, + &server, + &NoteStoreServer::onManageNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + ManageNotebookSharesResult res = noteStore->manageNotebookShares( + parameters, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInManageNotebookShares() +{ + ManageNotebookSharesParameters parameters = generateRandomManageNotebookSharesParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::ENML_VALIDATION; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreManageNotebookSharesTesterHelper helper( + [&] (const ManageNotebookSharesParameters & parametersParam, + IRequestContextPtr ctxParam) -> ManageNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequest, + &helper, + &NoteStoreManageNotebookSharesTesterHelper::onManageNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreManageNotebookSharesTesterHelper::manageNotebookSharesRequestReady, + &server, + &NoteStoreServer::onManageNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + ManageNotebookSharesResult res = noteStore->manageNotebookShares( + parameters, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInManageNotebookShares() +{ + ManageNotebookSharesParameters parameters = generateRandomManageNotebookSharesParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreManageNotebookSharesTesterHelper helper( + [&] (const ManageNotebookSharesParameters & parametersParam, + IRequestContextPtr ctxParam) -> ManageNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequest, + &helper, + &NoteStoreManageNotebookSharesTesterHelper::onManageNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreManageNotebookSharesTesterHelper::manageNotebookSharesRequestReady, + &server, + &NoteStoreServer::onManageNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + ManageNotebookSharesResult res = noteStore->manageNotebookShares( + parameters, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteManageNotebookSharesAsync() +{ + ManageNotebookSharesParameters parameters = generateRandomManageNotebookSharesParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + ManageNotebookSharesResult response = generateRandomManageNotebookSharesResult(); + + NoteStoreManageNotebookSharesTesterHelper helper( + [&] (const ManageNotebookSharesParameters & parametersParam, + IRequestContextPtr ctxParam) -> ManageNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequest, + &helper, + &NoteStoreManageNotebookSharesTesterHelper::onManageNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreManageNotebookSharesTesterHelper::manageNotebookSharesRequestReady, + &server, + &NoteStoreServer::onManageNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->manageNotebookSharesAsync( + parameters, + ctx); + + NoteStoreManageNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreManageNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreManageNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInManageNotebookSharesAsync() +{ + ManageNotebookSharesParameters parameters = generateRandomManageNotebookSharesParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_NOT_ASSOCIATED; + userException.parameter = generateRandomString(); + + NoteStoreManageNotebookSharesTesterHelper helper( + [&] (const ManageNotebookSharesParameters & parametersParam, + IRequestContextPtr ctxParam) -> ManageNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequest, + &helper, + &NoteStoreManageNotebookSharesTesterHelper::onManageNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreManageNotebookSharesTesterHelper::manageNotebookSharesRequestReady, + &server, + &NoteStoreServer::onManageNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->manageNotebookSharesAsync( + parameters, + ctx); + + NoteStoreManageNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreManageNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreManageNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInManageNotebookSharesAsync() +{ + ManageNotebookSharesParameters parameters = generateRandomManageNotebookSharesParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreManageNotebookSharesTesterHelper helper( + [&] (const ManageNotebookSharesParameters & parametersParam, + IRequestContextPtr ctxParam) -> ManageNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequest, + &helper, + &NoteStoreManageNotebookSharesTesterHelper::onManageNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreManageNotebookSharesTesterHelper::manageNotebookSharesRequestReady, + &server, + &NoteStoreServer::onManageNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->manageNotebookSharesAsync( + parameters, + ctx); + + NoteStoreManageNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreManageNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreManageNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInManageNotebookSharesAsync() +{ + ManageNotebookSharesParameters parameters = generateRandomManageNotebookSharesParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreManageNotebookSharesTesterHelper helper( + [&] (const ManageNotebookSharesParameters & parametersParam, + IRequestContextPtr ctxParam) -> ManageNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequest, + &helper, + &NoteStoreManageNotebookSharesTesterHelper::onManageNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreManageNotebookSharesTesterHelper::manageNotebookSharesRequestReady, + &server, + &NoteStoreServer::onManageNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->manageNotebookSharesAsync( + parameters, + ctx); + + NoteStoreManageNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreManageNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreManageNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInManageNotebookSharesAsync() +{ + ManageNotebookSharesParameters parameters = generateRandomManageNotebookSharesParameters(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreManageNotebookSharesTesterHelper helper( + [&] (const ManageNotebookSharesParameters & parametersParam, + IRequestContextPtr ctxParam) -> ManageNotebookSharesResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(parameters == parametersParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequest, + &helper, + &NoteStoreManageNotebookSharesTesterHelper::onManageNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreManageNotebookSharesTesterHelper::manageNotebookSharesRequestReady, + &server, + &NoteStoreServer::onManageNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::manageNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->manageNotebookSharesAsync( + parameters, + ctx); + + NoteStoreManageNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreManageNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreManageNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void NoteStoreTester::shouldExecuteGetNotebookShares() +{ + QString notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + ShareRelationships response = generateRandomShareRelationships(); + + NoteStoreGetNotebookSharesTesterHelper helper( + [&] (const QString & notebookGuidParam, + IRequestContextPtr ctxParam) -> ShareRelationships + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequest, + &helper, + &NoteStoreGetNotebookSharesTesterHelper::onGetNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookSharesTesterHelper::getNotebookSharesRequestReady, + &server, + &NoteStoreServer::onGetNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + ShareRelationships res = noteStore->getNotebookShares( + notebookGuid, + ctx); + QVERIFY(res == response); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNotebookShares() +{ + QString notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreGetNotebookSharesTesterHelper helper( + [&] (const QString & notebookGuidParam, + IRequestContextPtr ctxParam) -> ShareRelationships + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequest, + &helper, + &NoteStoreGetNotebookSharesTesterHelper::onGetNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookSharesTesterHelper::getNotebookSharesRequestReady, + &server, + &NoteStoreServer::onGetNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + ShareRelationships res = noteStore->getNotebookShares( + notebookGuid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNotebookShares() +{ + QString notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNotebookSharesTesterHelper helper( + [&] (const QString & notebookGuidParam, + IRequestContextPtr ctxParam) -> ShareRelationships + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequest, + &helper, + &NoteStoreGetNotebookSharesTesterHelper::onGetNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookSharesTesterHelper::getNotebookSharesRequestReady, + &server, + &NoteStoreServer::onGetNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + ShareRelationships res = noteStore->getNotebookShares( + notebookGuid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNotebookShares() +{ + QString notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNotebookSharesTesterHelper helper( + [&] (const QString & notebookGuidParam, + IRequestContextPtr ctxParam) -> ShareRelationships + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequest, + &helper, + &NoteStoreGetNotebookSharesTesterHelper::onGetNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookSharesTesterHelper::getNotebookSharesRequestReady, + &server, + &NoteStoreServer::onGetNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + ShareRelationships res = noteStore->getNotebookShares( + notebookGuid, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNotebookShares() +{ + QString notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNotebookSharesTesterHelper helper( + [&] (const QString & notebookGuidParam, + IRequestContextPtr ctxParam) -> ShareRelationships + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequest, + &helper, + &NoteStoreGetNotebookSharesTesterHelper::onGetNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookSharesTesterHelper::getNotebookSharesRequestReady, + &server, + &NoteStoreServer::onGetNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + ShareRelationships res = noteStore->getNotebookShares( + notebookGuid, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldExecuteGetNotebookSharesAsync() +{ + QString notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + ShareRelationships response = generateRandomShareRelationships(); + + NoteStoreGetNotebookSharesTesterHelper helper( + [&] (const QString & notebookGuidParam, + IRequestContextPtr ctxParam) -> ShareRelationships + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + return response; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequest, + &helper, + &NoteStoreGetNotebookSharesTesterHelper::onGetNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookSharesTesterHelper::getNotebookSharesRequestReady, + &server, + &NoteStoreServer::onGetNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = noteStore->getNotebookSharesAsync( + notebookGuid, + ctx); + + NoteStoreGetNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void NoteStoreTester::shouldDeliverEDAMUserExceptionInGetNotebookSharesAsync() +{ + QString notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + userException.parameter = generateRandomString(); + + NoteStoreGetNotebookSharesTesterHelper helper( + [&] (const QString & notebookGuidParam, + IRequestContextPtr ctxParam) -> ShareRelationships + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw userException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequest, + &helper, + &NoteStoreGetNotebookSharesTesterHelper::onGetNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookSharesTesterHelper::getNotebookSharesRequestReady, + &server, + &NoteStoreServer::onGetNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNotebookSharesAsync( + notebookGuid, + ctx); + + NoteStoreGetNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMNotFoundExceptionInGetNotebookSharesAsync() +{ + QString notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + NoteStoreGetNotebookSharesTesterHelper helper( + [&] (const QString & notebookGuidParam, + IRequestContextPtr ctxParam) -> ShareRelationships + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw notFoundException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequest, + &helper, + &NoteStoreGetNotebookSharesTesterHelper::onGetNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookSharesTesterHelper::getNotebookSharesRequestReady, + &server, + &NoteStoreServer::onGetNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNotebookSharesAsync( + notebookGuid, + ctx); + + NoteStoreGetNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverEDAMSystemExceptionInGetNotebookSharesAsync() +{ + QString notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + NoteStoreGetNotebookSharesTesterHelper helper( + [&] (const QString & notebookGuidParam, + IRequestContextPtr ctxParam) -> ShareRelationships + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw systemException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequest, + &helper, + &NoteStoreGetNotebookSharesTesterHelper::onGetNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookSharesTesterHelper::getNotebookSharesRequestReady, + &server, + &NoteStoreServer::onGetNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNotebookSharesAsync( + notebookGuid, + ctx); + + NoteStoreGetNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void NoteStoreTester::shouldDeliverThriftExceptionInGetNotebookSharesAsync() +{ + QString notebookGuid = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + NoteStoreGetNotebookSharesTesterHelper helper( + [&] (const QString & notebookGuidParam, + IRequestContextPtr ctxParam) -> ShareRelationships + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(notebookGuid == notebookGuidParam); + throw thriftException; + }); + + NoteStoreServer server; + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequest, + &helper, + &NoteStoreGetNotebookSharesTesterHelper::onGetNotebookSharesRequestReceived); + QObject::connect( + &helper, + &NoteStoreGetNotebookSharesTesterHelper::getNotebookSharesRequestReady, + &server, + &NoteStoreServer::onGetNotebookSharesRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &NoteStoreServer::getNotebookSharesRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr noteStore( + newNoteStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = noteStore->getNotebookSharesAsync( + notebookGuid, + ctx); + + NoteStoreGetNotebookSharesAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &NoteStoreGetNotebookSharesAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &NoteStoreGetNotebookSharesAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +} // namespace qevercloud + +#include diff --git a/src/qevercloud/QEverCloud/src/tests/generated/TestNoteStore.h b/src/qevercloud/QEverCloud/src/tests/generated/TestNoteStore.h new file mode 100644 index 00000000..7d0416bd --- /dev/null +++ b/src/qevercloud/QEverCloud/src/tests/generated/TestNoteStore.h @@ -0,0 +1,756 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + * + * This file was generated from Evernote Thrift API + */ + +#ifndef QEVERCLOUD_GENERATED_TESTNOTESTORE_H +#define QEVERCLOUD_GENERATED_TESTNOTESTORE_H + +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +class NoteStoreTester: public QObject +{ + Q_OBJECT +public: + explicit NoteStoreTester(QObject * parent = nullptr); + +private Q_SLOTS: + void shouldExecuteGetSyncState(); + void shouldDeliverEDAMUserExceptionInGetSyncState(); + void shouldDeliverEDAMSystemExceptionInGetSyncState(); + void shouldDeliverThriftExceptionInGetSyncState(); + void shouldExecuteGetSyncStateAsync(); + void shouldDeliverEDAMUserExceptionInGetSyncStateAsync(); + void shouldDeliverEDAMSystemExceptionInGetSyncStateAsync(); + void shouldDeliverThriftExceptionInGetSyncStateAsync(); + void shouldExecuteGetFilteredSyncChunk(); + void shouldDeliverEDAMUserExceptionInGetFilteredSyncChunk(); + void shouldDeliverEDAMSystemExceptionInGetFilteredSyncChunk(); + void shouldDeliverThriftExceptionInGetFilteredSyncChunk(); + void shouldExecuteGetFilteredSyncChunkAsync(); + void shouldDeliverEDAMUserExceptionInGetFilteredSyncChunkAsync(); + void shouldDeliverEDAMSystemExceptionInGetFilteredSyncChunkAsync(); + void shouldDeliverThriftExceptionInGetFilteredSyncChunkAsync(); + void shouldExecuteGetLinkedNotebookSyncState(); + void shouldDeliverEDAMUserExceptionInGetLinkedNotebookSyncState(); + void shouldDeliverEDAMSystemExceptionInGetLinkedNotebookSyncState(); + void shouldDeliverEDAMNotFoundExceptionInGetLinkedNotebookSyncState(); + void shouldDeliverThriftExceptionInGetLinkedNotebookSyncState(); + void shouldExecuteGetLinkedNotebookSyncStateAsync(); + void shouldDeliverEDAMUserExceptionInGetLinkedNotebookSyncStateAsync(); + void shouldDeliverEDAMSystemExceptionInGetLinkedNotebookSyncStateAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetLinkedNotebookSyncStateAsync(); + void shouldDeliverThriftExceptionInGetLinkedNotebookSyncStateAsync(); + void shouldExecuteGetLinkedNotebookSyncChunk(); + void shouldDeliverEDAMUserExceptionInGetLinkedNotebookSyncChunk(); + void shouldDeliverEDAMSystemExceptionInGetLinkedNotebookSyncChunk(); + void shouldDeliverEDAMNotFoundExceptionInGetLinkedNotebookSyncChunk(); + void shouldDeliverThriftExceptionInGetLinkedNotebookSyncChunk(); + void shouldExecuteGetLinkedNotebookSyncChunkAsync(); + void shouldDeliverEDAMUserExceptionInGetLinkedNotebookSyncChunkAsync(); + void shouldDeliverEDAMSystemExceptionInGetLinkedNotebookSyncChunkAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetLinkedNotebookSyncChunkAsync(); + void shouldDeliverThriftExceptionInGetLinkedNotebookSyncChunkAsync(); + void shouldExecuteListNotebooks(); + void shouldDeliverEDAMUserExceptionInListNotebooks(); + void shouldDeliverEDAMSystemExceptionInListNotebooks(); + void shouldDeliverThriftExceptionInListNotebooks(); + void shouldExecuteListNotebooksAsync(); + void shouldDeliverEDAMUserExceptionInListNotebooksAsync(); + void shouldDeliverEDAMSystemExceptionInListNotebooksAsync(); + void shouldDeliverThriftExceptionInListNotebooksAsync(); + void shouldExecuteListAccessibleBusinessNotebooks(); + void shouldDeliverEDAMUserExceptionInListAccessibleBusinessNotebooks(); + void shouldDeliverEDAMSystemExceptionInListAccessibleBusinessNotebooks(); + void shouldDeliverThriftExceptionInListAccessibleBusinessNotebooks(); + void shouldExecuteListAccessibleBusinessNotebooksAsync(); + void shouldDeliverEDAMUserExceptionInListAccessibleBusinessNotebooksAsync(); + void shouldDeliverEDAMSystemExceptionInListAccessibleBusinessNotebooksAsync(); + void shouldDeliverThriftExceptionInListAccessibleBusinessNotebooksAsync(); + void shouldExecuteGetNotebook(); + void shouldDeliverEDAMUserExceptionInGetNotebook(); + void shouldDeliverEDAMSystemExceptionInGetNotebook(); + void shouldDeliverEDAMNotFoundExceptionInGetNotebook(); + void shouldDeliverThriftExceptionInGetNotebook(); + void shouldExecuteGetNotebookAsync(); + void shouldDeliverEDAMUserExceptionInGetNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInGetNotebookAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetNotebookAsync(); + void shouldDeliverThriftExceptionInGetNotebookAsync(); + void shouldExecuteGetDefaultNotebook(); + void shouldDeliverEDAMUserExceptionInGetDefaultNotebook(); + void shouldDeliverEDAMSystemExceptionInGetDefaultNotebook(); + void shouldDeliverThriftExceptionInGetDefaultNotebook(); + void shouldExecuteGetDefaultNotebookAsync(); + void shouldDeliverEDAMUserExceptionInGetDefaultNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInGetDefaultNotebookAsync(); + void shouldDeliverThriftExceptionInGetDefaultNotebookAsync(); + void shouldExecuteCreateNotebook(); + void shouldDeliverEDAMUserExceptionInCreateNotebook(); + void shouldDeliverEDAMSystemExceptionInCreateNotebook(); + void shouldDeliverEDAMNotFoundExceptionInCreateNotebook(); + void shouldDeliverThriftExceptionInCreateNotebook(); + void shouldExecuteCreateNotebookAsync(); + void shouldDeliverEDAMUserExceptionInCreateNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInCreateNotebookAsync(); + void shouldDeliverEDAMNotFoundExceptionInCreateNotebookAsync(); + void shouldDeliverThriftExceptionInCreateNotebookAsync(); + void shouldExecuteUpdateNotebook(); + void shouldDeliverEDAMUserExceptionInUpdateNotebook(); + void shouldDeliverEDAMSystemExceptionInUpdateNotebook(); + void shouldDeliverEDAMNotFoundExceptionInUpdateNotebook(); + void shouldDeliverThriftExceptionInUpdateNotebook(); + void shouldExecuteUpdateNotebookAsync(); + void shouldDeliverEDAMUserExceptionInUpdateNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInUpdateNotebookAsync(); + void shouldDeliverEDAMNotFoundExceptionInUpdateNotebookAsync(); + void shouldDeliverThriftExceptionInUpdateNotebookAsync(); + void shouldExecuteExpungeNotebook(); + void shouldDeliverEDAMUserExceptionInExpungeNotebook(); + void shouldDeliverEDAMSystemExceptionInExpungeNotebook(); + void shouldDeliverEDAMNotFoundExceptionInExpungeNotebook(); + void shouldDeliverThriftExceptionInExpungeNotebook(); + void shouldExecuteExpungeNotebookAsync(); + void shouldDeliverEDAMUserExceptionInExpungeNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInExpungeNotebookAsync(); + void shouldDeliverEDAMNotFoundExceptionInExpungeNotebookAsync(); + void shouldDeliverThriftExceptionInExpungeNotebookAsync(); + void shouldExecuteListTags(); + void shouldDeliverEDAMUserExceptionInListTags(); + void shouldDeliverEDAMSystemExceptionInListTags(); + void shouldDeliverThriftExceptionInListTags(); + void shouldExecuteListTagsAsync(); + void shouldDeliverEDAMUserExceptionInListTagsAsync(); + void shouldDeliverEDAMSystemExceptionInListTagsAsync(); + void shouldDeliverThriftExceptionInListTagsAsync(); + void shouldExecuteListTagsByNotebook(); + void shouldDeliverEDAMUserExceptionInListTagsByNotebook(); + void shouldDeliverEDAMSystemExceptionInListTagsByNotebook(); + void shouldDeliverEDAMNotFoundExceptionInListTagsByNotebook(); + void shouldDeliverThriftExceptionInListTagsByNotebook(); + void shouldExecuteListTagsByNotebookAsync(); + void shouldDeliverEDAMUserExceptionInListTagsByNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInListTagsByNotebookAsync(); + void shouldDeliverEDAMNotFoundExceptionInListTagsByNotebookAsync(); + void shouldDeliverThriftExceptionInListTagsByNotebookAsync(); + void shouldExecuteGetTag(); + void shouldDeliverEDAMUserExceptionInGetTag(); + void shouldDeliverEDAMSystemExceptionInGetTag(); + void shouldDeliverEDAMNotFoundExceptionInGetTag(); + void shouldDeliverThriftExceptionInGetTag(); + void shouldExecuteGetTagAsync(); + void shouldDeliverEDAMUserExceptionInGetTagAsync(); + void shouldDeliverEDAMSystemExceptionInGetTagAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetTagAsync(); + void shouldDeliverThriftExceptionInGetTagAsync(); + void shouldExecuteCreateTag(); + void shouldDeliverEDAMUserExceptionInCreateTag(); + void shouldDeliverEDAMSystemExceptionInCreateTag(); + void shouldDeliverEDAMNotFoundExceptionInCreateTag(); + void shouldDeliverThriftExceptionInCreateTag(); + void shouldExecuteCreateTagAsync(); + void shouldDeliverEDAMUserExceptionInCreateTagAsync(); + void shouldDeliverEDAMSystemExceptionInCreateTagAsync(); + void shouldDeliverEDAMNotFoundExceptionInCreateTagAsync(); + void shouldDeliverThriftExceptionInCreateTagAsync(); + void shouldExecuteUpdateTag(); + void shouldDeliverEDAMUserExceptionInUpdateTag(); + void shouldDeliverEDAMSystemExceptionInUpdateTag(); + void shouldDeliverEDAMNotFoundExceptionInUpdateTag(); + void shouldDeliverThriftExceptionInUpdateTag(); + void shouldExecuteUpdateTagAsync(); + void shouldDeliverEDAMUserExceptionInUpdateTagAsync(); + void shouldDeliverEDAMSystemExceptionInUpdateTagAsync(); + void shouldDeliverEDAMNotFoundExceptionInUpdateTagAsync(); + void shouldDeliverThriftExceptionInUpdateTagAsync(); + void shouldExecuteUntagAll(); + void shouldDeliverEDAMUserExceptionInUntagAll(); + void shouldDeliverEDAMSystemExceptionInUntagAll(); + void shouldDeliverEDAMNotFoundExceptionInUntagAll(); + void shouldDeliverThriftExceptionInUntagAll(); + void shouldExecuteUntagAllAsync(); + void shouldDeliverEDAMUserExceptionInUntagAllAsync(); + void shouldDeliverEDAMSystemExceptionInUntagAllAsync(); + void shouldDeliverEDAMNotFoundExceptionInUntagAllAsync(); + void shouldDeliverThriftExceptionInUntagAllAsync(); + void shouldExecuteExpungeTag(); + void shouldDeliverEDAMUserExceptionInExpungeTag(); + void shouldDeliverEDAMSystemExceptionInExpungeTag(); + void shouldDeliverEDAMNotFoundExceptionInExpungeTag(); + void shouldDeliverThriftExceptionInExpungeTag(); + void shouldExecuteExpungeTagAsync(); + void shouldDeliverEDAMUserExceptionInExpungeTagAsync(); + void shouldDeliverEDAMSystemExceptionInExpungeTagAsync(); + void shouldDeliverEDAMNotFoundExceptionInExpungeTagAsync(); + void shouldDeliverThriftExceptionInExpungeTagAsync(); + void shouldExecuteListSearches(); + void shouldDeliverEDAMUserExceptionInListSearches(); + void shouldDeliverEDAMSystemExceptionInListSearches(); + void shouldDeliverThriftExceptionInListSearches(); + void shouldExecuteListSearchesAsync(); + void shouldDeliverEDAMUserExceptionInListSearchesAsync(); + void shouldDeliverEDAMSystemExceptionInListSearchesAsync(); + void shouldDeliverThriftExceptionInListSearchesAsync(); + void shouldExecuteGetSearch(); + void shouldDeliverEDAMUserExceptionInGetSearch(); + void shouldDeliverEDAMSystemExceptionInGetSearch(); + void shouldDeliverEDAMNotFoundExceptionInGetSearch(); + void shouldDeliverThriftExceptionInGetSearch(); + void shouldExecuteGetSearchAsync(); + void shouldDeliverEDAMUserExceptionInGetSearchAsync(); + void shouldDeliverEDAMSystemExceptionInGetSearchAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetSearchAsync(); + void shouldDeliverThriftExceptionInGetSearchAsync(); + void shouldExecuteCreateSearch(); + void shouldDeliverEDAMUserExceptionInCreateSearch(); + void shouldDeliverEDAMSystemExceptionInCreateSearch(); + void shouldDeliverThriftExceptionInCreateSearch(); + void shouldExecuteCreateSearchAsync(); + void shouldDeliverEDAMUserExceptionInCreateSearchAsync(); + void shouldDeliverEDAMSystemExceptionInCreateSearchAsync(); + void shouldDeliverThriftExceptionInCreateSearchAsync(); + void shouldExecuteUpdateSearch(); + void shouldDeliverEDAMUserExceptionInUpdateSearch(); + void shouldDeliverEDAMSystemExceptionInUpdateSearch(); + void shouldDeliverEDAMNotFoundExceptionInUpdateSearch(); + void shouldDeliverThriftExceptionInUpdateSearch(); + void shouldExecuteUpdateSearchAsync(); + void shouldDeliverEDAMUserExceptionInUpdateSearchAsync(); + void shouldDeliverEDAMSystemExceptionInUpdateSearchAsync(); + void shouldDeliverEDAMNotFoundExceptionInUpdateSearchAsync(); + void shouldDeliverThriftExceptionInUpdateSearchAsync(); + void shouldExecuteExpungeSearch(); + void shouldDeliverEDAMUserExceptionInExpungeSearch(); + void shouldDeliverEDAMSystemExceptionInExpungeSearch(); + void shouldDeliverEDAMNotFoundExceptionInExpungeSearch(); + void shouldDeliverThriftExceptionInExpungeSearch(); + void shouldExecuteExpungeSearchAsync(); + void shouldDeliverEDAMUserExceptionInExpungeSearchAsync(); + void shouldDeliverEDAMSystemExceptionInExpungeSearchAsync(); + void shouldDeliverEDAMNotFoundExceptionInExpungeSearchAsync(); + void shouldDeliverThriftExceptionInExpungeSearchAsync(); + void shouldExecuteFindNoteOffset(); + void shouldDeliverEDAMUserExceptionInFindNoteOffset(); + void shouldDeliverEDAMSystemExceptionInFindNoteOffset(); + void shouldDeliverEDAMNotFoundExceptionInFindNoteOffset(); + void shouldDeliverThriftExceptionInFindNoteOffset(); + void shouldExecuteFindNoteOffsetAsync(); + void shouldDeliverEDAMUserExceptionInFindNoteOffsetAsync(); + void shouldDeliverEDAMSystemExceptionInFindNoteOffsetAsync(); + void shouldDeliverEDAMNotFoundExceptionInFindNoteOffsetAsync(); + void shouldDeliverThriftExceptionInFindNoteOffsetAsync(); + void shouldExecuteFindNotesMetadata(); + void shouldDeliverEDAMUserExceptionInFindNotesMetadata(); + void shouldDeliverEDAMSystemExceptionInFindNotesMetadata(); + void shouldDeliverEDAMNotFoundExceptionInFindNotesMetadata(); + void shouldDeliverThriftExceptionInFindNotesMetadata(); + void shouldExecuteFindNotesMetadataAsync(); + void shouldDeliverEDAMUserExceptionInFindNotesMetadataAsync(); + void shouldDeliverEDAMSystemExceptionInFindNotesMetadataAsync(); + void shouldDeliverEDAMNotFoundExceptionInFindNotesMetadataAsync(); + void shouldDeliverThriftExceptionInFindNotesMetadataAsync(); + void shouldExecuteFindNoteCounts(); + void shouldDeliverEDAMUserExceptionInFindNoteCounts(); + void shouldDeliverEDAMSystemExceptionInFindNoteCounts(); + void shouldDeliverEDAMNotFoundExceptionInFindNoteCounts(); + void shouldDeliverThriftExceptionInFindNoteCounts(); + void shouldExecuteFindNoteCountsAsync(); + void shouldDeliverEDAMUserExceptionInFindNoteCountsAsync(); + void shouldDeliverEDAMSystemExceptionInFindNoteCountsAsync(); + void shouldDeliverEDAMNotFoundExceptionInFindNoteCountsAsync(); + void shouldDeliverThriftExceptionInFindNoteCountsAsync(); + void shouldExecuteGetNoteWithResultSpec(); + void shouldDeliverEDAMUserExceptionInGetNoteWithResultSpec(); + void shouldDeliverEDAMSystemExceptionInGetNoteWithResultSpec(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteWithResultSpec(); + void shouldDeliverThriftExceptionInGetNoteWithResultSpec(); + void shouldExecuteGetNoteWithResultSpecAsync(); + void shouldDeliverEDAMUserExceptionInGetNoteWithResultSpecAsync(); + void shouldDeliverEDAMSystemExceptionInGetNoteWithResultSpecAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteWithResultSpecAsync(); + void shouldDeliverThriftExceptionInGetNoteWithResultSpecAsync(); + void shouldExecuteGetNote(); + void shouldDeliverEDAMUserExceptionInGetNote(); + void shouldDeliverEDAMSystemExceptionInGetNote(); + void shouldDeliverEDAMNotFoundExceptionInGetNote(); + void shouldDeliverThriftExceptionInGetNote(); + void shouldExecuteGetNoteAsync(); + void shouldDeliverEDAMUserExceptionInGetNoteAsync(); + void shouldDeliverEDAMSystemExceptionInGetNoteAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteAsync(); + void shouldDeliverThriftExceptionInGetNoteAsync(); + void shouldExecuteGetNoteApplicationData(); + void shouldDeliverEDAMUserExceptionInGetNoteApplicationData(); + void shouldDeliverEDAMSystemExceptionInGetNoteApplicationData(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteApplicationData(); + void shouldDeliverThriftExceptionInGetNoteApplicationData(); + void shouldExecuteGetNoteApplicationDataAsync(); + void shouldDeliverEDAMUserExceptionInGetNoteApplicationDataAsync(); + void shouldDeliverEDAMSystemExceptionInGetNoteApplicationDataAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteApplicationDataAsync(); + void shouldDeliverThriftExceptionInGetNoteApplicationDataAsync(); + void shouldExecuteGetNoteApplicationDataEntry(); + void shouldDeliverEDAMUserExceptionInGetNoteApplicationDataEntry(); + void shouldDeliverEDAMSystemExceptionInGetNoteApplicationDataEntry(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteApplicationDataEntry(); + void shouldDeliverThriftExceptionInGetNoteApplicationDataEntry(); + void shouldExecuteGetNoteApplicationDataEntryAsync(); + void shouldDeliverEDAMUserExceptionInGetNoteApplicationDataEntryAsync(); + void shouldDeliverEDAMSystemExceptionInGetNoteApplicationDataEntryAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteApplicationDataEntryAsync(); + void shouldDeliverThriftExceptionInGetNoteApplicationDataEntryAsync(); + void shouldExecuteSetNoteApplicationDataEntry(); + void shouldDeliverEDAMUserExceptionInSetNoteApplicationDataEntry(); + void shouldDeliverEDAMSystemExceptionInSetNoteApplicationDataEntry(); + void shouldDeliverEDAMNotFoundExceptionInSetNoteApplicationDataEntry(); + void shouldDeliverThriftExceptionInSetNoteApplicationDataEntry(); + void shouldExecuteSetNoteApplicationDataEntryAsync(); + void shouldDeliverEDAMUserExceptionInSetNoteApplicationDataEntryAsync(); + void shouldDeliverEDAMSystemExceptionInSetNoteApplicationDataEntryAsync(); + void shouldDeliverEDAMNotFoundExceptionInSetNoteApplicationDataEntryAsync(); + void shouldDeliverThriftExceptionInSetNoteApplicationDataEntryAsync(); + void shouldExecuteUnsetNoteApplicationDataEntry(); + void shouldDeliverEDAMUserExceptionInUnsetNoteApplicationDataEntry(); + void shouldDeliverEDAMSystemExceptionInUnsetNoteApplicationDataEntry(); + void shouldDeliverEDAMNotFoundExceptionInUnsetNoteApplicationDataEntry(); + void shouldDeliverThriftExceptionInUnsetNoteApplicationDataEntry(); + void shouldExecuteUnsetNoteApplicationDataEntryAsync(); + void shouldDeliverEDAMUserExceptionInUnsetNoteApplicationDataEntryAsync(); + void shouldDeliverEDAMSystemExceptionInUnsetNoteApplicationDataEntryAsync(); + void shouldDeliverEDAMNotFoundExceptionInUnsetNoteApplicationDataEntryAsync(); + void shouldDeliverThriftExceptionInUnsetNoteApplicationDataEntryAsync(); + void shouldExecuteGetNoteContent(); + void shouldDeliverEDAMUserExceptionInGetNoteContent(); + void shouldDeliverEDAMSystemExceptionInGetNoteContent(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteContent(); + void shouldDeliverThriftExceptionInGetNoteContent(); + void shouldExecuteGetNoteContentAsync(); + void shouldDeliverEDAMUserExceptionInGetNoteContentAsync(); + void shouldDeliverEDAMSystemExceptionInGetNoteContentAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteContentAsync(); + void shouldDeliverThriftExceptionInGetNoteContentAsync(); + void shouldExecuteGetNoteSearchText(); + void shouldDeliverEDAMUserExceptionInGetNoteSearchText(); + void shouldDeliverEDAMSystemExceptionInGetNoteSearchText(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteSearchText(); + void shouldDeliverThriftExceptionInGetNoteSearchText(); + void shouldExecuteGetNoteSearchTextAsync(); + void shouldDeliverEDAMUserExceptionInGetNoteSearchTextAsync(); + void shouldDeliverEDAMSystemExceptionInGetNoteSearchTextAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteSearchTextAsync(); + void shouldDeliverThriftExceptionInGetNoteSearchTextAsync(); + void shouldExecuteGetResourceSearchText(); + void shouldDeliverEDAMUserExceptionInGetResourceSearchText(); + void shouldDeliverEDAMSystemExceptionInGetResourceSearchText(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceSearchText(); + void shouldDeliverThriftExceptionInGetResourceSearchText(); + void shouldExecuteGetResourceSearchTextAsync(); + void shouldDeliverEDAMUserExceptionInGetResourceSearchTextAsync(); + void shouldDeliverEDAMSystemExceptionInGetResourceSearchTextAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceSearchTextAsync(); + void shouldDeliverThriftExceptionInGetResourceSearchTextAsync(); + void shouldExecuteGetNoteTagNames(); + void shouldDeliverEDAMUserExceptionInGetNoteTagNames(); + void shouldDeliverEDAMSystemExceptionInGetNoteTagNames(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteTagNames(); + void shouldDeliverThriftExceptionInGetNoteTagNames(); + void shouldExecuteGetNoteTagNamesAsync(); + void shouldDeliverEDAMUserExceptionInGetNoteTagNamesAsync(); + void shouldDeliverEDAMSystemExceptionInGetNoteTagNamesAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteTagNamesAsync(); + void shouldDeliverThriftExceptionInGetNoteTagNamesAsync(); + void shouldExecuteCreateNote(); + void shouldDeliverEDAMUserExceptionInCreateNote(); + void shouldDeliverEDAMSystemExceptionInCreateNote(); + void shouldDeliverEDAMNotFoundExceptionInCreateNote(); + void shouldDeliverThriftExceptionInCreateNote(); + void shouldExecuteCreateNoteAsync(); + void shouldDeliverEDAMUserExceptionInCreateNoteAsync(); + void shouldDeliverEDAMSystemExceptionInCreateNoteAsync(); + void shouldDeliverEDAMNotFoundExceptionInCreateNoteAsync(); + void shouldDeliverThriftExceptionInCreateNoteAsync(); + void shouldExecuteUpdateNote(); + void shouldDeliverEDAMUserExceptionInUpdateNote(); + void shouldDeliverEDAMSystemExceptionInUpdateNote(); + void shouldDeliverEDAMNotFoundExceptionInUpdateNote(); + void shouldDeliverThriftExceptionInUpdateNote(); + void shouldExecuteUpdateNoteAsync(); + void shouldDeliverEDAMUserExceptionInUpdateNoteAsync(); + void shouldDeliverEDAMSystemExceptionInUpdateNoteAsync(); + void shouldDeliverEDAMNotFoundExceptionInUpdateNoteAsync(); + void shouldDeliverThriftExceptionInUpdateNoteAsync(); + void shouldExecuteDeleteNote(); + void shouldDeliverEDAMUserExceptionInDeleteNote(); + void shouldDeliverEDAMSystemExceptionInDeleteNote(); + void shouldDeliverEDAMNotFoundExceptionInDeleteNote(); + void shouldDeliverThriftExceptionInDeleteNote(); + void shouldExecuteDeleteNoteAsync(); + void shouldDeliverEDAMUserExceptionInDeleteNoteAsync(); + void shouldDeliverEDAMSystemExceptionInDeleteNoteAsync(); + void shouldDeliverEDAMNotFoundExceptionInDeleteNoteAsync(); + void shouldDeliverThriftExceptionInDeleteNoteAsync(); + void shouldExecuteExpungeNote(); + void shouldDeliverEDAMUserExceptionInExpungeNote(); + void shouldDeliverEDAMSystemExceptionInExpungeNote(); + void shouldDeliverEDAMNotFoundExceptionInExpungeNote(); + void shouldDeliverThriftExceptionInExpungeNote(); + void shouldExecuteExpungeNoteAsync(); + void shouldDeliverEDAMUserExceptionInExpungeNoteAsync(); + void shouldDeliverEDAMSystemExceptionInExpungeNoteAsync(); + void shouldDeliverEDAMNotFoundExceptionInExpungeNoteAsync(); + void shouldDeliverThriftExceptionInExpungeNoteAsync(); + void shouldExecuteCopyNote(); + void shouldDeliverEDAMUserExceptionInCopyNote(); + void shouldDeliverEDAMSystemExceptionInCopyNote(); + void shouldDeliverEDAMNotFoundExceptionInCopyNote(); + void shouldDeliverThriftExceptionInCopyNote(); + void shouldExecuteCopyNoteAsync(); + void shouldDeliverEDAMUserExceptionInCopyNoteAsync(); + void shouldDeliverEDAMSystemExceptionInCopyNoteAsync(); + void shouldDeliverEDAMNotFoundExceptionInCopyNoteAsync(); + void shouldDeliverThriftExceptionInCopyNoteAsync(); + void shouldExecuteListNoteVersions(); + void shouldDeliverEDAMUserExceptionInListNoteVersions(); + void shouldDeliverEDAMSystemExceptionInListNoteVersions(); + void shouldDeliverEDAMNotFoundExceptionInListNoteVersions(); + void shouldDeliverThriftExceptionInListNoteVersions(); + void shouldExecuteListNoteVersionsAsync(); + void shouldDeliverEDAMUserExceptionInListNoteVersionsAsync(); + void shouldDeliverEDAMSystemExceptionInListNoteVersionsAsync(); + void shouldDeliverEDAMNotFoundExceptionInListNoteVersionsAsync(); + void shouldDeliverThriftExceptionInListNoteVersionsAsync(); + void shouldExecuteGetNoteVersion(); + void shouldDeliverEDAMUserExceptionInGetNoteVersion(); + void shouldDeliverEDAMSystemExceptionInGetNoteVersion(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteVersion(); + void shouldDeliverThriftExceptionInGetNoteVersion(); + void shouldExecuteGetNoteVersionAsync(); + void shouldDeliverEDAMUserExceptionInGetNoteVersionAsync(); + void shouldDeliverEDAMSystemExceptionInGetNoteVersionAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetNoteVersionAsync(); + void shouldDeliverThriftExceptionInGetNoteVersionAsync(); + void shouldExecuteGetResource(); + void shouldDeliverEDAMUserExceptionInGetResource(); + void shouldDeliverEDAMSystemExceptionInGetResource(); + void shouldDeliverEDAMNotFoundExceptionInGetResource(); + void shouldDeliverThriftExceptionInGetResource(); + void shouldExecuteGetResourceAsync(); + void shouldDeliverEDAMUserExceptionInGetResourceAsync(); + void shouldDeliverEDAMSystemExceptionInGetResourceAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceAsync(); + void shouldDeliverThriftExceptionInGetResourceAsync(); + void shouldExecuteGetResourceApplicationData(); + void shouldDeliverEDAMUserExceptionInGetResourceApplicationData(); + void shouldDeliverEDAMSystemExceptionInGetResourceApplicationData(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceApplicationData(); + void shouldDeliverThriftExceptionInGetResourceApplicationData(); + void shouldExecuteGetResourceApplicationDataAsync(); + void shouldDeliverEDAMUserExceptionInGetResourceApplicationDataAsync(); + void shouldDeliverEDAMSystemExceptionInGetResourceApplicationDataAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceApplicationDataAsync(); + void shouldDeliverThriftExceptionInGetResourceApplicationDataAsync(); + void shouldExecuteGetResourceApplicationDataEntry(); + void shouldDeliverEDAMUserExceptionInGetResourceApplicationDataEntry(); + void shouldDeliverEDAMSystemExceptionInGetResourceApplicationDataEntry(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceApplicationDataEntry(); + void shouldDeliverThriftExceptionInGetResourceApplicationDataEntry(); + void shouldExecuteGetResourceApplicationDataEntryAsync(); + void shouldDeliverEDAMUserExceptionInGetResourceApplicationDataEntryAsync(); + void shouldDeliverEDAMSystemExceptionInGetResourceApplicationDataEntryAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceApplicationDataEntryAsync(); + void shouldDeliverThriftExceptionInGetResourceApplicationDataEntryAsync(); + void shouldExecuteSetResourceApplicationDataEntry(); + void shouldDeliverEDAMUserExceptionInSetResourceApplicationDataEntry(); + void shouldDeliverEDAMSystemExceptionInSetResourceApplicationDataEntry(); + void shouldDeliverEDAMNotFoundExceptionInSetResourceApplicationDataEntry(); + void shouldDeliverThriftExceptionInSetResourceApplicationDataEntry(); + void shouldExecuteSetResourceApplicationDataEntryAsync(); + void shouldDeliverEDAMUserExceptionInSetResourceApplicationDataEntryAsync(); + void shouldDeliverEDAMSystemExceptionInSetResourceApplicationDataEntryAsync(); + void shouldDeliverEDAMNotFoundExceptionInSetResourceApplicationDataEntryAsync(); + void shouldDeliverThriftExceptionInSetResourceApplicationDataEntryAsync(); + void shouldExecuteUnsetResourceApplicationDataEntry(); + void shouldDeliverEDAMUserExceptionInUnsetResourceApplicationDataEntry(); + void shouldDeliverEDAMSystemExceptionInUnsetResourceApplicationDataEntry(); + void shouldDeliverEDAMNotFoundExceptionInUnsetResourceApplicationDataEntry(); + void shouldDeliverThriftExceptionInUnsetResourceApplicationDataEntry(); + void shouldExecuteUnsetResourceApplicationDataEntryAsync(); + void shouldDeliverEDAMUserExceptionInUnsetResourceApplicationDataEntryAsync(); + void shouldDeliverEDAMSystemExceptionInUnsetResourceApplicationDataEntryAsync(); + void shouldDeliverEDAMNotFoundExceptionInUnsetResourceApplicationDataEntryAsync(); + void shouldDeliverThriftExceptionInUnsetResourceApplicationDataEntryAsync(); + void shouldExecuteUpdateResource(); + void shouldDeliverEDAMUserExceptionInUpdateResource(); + void shouldDeliverEDAMSystemExceptionInUpdateResource(); + void shouldDeliverEDAMNotFoundExceptionInUpdateResource(); + void shouldDeliverThriftExceptionInUpdateResource(); + void shouldExecuteUpdateResourceAsync(); + void shouldDeliverEDAMUserExceptionInUpdateResourceAsync(); + void shouldDeliverEDAMSystemExceptionInUpdateResourceAsync(); + void shouldDeliverEDAMNotFoundExceptionInUpdateResourceAsync(); + void shouldDeliverThriftExceptionInUpdateResourceAsync(); + void shouldExecuteGetResourceData(); + void shouldDeliverEDAMUserExceptionInGetResourceData(); + void shouldDeliverEDAMSystemExceptionInGetResourceData(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceData(); + void shouldDeliverThriftExceptionInGetResourceData(); + void shouldExecuteGetResourceDataAsync(); + void shouldDeliverEDAMUserExceptionInGetResourceDataAsync(); + void shouldDeliverEDAMSystemExceptionInGetResourceDataAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceDataAsync(); + void shouldDeliverThriftExceptionInGetResourceDataAsync(); + void shouldExecuteGetResourceByHash(); + void shouldDeliverEDAMUserExceptionInGetResourceByHash(); + void shouldDeliverEDAMSystemExceptionInGetResourceByHash(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceByHash(); + void shouldDeliverThriftExceptionInGetResourceByHash(); + void shouldExecuteGetResourceByHashAsync(); + void shouldDeliverEDAMUserExceptionInGetResourceByHashAsync(); + void shouldDeliverEDAMSystemExceptionInGetResourceByHashAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceByHashAsync(); + void shouldDeliverThriftExceptionInGetResourceByHashAsync(); + void shouldExecuteGetResourceRecognition(); + void shouldDeliverEDAMUserExceptionInGetResourceRecognition(); + void shouldDeliverEDAMSystemExceptionInGetResourceRecognition(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceRecognition(); + void shouldDeliverThriftExceptionInGetResourceRecognition(); + void shouldExecuteGetResourceRecognitionAsync(); + void shouldDeliverEDAMUserExceptionInGetResourceRecognitionAsync(); + void shouldDeliverEDAMSystemExceptionInGetResourceRecognitionAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceRecognitionAsync(); + void shouldDeliverThriftExceptionInGetResourceRecognitionAsync(); + void shouldExecuteGetResourceAlternateData(); + void shouldDeliverEDAMUserExceptionInGetResourceAlternateData(); + void shouldDeliverEDAMSystemExceptionInGetResourceAlternateData(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceAlternateData(); + void shouldDeliverThriftExceptionInGetResourceAlternateData(); + void shouldExecuteGetResourceAlternateDataAsync(); + void shouldDeliverEDAMUserExceptionInGetResourceAlternateDataAsync(); + void shouldDeliverEDAMSystemExceptionInGetResourceAlternateDataAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceAlternateDataAsync(); + void shouldDeliverThriftExceptionInGetResourceAlternateDataAsync(); + void shouldExecuteGetResourceAttributes(); + void shouldDeliverEDAMUserExceptionInGetResourceAttributes(); + void shouldDeliverEDAMSystemExceptionInGetResourceAttributes(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceAttributes(); + void shouldDeliverThriftExceptionInGetResourceAttributes(); + void shouldExecuteGetResourceAttributesAsync(); + void shouldDeliverEDAMUserExceptionInGetResourceAttributesAsync(); + void shouldDeliverEDAMSystemExceptionInGetResourceAttributesAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetResourceAttributesAsync(); + void shouldDeliverThriftExceptionInGetResourceAttributesAsync(); + void shouldExecuteGetPublicNotebook(); + void shouldDeliverEDAMSystemExceptionInGetPublicNotebook(); + void shouldDeliverEDAMNotFoundExceptionInGetPublicNotebook(); + void shouldDeliverThriftExceptionInGetPublicNotebook(); + void shouldExecuteGetPublicNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInGetPublicNotebookAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetPublicNotebookAsync(); + void shouldDeliverThriftExceptionInGetPublicNotebookAsync(); + void shouldExecuteShareNotebook(); + void shouldDeliverEDAMUserExceptionInShareNotebook(); + void shouldDeliverEDAMNotFoundExceptionInShareNotebook(); + void shouldDeliverEDAMSystemExceptionInShareNotebook(); + void shouldDeliverThriftExceptionInShareNotebook(); + void shouldExecuteShareNotebookAsync(); + void shouldDeliverEDAMUserExceptionInShareNotebookAsync(); + void shouldDeliverEDAMNotFoundExceptionInShareNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInShareNotebookAsync(); + void shouldDeliverThriftExceptionInShareNotebookAsync(); + void shouldExecuteCreateOrUpdateNotebookShares(); + void shouldDeliverEDAMUserExceptionInCreateOrUpdateNotebookShares(); + void shouldDeliverEDAMNotFoundExceptionInCreateOrUpdateNotebookShares(); + void shouldDeliverEDAMSystemExceptionInCreateOrUpdateNotebookShares(); + void shouldDeliverEDAMInvalidContactsExceptionInCreateOrUpdateNotebookShares(); + void shouldDeliverThriftExceptionInCreateOrUpdateNotebookShares(); + void shouldExecuteCreateOrUpdateNotebookSharesAsync(); + void shouldDeliverEDAMUserExceptionInCreateOrUpdateNotebookSharesAsync(); + void shouldDeliverEDAMNotFoundExceptionInCreateOrUpdateNotebookSharesAsync(); + void shouldDeliverEDAMSystemExceptionInCreateOrUpdateNotebookSharesAsync(); + void shouldDeliverEDAMInvalidContactsExceptionInCreateOrUpdateNotebookSharesAsync(); + void shouldDeliverThriftExceptionInCreateOrUpdateNotebookSharesAsync(); + void shouldExecuteUpdateSharedNotebook(); + void shouldDeliverEDAMUserExceptionInUpdateSharedNotebook(); + void shouldDeliverEDAMNotFoundExceptionInUpdateSharedNotebook(); + void shouldDeliverEDAMSystemExceptionInUpdateSharedNotebook(); + void shouldDeliverThriftExceptionInUpdateSharedNotebook(); + void shouldExecuteUpdateSharedNotebookAsync(); + void shouldDeliverEDAMUserExceptionInUpdateSharedNotebookAsync(); + void shouldDeliverEDAMNotFoundExceptionInUpdateSharedNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInUpdateSharedNotebookAsync(); + void shouldDeliverThriftExceptionInUpdateSharedNotebookAsync(); + void shouldExecuteSetNotebookRecipientSettings(); + void shouldDeliverEDAMUserExceptionInSetNotebookRecipientSettings(); + void shouldDeliverEDAMNotFoundExceptionInSetNotebookRecipientSettings(); + void shouldDeliverEDAMSystemExceptionInSetNotebookRecipientSettings(); + void shouldDeliverThriftExceptionInSetNotebookRecipientSettings(); + void shouldExecuteSetNotebookRecipientSettingsAsync(); + void shouldDeliverEDAMUserExceptionInSetNotebookRecipientSettingsAsync(); + void shouldDeliverEDAMNotFoundExceptionInSetNotebookRecipientSettingsAsync(); + void shouldDeliverEDAMSystemExceptionInSetNotebookRecipientSettingsAsync(); + void shouldDeliverThriftExceptionInSetNotebookRecipientSettingsAsync(); + void shouldExecuteListSharedNotebooks(); + void shouldDeliverEDAMUserExceptionInListSharedNotebooks(); + void shouldDeliverEDAMNotFoundExceptionInListSharedNotebooks(); + void shouldDeliverEDAMSystemExceptionInListSharedNotebooks(); + void shouldDeliverThriftExceptionInListSharedNotebooks(); + void shouldExecuteListSharedNotebooksAsync(); + void shouldDeliverEDAMUserExceptionInListSharedNotebooksAsync(); + void shouldDeliverEDAMNotFoundExceptionInListSharedNotebooksAsync(); + void shouldDeliverEDAMSystemExceptionInListSharedNotebooksAsync(); + void shouldDeliverThriftExceptionInListSharedNotebooksAsync(); + void shouldExecuteCreateLinkedNotebook(); + void shouldDeliverEDAMUserExceptionInCreateLinkedNotebook(); + void shouldDeliverEDAMNotFoundExceptionInCreateLinkedNotebook(); + void shouldDeliverEDAMSystemExceptionInCreateLinkedNotebook(); + void shouldDeliverThriftExceptionInCreateLinkedNotebook(); + void shouldExecuteCreateLinkedNotebookAsync(); + void shouldDeliverEDAMUserExceptionInCreateLinkedNotebookAsync(); + void shouldDeliverEDAMNotFoundExceptionInCreateLinkedNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInCreateLinkedNotebookAsync(); + void shouldDeliverThriftExceptionInCreateLinkedNotebookAsync(); + void shouldExecuteUpdateLinkedNotebook(); + void shouldDeliverEDAMUserExceptionInUpdateLinkedNotebook(); + void shouldDeliverEDAMNotFoundExceptionInUpdateLinkedNotebook(); + void shouldDeliverEDAMSystemExceptionInUpdateLinkedNotebook(); + void shouldDeliverThriftExceptionInUpdateLinkedNotebook(); + void shouldExecuteUpdateLinkedNotebookAsync(); + void shouldDeliverEDAMUserExceptionInUpdateLinkedNotebookAsync(); + void shouldDeliverEDAMNotFoundExceptionInUpdateLinkedNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInUpdateLinkedNotebookAsync(); + void shouldDeliverThriftExceptionInUpdateLinkedNotebookAsync(); + void shouldExecuteListLinkedNotebooks(); + void shouldDeliverEDAMUserExceptionInListLinkedNotebooks(); + void shouldDeliverEDAMNotFoundExceptionInListLinkedNotebooks(); + void shouldDeliverEDAMSystemExceptionInListLinkedNotebooks(); + void shouldDeliverThriftExceptionInListLinkedNotebooks(); + void shouldExecuteListLinkedNotebooksAsync(); + void shouldDeliverEDAMUserExceptionInListLinkedNotebooksAsync(); + void shouldDeliverEDAMNotFoundExceptionInListLinkedNotebooksAsync(); + void shouldDeliverEDAMSystemExceptionInListLinkedNotebooksAsync(); + void shouldDeliverThriftExceptionInListLinkedNotebooksAsync(); + void shouldExecuteExpungeLinkedNotebook(); + void shouldDeliverEDAMUserExceptionInExpungeLinkedNotebook(); + void shouldDeliverEDAMNotFoundExceptionInExpungeLinkedNotebook(); + void shouldDeliverEDAMSystemExceptionInExpungeLinkedNotebook(); + void shouldDeliverThriftExceptionInExpungeLinkedNotebook(); + void shouldExecuteExpungeLinkedNotebookAsync(); + void shouldDeliverEDAMUserExceptionInExpungeLinkedNotebookAsync(); + void shouldDeliverEDAMNotFoundExceptionInExpungeLinkedNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInExpungeLinkedNotebookAsync(); + void shouldDeliverThriftExceptionInExpungeLinkedNotebookAsync(); + void shouldExecuteAuthenticateToSharedNotebook(); + void shouldDeliverEDAMUserExceptionInAuthenticateToSharedNotebook(); + void shouldDeliverEDAMNotFoundExceptionInAuthenticateToSharedNotebook(); + void shouldDeliverEDAMSystemExceptionInAuthenticateToSharedNotebook(); + void shouldDeliverThriftExceptionInAuthenticateToSharedNotebook(); + void shouldExecuteAuthenticateToSharedNotebookAsync(); + void shouldDeliverEDAMUserExceptionInAuthenticateToSharedNotebookAsync(); + void shouldDeliverEDAMNotFoundExceptionInAuthenticateToSharedNotebookAsync(); + void shouldDeliverEDAMSystemExceptionInAuthenticateToSharedNotebookAsync(); + void shouldDeliverThriftExceptionInAuthenticateToSharedNotebookAsync(); + void shouldExecuteGetSharedNotebookByAuth(); + void shouldDeliverEDAMUserExceptionInGetSharedNotebookByAuth(); + void shouldDeliverEDAMNotFoundExceptionInGetSharedNotebookByAuth(); + void shouldDeliverEDAMSystemExceptionInGetSharedNotebookByAuth(); + void shouldDeliverThriftExceptionInGetSharedNotebookByAuth(); + void shouldExecuteGetSharedNotebookByAuthAsync(); + void shouldDeliverEDAMUserExceptionInGetSharedNotebookByAuthAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetSharedNotebookByAuthAsync(); + void shouldDeliverEDAMSystemExceptionInGetSharedNotebookByAuthAsync(); + void shouldDeliverThriftExceptionInGetSharedNotebookByAuthAsync(); + void shouldExecuteEmailNote(); + void shouldDeliverEDAMUserExceptionInEmailNote(); + void shouldDeliverEDAMNotFoundExceptionInEmailNote(); + void shouldDeliverEDAMSystemExceptionInEmailNote(); + void shouldDeliverThriftExceptionInEmailNote(); + void shouldExecuteEmailNoteAsync(); + void shouldDeliverEDAMUserExceptionInEmailNoteAsync(); + void shouldDeliverEDAMNotFoundExceptionInEmailNoteAsync(); + void shouldDeliverEDAMSystemExceptionInEmailNoteAsync(); + void shouldDeliverThriftExceptionInEmailNoteAsync(); + void shouldExecuteShareNote(); + void shouldDeliverEDAMUserExceptionInShareNote(); + void shouldDeliverEDAMNotFoundExceptionInShareNote(); + void shouldDeliverEDAMSystemExceptionInShareNote(); + void shouldDeliverThriftExceptionInShareNote(); + void shouldExecuteShareNoteAsync(); + void shouldDeliverEDAMUserExceptionInShareNoteAsync(); + void shouldDeliverEDAMNotFoundExceptionInShareNoteAsync(); + void shouldDeliverEDAMSystemExceptionInShareNoteAsync(); + void shouldDeliverThriftExceptionInShareNoteAsync(); + void shouldExecuteStopSharingNote(); + void shouldDeliverEDAMUserExceptionInStopSharingNote(); + void shouldDeliverEDAMNotFoundExceptionInStopSharingNote(); + void shouldDeliverEDAMSystemExceptionInStopSharingNote(); + void shouldDeliverThriftExceptionInStopSharingNote(); + void shouldExecuteStopSharingNoteAsync(); + void shouldDeliverEDAMUserExceptionInStopSharingNoteAsync(); + void shouldDeliverEDAMNotFoundExceptionInStopSharingNoteAsync(); + void shouldDeliverEDAMSystemExceptionInStopSharingNoteAsync(); + void shouldDeliverThriftExceptionInStopSharingNoteAsync(); + void shouldExecuteAuthenticateToSharedNote(); + void shouldDeliverEDAMUserExceptionInAuthenticateToSharedNote(); + void shouldDeliverEDAMNotFoundExceptionInAuthenticateToSharedNote(); + void shouldDeliverEDAMSystemExceptionInAuthenticateToSharedNote(); + void shouldDeliverThriftExceptionInAuthenticateToSharedNote(); + void shouldExecuteAuthenticateToSharedNoteAsync(); + void shouldDeliverEDAMUserExceptionInAuthenticateToSharedNoteAsync(); + void shouldDeliverEDAMNotFoundExceptionInAuthenticateToSharedNoteAsync(); + void shouldDeliverEDAMSystemExceptionInAuthenticateToSharedNoteAsync(); + void shouldDeliverThriftExceptionInAuthenticateToSharedNoteAsync(); + void shouldExecuteFindRelated(); + void shouldDeliverEDAMUserExceptionInFindRelated(); + void shouldDeliverEDAMSystemExceptionInFindRelated(); + void shouldDeliverEDAMNotFoundExceptionInFindRelated(); + void shouldDeliverThriftExceptionInFindRelated(); + void shouldExecuteFindRelatedAsync(); + void shouldDeliverEDAMUserExceptionInFindRelatedAsync(); + void shouldDeliverEDAMSystemExceptionInFindRelatedAsync(); + void shouldDeliverEDAMNotFoundExceptionInFindRelatedAsync(); + void shouldDeliverThriftExceptionInFindRelatedAsync(); + void shouldExecuteUpdateNoteIfUsnMatches(); + void shouldDeliverEDAMUserExceptionInUpdateNoteIfUsnMatches(); + void shouldDeliverEDAMNotFoundExceptionInUpdateNoteIfUsnMatches(); + void shouldDeliverEDAMSystemExceptionInUpdateNoteIfUsnMatches(); + void shouldDeliverThriftExceptionInUpdateNoteIfUsnMatches(); + void shouldExecuteUpdateNoteIfUsnMatchesAsync(); + void shouldDeliverEDAMUserExceptionInUpdateNoteIfUsnMatchesAsync(); + void shouldDeliverEDAMNotFoundExceptionInUpdateNoteIfUsnMatchesAsync(); + void shouldDeliverEDAMSystemExceptionInUpdateNoteIfUsnMatchesAsync(); + void shouldDeliverThriftExceptionInUpdateNoteIfUsnMatchesAsync(); + void shouldExecuteManageNotebookShares(); + void shouldDeliverEDAMUserExceptionInManageNotebookShares(); + void shouldDeliverEDAMNotFoundExceptionInManageNotebookShares(); + void shouldDeliverEDAMSystemExceptionInManageNotebookShares(); + void shouldDeliverThriftExceptionInManageNotebookShares(); + void shouldExecuteManageNotebookSharesAsync(); + void shouldDeliverEDAMUserExceptionInManageNotebookSharesAsync(); + void shouldDeliverEDAMNotFoundExceptionInManageNotebookSharesAsync(); + void shouldDeliverEDAMSystemExceptionInManageNotebookSharesAsync(); + void shouldDeliverThriftExceptionInManageNotebookSharesAsync(); + void shouldExecuteGetNotebookShares(); + void shouldDeliverEDAMUserExceptionInGetNotebookShares(); + void shouldDeliverEDAMNotFoundExceptionInGetNotebookShares(); + void shouldDeliverEDAMSystemExceptionInGetNotebookShares(); + void shouldDeliverThriftExceptionInGetNotebookShares(); + void shouldExecuteGetNotebookSharesAsync(); + void shouldDeliverEDAMUserExceptionInGetNotebookSharesAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetNotebookSharesAsync(); + void shouldDeliverEDAMSystemExceptionInGetNotebookSharesAsync(); + void shouldDeliverThriftExceptionInGetNotebookSharesAsync(); +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_GENERATED_TESTNOTESTORE_H diff --git a/src/qevercloud/QEverCloud/src/tests/generated/TestUserStore.cpp b/src/qevercloud/QEverCloud/src/tests/generated/TestUserStore.cpp new file mode 100644 index 00000000..e457ecae --- /dev/null +++ b/src/qevercloud/QEverCloud/src/tests/generated/TestUserStore.cpp @@ -0,0 +1,13387 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + * + * This file was generated from Evernote Thrift API + */ + +#include "TestUserStore.h" +#include "../../Impl.h" +#include "../../HttpUtils.h" +#include "RandomDataGenerators.h" +#include +#include +#include +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +UserStoreTester::UserStoreTester(QObject * parent) : + QObject(parent) +{} + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreCheckVersionTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + bool( + QString, + qint16, + qint16, + IRequestContextPtr ctx)>; + +public: + explicit UserStoreCheckVersionTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void checkVersionRequestReady( + bool value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onCheckVersionRequestReceived( + QString clientName, + qint16 edamVersionMajor, + qint16 edamVersionMinor, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + clientName, + edamVersionMajor, + edamVersionMinor, + ctx); + + Q_EMIT checkVersionRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT checkVersionRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreGetBootstrapInfoTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + BootstrapInfo( + QString, + IRequestContextPtr ctx)>; + +public: + explicit UserStoreGetBootstrapInfoTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getBootstrapInfoRequestReady( + BootstrapInfo value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetBootstrapInfoRequestReceived( + QString locale, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + locale, + ctx); + + Q_EMIT getBootstrapInfoRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getBootstrapInfoRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreAuthenticateLongSessionTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + AuthenticationResult( + QString, + QString, + QString, + QString, + QString, + QString, + bool, + IRequestContextPtr ctx)>; + +public: + explicit UserStoreAuthenticateLongSessionTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void authenticateLongSessionRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onAuthenticateLongSessionRequestReceived( + QString username, + QString password, + QString consumerKey, + QString consumerSecret, + QString deviceIdentifier, + QString deviceDescription, + bool supportsTwoFactor, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + + Q_EMIT authenticateLongSessionRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT authenticateLongSessionRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreCompleteTwoFactorAuthenticationTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + AuthenticationResult( + QString, + QString, + QString, + IRequestContextPtr ctx)>; + +public: + explicit UserStoreCompleteTwoFactorAuthenticationTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void completeTwoFactorAuthenticationRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onCompleteTwoFactorAuthenticationRequestReceived( + QString oneTimeCode, + QString deviceIdentifier, + QString deviceDescription, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + + Q_EMIT completeTwoFactorAuthenticationRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT completeTwoFactorAuthenticationRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreRevokeLongSessionTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + void( + IRequestContextPtr ctx)>; + +public: + explicit UserStoreRevokeLongSessionTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void revokeLongSessionRequestReady( + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onRevokeLongSessionRequestReceived( + IRequestContextPtr ctx) + { + try + { + m_executor( + ctx); + + Q_EMIT revokeLongSessionRequestReady( + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT revokeLongSessionRequestReady( + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreAuthenticateToBusinessTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + AuthenticationResult( + IRequestContextPtr ctx)>; + +public: + explicit UserStoreAuthenticateToBusinessTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void authenticateToBusinessRequestReady( + AuthenticationResult value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onAuthenticateToBusinessRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT authenticateToBusinessRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT authenticateToBusinessRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreGetUserTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + User( + IRequestContextPtr ctx)>; + +public: + explicit UserStoreGetUserTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getUserRequestReady( + User value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetUserRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT getUserRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getUserRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreGetPublicUserInfoTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + PublicUserInfo( + QString, + IRequestContextPtr ctx)>; + +public: + explicit UserStoreGetPublicUserInfoTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getPublicUserInfoRequestReady( + PublicUserInfo value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetPublicUserInfoRequestReceived( + QString username, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + username, + ctx); + + Q_EMIT getPublicUserInfoRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getPublicUserInfoRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreGetUserUrlsTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + UserUrls( + IRequestContextPtr ctx)>; + +public: + explicit UserStoreGetUserUrlsTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getUserUrlsRequestReady( + UserUrls value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetUserUrlsRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT getUserUrlsRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getUserUrlsRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreInviteToBusinessTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + void( + QString, + IRequestContextPtr ctx)>; + +public: + explicit UserStoreInviteToBusinessTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void inviteToBusinessRequestReady( + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onInviteToBusinessRequestReceived( + QString emailAddress, + IRequestContextPtr ctx) + { + try + { + m_executor( + emailAddress, + ctx); + + Q_EMIT inviteToBusinessRequestReady( + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT inviteToBusinessRequestReady( + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreRemoveFromBusinessTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + void( + QString, + IRequestContextPtr ctx)>; + +public: + explicit UserStoreRemoveFromBusinessTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void removeFromBusinessRequestReady( + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onRemoveFromBusinessRequestReceived( + QString emailAddress, + IRequestContextPtr ctx) + { + try + { + m_executor( + emailAddress, + ctx); + + Q_EMIT removeFromBusinessRequestReady( + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT removeFromBusinessRequestReady( + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreUpdateBusinessUserIdentifierTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + void( + QString, + QString, + IRequestContextPtr ctx)>; + +public: + explicit UserStoreUpdateBusinessUserIdentifierTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void updateBusinessUserIdentifierRequestReady( + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onUpdateBusinessUserIdentifierRequestReceived( + QString oldEmailAddress, + QString newEmailAddress, + IRequestContextPtr ctx) + { + try + { + m_executor( + oldEmailAddress, + newEmailAddress, + ctx); + + Q_EMIT updateBusinessUserIdentifierRequestReady( + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT updateBusinessUserIdentifierRequestReady( + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreListBusinessUsersTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QList( + IRequestContextPtr ctx)>; + +public: + explicit UserStoreListBusinessUsersTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void listBusinessUsersRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onListBusinessUsersRequestReceived( + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + ctx); + + Q_EMIT listBusinessUsersRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT listBusinessUsersRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreListBusinessInvitationsTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + QList( + bool, + IRequestContextPtr ctx)>; + +public: + explicit UserStoreListBusinessInvitationsTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void listBusinessInvitationsRequestReady( + QList value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onListBusinessInvitationsRequestReceived( + bool includeRequestedInvitations, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + includeRequestedInvitations, + ctx); + + Q_EMIT listBusinessInvitationsRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT listBusinessInvitationsRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreGetAccountLimitsTesterHelper: public QObject +{ + Q_OBJECT +public: + using Executor = std::function< + AccountLimits( + ServiceLevel, + IRequestContextPtr ctx)>; + +public: + explicit UserStoreGetAccountLimitsTesterHelper( + Executor executor, + QObject * parent = nullptr) : + QObject(parent), + m_executor(std::move(executor)) + {} + +Q_SIGNALS: + void getAccountLimitsRequestReady( + AccountLimits value, + EverCloudExceptionDataPtr exceptionData); + +public Q_SLOTS: + void onGetAccountLimitsRequestReceived( + ServiceLevel serviceLevel, + IRequestContextPtr ctx) + { + try + { + auto v = m_executor( + serviceLevel, + ctx); + + Q_EMIT getAccountLimitsRequestReady( + v, + EverCloudExceptionDataPtr()); + } + catch(const EverCloudException & e) + { + Q_EMIT getAccountLimitsRequestReady( + {}, + e.exceptionData()); + } + } + +private: + Executor m_executor; +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreCheckVersionAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreCheckVersionAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + bool m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreGetBootstrapInfoAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreGetBootstrapInfoAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + BootstrapInfo m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreAuthenticateLongSessionAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreAuthenticateLongSessionAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + AuthenticationResult m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + AuthenticationResult m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreRevokeLongSessionAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreRevokeLongSessionAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + Q_UNUSED(value) + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreAuthenticateToBusinessAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreAuthenticateToBusinessAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + AuthenticationResult m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreGetUserAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreGetUserAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + User m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreGetPublicUserInfoAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreGetPublicUserInfoAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + PublicUserInfo m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreGetUserUrlsAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreGetUserUrlsAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + UserUrls m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreInviteToBusinessAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreInviteToBusinessAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + Q_UNUSED(value) + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreRemoveFromBusinessAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreRemoveFromBusinessAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + Q_UNUSED(value) + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + Q_UNUSED(value) + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreListBusinessUsersAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreListBusinessUsersAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QList m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast>(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreListBusinessInvitationsAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreListBusinessInvitationsAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + QList m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast>(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreGetAccountLimitsAsyncValueFetcher: public QObject +{ + Q_OBJECT +public: + explicit UserStoreGetAccountLimitsAsyncValueFetcher(QObject * parent = nullptr) : + QObject(parent) + {} + + AccountLimits m_value; + EverCloudExceptionDataPtr m_exceptionData; + +Q_SIGNALS: + void finished(); + +public Q_SLOTS: + void onFinished( + QVariant value, + EverCloudExceptionDataPtr data, + IRequestContextPtr ctx) + { + m_value = qvariant_cast(value); + Q_UNUSED(ctx) + m_exceptionData = data; + Q_EMIT finished(); + } +}; + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteCheckVersion() +{ + QString clientName = generateRandomString(); + qint16 edamVersionMajor = generateRandomInt16(); + qint16 edamVersionMinor = generateRandomInt16(); + IRequestContextPtr ctx = newRequestContext(); + + bool response = generateRandomBool(); + + UserStoreCheckVersionTesterHelper helper( + [&] (const QString & clientNameParam, + qint16 edamVersionMajorParam, + qint16 edamVersionMinorParam, + IRequestContextPtr ctxParam) -> bool + { + Q_ASSERT(clientName == clientNameParam); + Q_ASSERT(edamVersionMajor == edamVersionMajorParam); + Q_ASSERT(edamVersionMinor == edamVersionMinorParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::checkVersionRequest, + &helper, + &UserStoreCheckVersionTesterHelper::onCheckVersionRequestReceived); + QObject::connect( + &helper, + &UserStoreCheckVersionTesterHelper::checkVersionRequestReady, + &server, + &UserStoreServer::onCheckVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::checkVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool res = userStore->checkVersion( + clientName, + edamVersionMajor, + edamVersionMinor, + ctx); + QVERIFY(res == response); +} + +void UserStoreTester::shouldDeliverThriftExceptionInCheckVersion() +{ + QString clientName = generateRandomString(); + qint16 edamVersionMajor = generateRandomInt16(); + qint16 edamVersionMinor = generateRandomInt16(); + IRequestContextPtr ctx = newRequestContext(); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreCheckVersionTesterHelper helper( + [&] (const QString & clientNameParam, + qint16 edamVersionMajorParam, + qint16 edamVersionMinorParam, + IRequestContextPtr ctxParam) -> bool + { + Q_ASSERT(clientName == clientNameParam); + Q_ASSERT(edamVersionMajor == edamVersionMajorParam); + Q_ASSERT(edamVersionMinor == edamVersionMinorParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::checkVersionRequest, + &helper, + &UserStoreCheckVersionTesterHelper::onCheckVersionRequestReceived); + QObject::connect( + &helper, + &UserStoreCheckVersionTesterHelper::checkVersionRequestReady, + &server, + &UserStoreServer::onCheckVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::checkVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + bool res = userStore->checkVersion( + clientName, + edamVersionMajor, + edamVersionMinor, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteCheckVersionAsync() +{ + QString clientName = generateRandomString(); + qint16 edamVersionMajor = generateRandomInt16(); + qint16 edamVersionMinor = generateRandomInt16(); + IRequestContextPtr ctx = newRequestContext(); + + bool response = generateRandomBool(); + + UserStoreCheckVersionTesterHelper helper( + [&] (const QString & clientNameParam, + qint16 edamVersionMajorParam, + qint16 edamVersionMinorParam, + IRequestContextPtr ctxParam) -> bool + { + Q_ASSERT(clientName == clientNameParam); + Q_ASSERT(edamVersionMajor == edamVersionMajorParam); + Q_ASSERT(edamVersionMinor == edamVersionMinorParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::checkVersionRequest, + &helper, + &UserStoreCheckVersionTesterHelper::onCheckVersionRequestReceived); + QObject::connect( + &helper, + &UserStoreCheckVersionTesterHelper::checkVersionRequestReady, + &server, + &UserStoreServer::onCheckVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::checkVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->checkVersionAsync( + clientName, + edamVersionMajor, + edamVersionMinor, + ctx); + + UserStoreCheckVersionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreCheckVersionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreCheckVersionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverThriftExceptionInCheckVersionAsync() +{ + QString clientName = generateRandomString(); + qint16 edamVersionMajor = generateRandomInt16(); + qint16 edamVersionMinor = generateRandomInt16(); + IRequestContextPtr ctx = newRequestContext(); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreCheckVersionTesterHelper helper( + [&] (const QString & clientNameParam, + qint16 edamVersionMajorParam, + qint16 edamVersionMinorParam, + IRequestContextPtr ctxParam) -> bool + { + Q_ASSERT(clientName == clientNameParam); + Q_ASSERT(edamVersionMajor == edamVersionMajorParam); + Q_ASSERT(edamVersionMinor == edamVersionMinorParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::checkVersionRequest, + &helper, + &UserStoreCheckVersionTesterHelper::onCheckVersionRequestReceived); + QObject::connect( + &helper, + &UserStoreCheckVersionTesterHelper::checkVersionRequestReady, + &server, + &UserStoreServer::onCheckVersionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::checkVersionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->checkVersionAsync( + clientName, + edamVersionMajor, + edamVersionMinor, + ctx); + + UserStoreCheckVersionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreCheckVersionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreCheckVersionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteGetBootstrapInfo() +{ + QString locale = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + BootstrapInfo response = generateRandomBootstrapInfo(); + + UserStoreGetBootstrapInfoTesterHelper helper( + [&] (const QString & localeParam, + IRequestContextPtr ctxParam) -> BootstrapInfo + { + Q_ASSERT(locale == localeParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getBootstrapInfoRequest, + &helper, + &UserStoreGetBootstrapInfoTesterHelper::onGetBootstrapInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetBootstrapInfoTesterHelper::getBootstrapInfoRequestReady, + &server, + &UserStoreServer::onGetBootstrapInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getBootstrapInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + BootstrapInfo res = userStore->getBootstrapInfo( + locale, + ctx); + QVERIFY(res == response); +} + +void UserStoreTester::shouldDeliverThriftExceptionInGetBootstrapInfo() +{ + QString locale = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreGetBootstrapInfoTesterHelper helper( + [&] (const QString & localeParam, + IRequestContextPtr ctxParam) -> BootstrapInfo + { + Q_ASSERT(locale == localeParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getBootstrapInfoRequest, + &helper, + &UserStoreGetBootstrapInfoTesterHelper::onGetBootstrapInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetBootstrapInfoTesterHelper::getBootstrapInfoRequestReady, + &server, + &UserStoreServer::onGetBootstrapInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getBootstrapInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + BootstrapInfo res = userStore->getBootstrapInfo( + locale, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteGetBootstrapInfoAsync() +{ + QString locale = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + BootstrapInfo response = generateRandomBootstrapInfo(); + + UserStoreGetBootstrapInfoTesterHelper helper( + [&] (const QString & localeParam, + IRequestContextPtr ctxParam) -> BootstrapInfo + { + Q_ASSERT(locale == localeParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getBootstrapInfoRequest, + &helper, + &UserStoreGetBootstrapInfoTesterHelper::onGetBootstrapInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetBootstrapInfoTesterHelper::getBootstrapInfoRequestReady, + &server, + &UserStoreServer::onGetBootstrapInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getBootstrapInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->getBootstrapInfoAsync( + locale, + ctx); + + UserStoreGetBootstrapInfoAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetBootstrapInfoAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetBootstrapInfoAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverThriftExceptionInGetBootstrapInfoAsync() +{ + QString locale = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreGetBootstrapInfoTesterHelper helper( + [&] (const QString & localeParam, + IRequestContextPtr ctxParam) -> BootstrapInfo + { + Q_ASSERT(locale == localeParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getBootstrapInfoRequest, + &helper, + &UserStoreGetBootstrapInfoTesterHelper::onGetBootstrapInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetBootstrapInfoTesterHelper::getBootstrapInfoRequestReady, + &server, + &UserStoreServer::onGetBootstrapInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getBootstrapInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getBootstrapInfoAsync( + locale, + ctx); + + UserStoreGetBootstrapInfoAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetBootstrapInfoAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetBootstrapInfoAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteAuthenticateLongSession() +{ + QString username = generateRandomString(); + QString password = generateRandomString(); + QString consumerKey = generateRandomString(); + QString consumerSecret = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + bool supportsTwoFactor = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext(); + + AuthenticationResult response = generateRandomAuthenticationResult(); + + UserStoreAuthenticateLongSessionTesterHelper helper( + [&] (const QString & usernameParam, + const QString & passwordParam, + const QString & consumerKeyParam, + const QString & consumerSecretParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + bool supportsTwoFactorParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(username == usernameParam); + Q_ASSERT(password == passwordParam); + Q_ASSERT(consumerKey == consumerKeyParam); + Q_ASSERT(consumerSecret == consumerSecretParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + Q_ASSERT(supportsTwoFactor == supportsTwoFactorParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequest, + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::onAuthenticateLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::authenticateLongSessionRequestReady, + &server, + &UserStoreServer::onAuthenticateLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AuthenticationResult res = userStore->authenticateLongSession( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + QVERIFY(res == response); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInAuthenticateLongSession() +{ + QString username = generateRandomString(); + QString password = generateRandomString(); + QString consumerKey = generateRandomString(); + QString consumerSecret = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + bool supportsTwoFactor = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext(); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + userException.parameter = generateRandomString(); + + UserStoreAuthenticateLongSessionTesterHelper helper( + [&] (const QString & usernameParam, + const QString & passwordParam, + const QString & consumerKeyParam, + const QString & consumerSecretParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + bool supportsTwoFactorParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(username == usernameParam); + Q_ASSERT(password == passwordParam); + Q_ASSERT(consumerKey == consumerKeyParam); + Q_ASSERT(consumerSecret == consumerSecretParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + Q_ASSERT(supportsTwoFactor == supportsTwoFactorParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequest, + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::onAuthenticateLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::authenticateLongSessionRequestReady, + &server, + &UserStoreServer::onAuthenticateLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = userStore->authenticateLongSession( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInAuthenticateLongSession() +{ + QString username = generateRandomString(); + QString password = generateRandomString(); + QString consumerKey = generateRandomString(); + QString consumerSecret = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + bool supportsTwoFactor = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext(); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LEN_TOO_LONG; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreAuthenticateLongSessionTesterHelper helper( + [&] (const QString & usernameParam, + const QString & passwordParam, + const QString & consumerKeyParam, + const QString & consumerSecretParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + bool supportsTwoFactorParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(username == usernameParam); + Q_ASSERT(password == passwordParam); + Q_ASSERT(consumerKey == consumerKeyParam); + Q_ASSERT(consumerSecret == consumerSecretParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + Q_ASSERT(supportsTwoFactor == supportsTwoFactorParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequest, + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::onAuthenticateLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::authenticateLongSessionRequestReady, + &server, + &UserStoreServer::onAuthenticateLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = userStore->authenticateLongSession( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInAuthenticateLongSession() +{ + QString username = generateRandomString(); + QString password = generateRandomString(); + QString consumerKey = generateRandomString(); + QString consumerSecret = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + bool supportsTwoFactor = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext(); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreAuthenticateLongSessionTesterHelper helper( + [&] (const QString & usernameParam, + const QString & passwordParam, + const QString & consumerKeyParam, + const QString & consumerSecretParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + bool supportsTwoFactorParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(username == usernameParam); + Q_ASSERT(password == passwordParam); + Q_ASSERT(consumerKey == consumerKeyParam); + Q_ASSERT(consumerSecret == consumerSecretParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + Q_ASSERT(supportsTwoFactor == supportsTwoFactorParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequest, + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::onAuthenticateLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::authenticateLongSessionRequestReady, + &server, + &UserStoreServer::onAuthenticateLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = userStore->authenticateLongSession( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteAuthenticateLongSessionAsync() +{ + QString username = generateRandomString(); + QString password = generateRandomString(); + QString consumerKey = generateRandomString(); + QString consumerSecret = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + bool supportsTwoFactor = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext(); + + AuthenticationResult response = generateRandomAuthenticationResult(); + + UserStoreAuthenticateLongSessionTesterHelper helper( + [&] (const QString & usernameParam, + const QString & passwordParam, + const QString & consumerKeyParam, + const QString & consumerSecretParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + bool supportsTwoFactorParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(username == usernameParam); + Q_ASSERT(password == passwordParam); + Q_ASSERT(consumerKey == consumerKeyParam); + Q_ASSERT(consumerSecret == consumerSecretParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + Q_ASSERT(supportsTwoFactor == supportsTwoFactorParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequest, + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::onAuthenticateLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::authenticateLongSessionRequestReady, + &server, + &UserStoreServer::onAuthenticateLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->authenticateLongSessionAsync( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + + UserStoreAuthenticateLongSessionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreAuthenticateLongSessionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreAuthenticateLongSessionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInAuthenticateLongSessionAsync() +{ + QString username = generateRandomString(); + QString password = generateRandomString(); + QString consumerKey = generateRandomString(); + QString consumerSecret = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + bool supportsTwoFactor = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext(); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ENML_VALIDATION; + userException.parameter = generateRandomString(); + + UserStoreAuthenticateLongSessionTesterHelper helper( + [&] (const QString & usernameParam, + const QString & passwordParam, + const QString & consumerKeyParam, + const QString & consumerSecretParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + bool supportsTwoFactorParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(username == usernameParam); + Q_ASSERT(password == passwordParam); + Q_ASSERT(consumerKey == consumerKeyParam); + Q_ASSERT(consumerSecret == consumerSecretParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + Q_ASSERT(supportsTwoFactor == supportsTwoFactorParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequest, + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::onAuthenticateLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::authenticateLongSessionRequestReady, + &server, + &UserStoreServer::onAuthenticateLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->authenticateLongSessionAsync( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + + UserStoreAuthenticateLongSessionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreAuthenticateLongSessionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreAuthenticateLongSessionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInAuthenticateLongSessionAsync() +{ + QString username = generateRandomString(); + QString password = generateRandomString(); + QString consumerKey = generateRandomString(); + QString consumerSecret = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + bool supportsTwoFactor = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext(); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreAuthenticateLongSessionTesterHelper helper( + [&] (const QString & usernameParam, + const QString & passwordParam, + const QString & consumerKeyParam, + const QString & consumerSecretParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + bool supportsTwoFactorParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(username == usernameParam); + Q_ASSERT(password == passwordParam); + Q_ASSERT(consumerKey == consumerKeyParam); + Q_ASSERT(consumerSecret == consumerSecretParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + Q_ASSERT(supportsTwoFactor == supportsTwoFactorParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequest, + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::onAuthenticateLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::authenticateLongSessionRequestReady, + &server, + &UserStoreServer::onAuthenticateLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->authenticateLongSessionAsync( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + + UserStoreAuthenticateLongSessionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreAuthenticateLongSessionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreAuthenticateLongSessionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInAuthenticateLongSessionAsync() +{ + QString username = generateRandomString(); + QString password = generateRandomString(); + QString consumerKey = generateRandomString(); + QString consumerSecret = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + bool supportsTwoFactor = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext(); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreAuthenticateLongSessionTesterHelper helper( + [&] (const QString & usernameParam, + const QString & passwordParam, + const QString & consumerKeyParam, + const QString & consumerSecretParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + bool supportsTwoFactorParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(username == usernameParam); + Q_ASSERT(password == passwordParam); + Q_ASSERT(consumerKey == consumerKeyParam); + Q_ASSERT(consumerSecret == consumerSecretParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + Q_ASSERT(supportsTwoFactor == supportsTwoFactorParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequest, + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::onAuthenticateLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateLongSessionTesterHelper::authenticateLongSessionRequestReady, + &server, + &UserStoreServer::onAuthenticateLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->authenticateLongSessionAsync( + username, + password, + consumerKey, + consumerSecret, + deviceIdentifier, + deviceDescription, + supportsTwoFactor, + ctx); + + UserStoreAuthenticateLongSessionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreAuthenticateLongSessionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreAuthenticateLongSessionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteCompleteTwoFactorAuthentication() +{ + QString oneTimeCode = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + AuthenticationResult response = generateRandomAuthenticationResult(); + + UserStoreCompleteTwoFactorAuthenticationTesterHelper helper( + [&] (const QString & oneTimeCodeParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oneTimeCode == oneTimeCodeParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequest, + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::onCompleteTwoFactorAuthenticationRequestReceived); + QObject::connect( + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::completeTwoFactorAuthenticationRequestReady, + &server, + &UserStoreServer::onCompleteTwoFactorAuthenticationRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AuthenticationResult res = userStore->completeTwoFactorAuthentication( + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + QVERIFY(res == response); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInCompleteTwoFactorAuthentication() +{ + QString oneTimeCode = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNKNOWN; + userException.parameter = generateRandomString(); + + UserStoreCompleteTwoFactorAuthenticationTesterHelper helper( + [&] (const QString & oneTimeCodeParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oneTimeCode == oneTimeCodeParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequest, + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::onCompleteTwoFactorAuthenticationRequestReceived); + QObject::connect( + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::completeTwoFactorAuthenticationRequestReady, + &server, + &UserStoreServer::onCompleteTwoFactorAuthenticationRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = userStore->completeTwoFactorAuthentication( + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInCompleteTwoFactorAuthentication() +{ + QString oneTimeCode = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TOO_MANY; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreCompleteTwoFactorAuthenticationTesterHelper helper( + [&] (const QString & oneTimeCodeParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oneTimeCode == oneTimeCodeParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequest, + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::onCompleteTwoFactorAuthenticationRequestReceived); + QObject::connect( + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::completeTwoFactorAuthenticationRequestReady, + &server, + &UserStoreServer::onCompleteTwoFactorAuthenticationRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = userStore->completeTwoFactorAuthentication( + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInCompleteTwoFactorAuthentication() +{ + QString oneTimeCode = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreCompleteTwoFactorAuthenticationTesterHelper helper( + [&] (const QString & oneTimeCodeParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oneTimeCode == oneTimeCodeParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequest, + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::onCompleteTwoFactorAuthenticationRequestReceived); + QObject::connect( + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::completeTwoFactorAuthenticationRequestReady, + &server, + &UserStoreServer::onCompleteTwoFactorAuthenticationRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = userStore->completeTwoFactorAuthentication( + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteCompleteTwoFactorAuthenticationAsync() +{ + QString oneTimeCode = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + AuthenticationResult response = generateRandomAuthenticationResult(); + + UserStoreCompleteTwoFactorAuthenticationTesterHelper helper( + [&] (const QString & oneTimeCodeParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oneTimeCode == oneTimeCodeParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequest, + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::onCompleteTwoFactorAuthenticationRequestReceived); + QObject::connect( + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::completeTwoFactorAuthenticationRequestReady, + &server, + &UserStoreServer::onCompleteTwoFactorAuthenticationRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->completeTwoFactorAuthenticationAsync( + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + + UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInCompleteTwoFactorAuthenticationAsync() +{ + QString oneTimeCode = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_LONG; + userException.parameter = generateRandomString(); + + UserStoreCompleteTwoFactorAuthenticationTesterHelper helper( + [&] (const QString & oneTimeCodeParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oneTimeCode == oneTimeCodeParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequest, + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::onCompleteTwoFactorAuthenticationRequestReceived); + QObject::connect( + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::completeTwoFactorAuthenticationRequestReady, + &server, + &UserStoreServer::onCompleteTwoFactorAuthenticationRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->completeTwoFactorAuthenticationAsync( + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + + UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInCompleteTwoFactorAuthenticationAsync() +{ + QString oneTimeCode = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreCompleteTwoFactorAuthenticationTesterHelper helper( + [&] (const QString & oneTimeCodeParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oneTimeCode == oneTimeCodeParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequest, + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::onCompleteTwoFactorAuthenticationRequestReceived); + QObject::connect( + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::completeTwoFactorAuthenticationRequestReady, + &server, + &UserStoreServer::onCompleteTwoFactorAuthenticationRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->completeTwoFactorAuthenticationAsync( + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + + UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInCompleteTwoFactorAuthenticationAsync() +{ + QString oneTimeCode = generateRandomString(); + QString deviceIdentifier = generateRandomString(); + QString deviceDescription = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreCompleteTwoFactorAuthenticationTesterHelper helper( + [&] (const QString & oneTimeCodeParam, + const QString & deviceIdentifierParam, + const QString & deviceDescriptionParam, + IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oneTimeCode == oneTimeCodeParam); + Q_ASSERT(deviceIdentifier == deviceIdentifierParam); + Q_ASSERT(deviceDescription == deviceDescriptionParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequest, + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::onCompleteTwoFactorAuthenticationRequestReceived); + QObject::connect( + &helper, + &UserStoreCompleteTwoFactorAuthenticationTesterHelper::completeTwoFactorAuthenticationRequestReady, + &server, + &UserStoreServer::onCompleteTwoFactorAuthenticationRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::completeTwoFactorAuthenticationRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->completeTwoFactorAuthenticationAsync( + oneTimeCode, + deviceIdentifier, + deviceDescription, + ctx); + + UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreCompleteTwoFactorAuthenticationAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteRevokeLongSession() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + UserStoreRevokeLongSessionTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequest, + &helper, + &UserStoreRevokeLongSessionTesterHelper::onRevokeLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreRevokeLongSessionTesterHelper::revokeLongSessionRequestReady, + &server, + &UserStoreServer::onRevokeLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + userStore->revokeLongSession( + ctx); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInRevokeLongSession() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DATA_REQUIRED; + userException.parameter = generateRandomString(); + + UserStoreRevokeLongSessionTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequest, + &helper, + &UserStoreRevokeLongSessionTesterHelper::onRevokeLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreRevokeLongSessionTesterHelper::revokeLongSessionRequestReady, + &server, + &UserStoreServer::onRevokeLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->revokeLongSession( + ctx); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInRevokeLongSession() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::TOO_MANY; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreRevokeLongSessionTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequest, + &helper, + &UserStoreRevokeLongSessionTesterHelper::onRevokeLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreRevokeLongSessionTesterHelper::revokeLongSessionRequestReady, + &server, + &UserStoreServer::onRevokeLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->revokeLongSession( + ctx); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInRevokeLongSession() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreRevokeLongSessionTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequest, + &helper, + &UserStoreRevokeLongSessionTesterHelper::onRevokeLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreRevokeLongSessionTesterHelper::revokeLongSessionRequestReady, + &server, + &UserStoreServer::onRevokeLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->revokeLongSession( + ctx); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteRevokeLongSessionAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + UserStoreRevokeLongSessionTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequest, + &helper, + &UserStoreRevokeLongSessionTesterHelper::onRevokeLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreRevokeLongSessionTesterHelper::revokeLongSessionRequestReady, + &server, + &UserStoreServer::onRevokeLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->revokeLongSessionAsync( + ctx); + + UserStoreRevokeLongSessionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreRevokeLongSessionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreRevokeLongSessionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInRevokeLongSessionAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ENML_VALIDATION; + userException.parameter = generateRandomString(); + + UserStoreRevokeLongSessionTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequest, + &helper, + &UserStoreRevokeLongSessionTesterHelper::onRevokeLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreRevokeLongSessionTesterHelper::revokeLongSessionRequestReady, + &server, + &UserStoreServer::onRevokeLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->revokeLongSessionAsync( + ctx); + + UserStoreRevokeLongSessionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreRevokeLongSessionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreRevokeLongSessionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInRevokeLongSessionAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INTERNAL_ERROR; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreRevokeLongSessionTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequest, + &helper, + &UserStoreRevokeLongSessionTesterHelper::onRevokeLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreRevokeLongSessionTesterHelper::revokeLongSessionRequestReady, + &server, + &UserStoreServer::onRevokeLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->revokeLongSessionAsync( + ctx); + + UserStoreRevokeLongSessionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreRevokeLongSessionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreRevokeLongSessionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInRevokeLongSessionAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreRevokeLongSessionTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequest, + &helper, + &UserStoreRevokeLongSessionTesterHelper::onRevokeLongSessionRequestReceived); + QObject::connect( + &helper, + &UserStoreRevokeLongSessionTesterHelper::revokeLongSessionRequestReady, + &server, + &UserStoreServer::onRevokeLongSessionRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::revokeLongSessionRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->revokeLongSessionAsync( + ctx); + + UserStoreRevokeLongSessionAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreRevokeLongSessionAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreRevokeLongSessionAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteAuthenticateToBusiness() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + AuthenticationResult response = generateRandomAuthenticationResult(); + + UserStoreAuthenticateToBusinessTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequest, + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::onAuthenticateToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::authenticateToBusinessRequestReady, + &server, + &UserStoreServer::onAuthenticateToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AuthenticationResult res = userStore->authenticateToBusiness( + ctx); + QVERIFY(res == response); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInAuthenticateToBusiness() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LIMIT_REACHED; + userException.parameter = generateRandomString(); + + UserStoreAuthenticateToBusinessTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequest, + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::onAuthenticateToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::authenticateToBusinessRequestReady, + &server, + &UserStoreServer::onAuthenticateToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = userStore->authenticateToBusiness( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInAuthenticateToBusiness() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::UNKNOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreAuthenticateToBusinessTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequest, + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::onAuthenticateToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::authenticateToBusinessRequestReady, + &server, + &UserStoreServer::onAuthenticateToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = userStore->authenticateToBusiness( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInAuthenticateToBusiness() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreAuthenticateToBusinessTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequest, + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::onAuthenticateToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::authenticateToBusinessRequestReady, + &server, + &UserStoreServer::onAuthenticateToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AuthenticationResult res = userStore->authenticateToBusiness( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteAuthenticateToBusinessAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + AuthenticationResult response = generateRandomAuthenticationResult(); + + UserStoreAuthenticateToBusinessTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequest, + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::onAuthenticateToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::authenticateToBusinessRequestReady, + &server, + &UserStoreServer::onAuthenticateToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->authenticateToBusinessAsync( + ctx); + + UserStoreAuthenticateToBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreAuthenticateToBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreAuthenticateToBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInAuthenticateToBusinessAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_MANY; + userException.parameter = generateRandomString(); + + UserStoreAuthenticateToBusinessTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequest, + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::onAuthenticateToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::authenticateToBusinessRequestReady, + &server, + &UserStoreServer::onAuthenticateToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->authenticateToBusinessAsync( + ctx); + + UserStoreAuthenticateToBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreAuthenticateToBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreAuthenticateToBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInAuthenticateToBusinessAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreAuthenticateToBusinessTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequest, + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::onAuthenticateToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::authenticateToBusinessRequestReady, + &server, + &UserStoreServer::onAuthenticateToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->authenticateToBusinessAsync( + ctx); + + UserStoreAuthenticateToBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreAuthenticateToBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreAuthenticateToBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInAuthenticateToBusinessAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreAuthenticateToBusinessTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> AuthenticationResult + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequest, + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::onAuthenticateToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreAuthenticateToBusinessTesterHelper::authenticateToBusinessRequestReady, + &server, + &UserStoreServer::onAuthenticateToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::authenticateToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->authenticateToBusinessAsync( + ctx); + + UserStoreAuthenticateToBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreAuthenticateToBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreAuthenticateToBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteGetUser() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + User response = generateRandomUser(); + + UserStoreGetUserTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> User + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserRequest, + &helper, + &UserStoreGetUserTesterHelper::onGetUserRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserTesterHelper::getUserRequestReady, + &server, + &UserStoreServer::onGetUserRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + User res = userStore->getUser( + ctx); + QVERIFY(res == response); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInGetUser() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + userException.parameter = generateRandomString(); + + UserStoreGetUserTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> User + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserRequest, + &helper, + &UserStoreGetUserTesterHelper::onGetUserRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserTesterHelper::getUserRequestReady, + &server, + &UserStoreServer::onGetUserRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + User res = userStore->getUser( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInGetUser() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DATA_CONFLICT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreGetUserTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> User + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserRequest, + &helper, + &UserStoreGetUserTesterHelper::onGetUserRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserTesterHelper::getUserRequestReady, + &server, + &UserStoreServer::onGetUserRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + User res = userStore->getUser( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInGetUser() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreGetUserTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> User + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserRequest, + &helper, + &UserStoreGetUserTesterHelper::onGetUserRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserTesterHelper::getUserRequestReady, + &server, + &UserStoreServer::onGetUserRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + User res = userStore->getUser( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteGetUserAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + User response = generateRandomUser(); + + UserStoreGetUserTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> User + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserRequest, + &helper, + &UserStoreGetUserTesterHelper::onGetUserRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserTesterHelper::getUserRequestReady, + &server, + &UserStoreServer::onGetUserRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->getUserAsync( + ctx); + + UserStoreGetUserAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetUserAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetUserAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInGetUserAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::RATE_LIMIT_REACHED; + userException.parameter = generateRandomString(); + + UserStoreGetUserTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> User + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserRequest, + &helper, + &UserStoreGetUserTesterHelper::onGetUserRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserTesterHelper::getUserRequestReady, + &server, + &UserStoreServer::onGetUserRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getUserAsync( + ctx); + + UserStoreGetUserAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetUserAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetUserAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInGetUserAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DATA_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreGetUserTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> User + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserRequest, + &helper, + &UserStoreGetUserTesterHelper::onGetUserRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserTesterHelper::getUserRequestReady, + &server, + &UserStoreServer::onGetUserRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getUserAsync( + ctx); + + UserStoreGetUserAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetUserAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetUserAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInGetUserAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreGetUserTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> User + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserRequest, + &helper, + &UserStoreGetUserTesterHelper::onGetUserRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserTesterHelper::getUserRequestReady, + &server, + &UserStoreServer::onGetUserRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getUserAsync( + ctx); + + UserStoreGetUserAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetUserAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetUserAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteGetPublicUserInfo() +{ + QString username = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + PublicUserInfo response = generateRandomPublicUserInfo(); + + UserStoreGetPublicUserInfoTesterHelper helper( + [&] (const QString & usernameParam, + IRequestContextPtr ctxParam) -> PublicUserInfo + { + Q_ASSERT(username == usernameParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequest, + &helper, + &UserStoreGetPublicUserInfoTesterHelper::onGetPublicUserInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetPublicUserInfoTesterHelper::getPublicUserInfoRequestReady, + &server, + &UserStoreServer::onGetPublicUserInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + PublicUserInfo res = userStore->getPublicUserInfo( + username, + ctx); + QVERIFY(res == response); +} + +void UserStoreTester::shouldDeliverEDAMNotFoundExceptionInGetPublicUserInfo() +{ + QString username = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + UserStoreGetPublicUserInfoTesterHelper helper( + [&] (const QString & usernameParam, + IRequestContextPtr ctxParam) -> PublicUserInfo + { + Q_ASSERT(username == usernameParam); + throw notFoundException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequest, + &helper, + &UserStoreGetPublicUserInfoTesterHelper::onGetPublicUserInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetPublicUserInfoTesterHelper::getPublicUserInfoRequestReady, + &server, + &UserStoreServer::onGetPublicUserInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + PublicUserInfo res = userStore->getPublicUserInfo( + username, + ctx); + Q_UNUSED(res) + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInGetPublicUserInfo() +{ + QString username = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreGetPublicUserInfoTesterHelper helper( + [&] (const QString & usernameParam, + IRequestContextPtr ctxParam) -> PublicUserInfo + { + Q_ASSERT(username == usernameParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequest, + &helper, + &UserStoreGetPublicUserInfoTesterHelper::onGetPublicUserInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetPublicUserInfoTesterHelper::getPublicUserInfoRequestReady, + &server, + &UserStoreServer::onGetPublicUserInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + PublicUserInfo res = userStore->getPublicUserInfo( + username, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInGetPublicUserInfo() +{ + QString username = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::RATE_LIMIT_REACHED; + userException.parameter = generateRandomString(); + + UserStoreGetPublicUserInfoTesterHelper helper( + [&] (const QString & usernameParam, + IRequestContextPtr ctxParam) -> PublicUserInfo + { + Q_ASSERT(username == usernameParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequest, + &helper, + &UserStoreGetPublicUserInfoTesterHelper::onGetPublicUserInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetPublicUserInfoTesterHelper::getPublicUserInfoRequestReady, + &server, + &UserStoreServer::onGetPublicUserInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + PublicUserInfo res = userStore->getPublicUserInfo( + username, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInGetPublicUserInfo() +{ + QString username = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreGetPublicUserInfoTesterHelper helper( + [&] (const QString & usernameParam, + IRequestContextPtr ctxParam) -> PublicUserInfo + { + Q_ASSERT(username == usernameParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequest, + &helper, + &UserStoreGetPublicUserInfoTesterHelper::onGetPublicUserInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetPublicUserInfoTesterHelper::getPublicUserInfoRequestReady, + &server, + &UserStoreServer::onGetPublicUserInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + PublicUserInfo res = userStore->getPublicUserInfo( + username, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteGetPublicUserInfoAsync() +{ + QString username = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + PublicUserInfo response = generateRandomPublicUserInfo(); + + UserStoreGetPublicUserInfoTesterHelper helper( + [&] (const QString & usernameParam, + IRequestContextPtr ctxParam) -> PublicUserInfo + { + Q_ASSERT(username == usernameParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequest, + &helper, + &UserStoreGetPublicUserInfoTesterHelper::onGetPublicUserInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetPublicUserInfoTesterHelper::getPublicUserInfoRequestReady, + &server, + &UserStoreServer::onGetPublicUserInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->getPublicUserInfoAsync( + username, + ctx); + + UserStoreGetPublicUserInfoAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetPublicUserInfoAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetPublicUserInfoAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMNotFoundExceptionInGetPublicUserInfoAsync() +{ + QString username = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + UserStoreGetPublicUserInfoTesterHelper helper( + [&] (const QString & usernameParam, + IRequestContextPtr ctxParam) -> PublicUserInfo + { + Q_ASSERT(username == usernameParam); + throw notFoundException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequest, + &helper, + &UserStoreGetPublicUserInfoTesterHelper::onGetPublicUserInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetPublicUserInfoTesterHelper::getPublicUserInfoRequestReady, + &server, + &UserStoreServer::onGetPublicUserInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getPublicUserInfoAsync( + username, + ctx); + + UserStoreGetPublicUserInfoAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetPublicUserInfoAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetPublicUserInfoAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInGetPublicUserInfoAsync() +{ + QString username = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::RATE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreGetPublicUserInfoTesterHelper helper( + [&] (const QString & usernameParam, + IRequestContextPtr ctxParam) -> PublicUserInfo + { + Q_ASSERT(username == usernameParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequest, + &helper, + &UserStoreGetPublicUserInfoTesterHelper::onGetPublicUserInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetPublicUserInfoTesterHelper::getPublicUserInfoRequestReady, + &server, + &UserStoreServer::onGetPublicUserInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getPublicUserInfoAsync( + username, + ctx); + + UserStoreGetPublicUserInfoAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetPublicUserInfoAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetPublicUserInfoAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInGetPublicUserInfoAsync() +{ + QString username = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::SHARD_UNAVAILABLE; + userException.parameter = generateRandomString(); + + UserStoreGetPublicUserInfoTesterHelper helper( + [&] (const QString & usernameParam, + IRequestContextPtr ctxParam) -> PublicUserInfo + { + Q_ASSERT(username == usernameParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequest, + &helper, + &UserStoreGetPublicUserInfoTesterHelper::onGetPublicUserInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetPublicUserInfoTesterHelper::getPublicUserInfoRequestReady, + &server, + &UserStoreServer::onGetPublicUserInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getPublicUserInfoAsync( + username, + ctx); + + UserStoreGetPublicUserInfoAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetPublicUserInfoAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetPublicUserInfoAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInGetPublicUserInfoAsync() +{ + QString username = generateRandomString(); + IRequestContextPtr ctx = newRequestContext(); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreGetPublicUserInfoTesterHelper helper( + [&] (const QString & usernameParam, + IRequestContextPtr ctxParam) -> PublicUserInfo + { + Q_ASSERT(username == usernameParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequest, + &helper, + &UserStoreGetPublicUserInfoTesterHelper::onGetPublicUserInfoRequestReceived); + QObject::connect( + &helper, + &UserStoreGetPublicUserInfoTesterHelper::getPublicUserInfoRequestReady, + &server, + &UserStoreServer::onGetPublicUserInfoRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getPublicUserInfoRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getPublicUserInfoAsync( + username, + ctx); + + UserStoreGetPublicUserInfoAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetPublicUserInfoAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetPublicUserInfoAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteGetUserUrls() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + UserUrls response = generateRandomUserUrls(); + + UserStoreGetUserUrlsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> UserUrls + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequest, + &helper, + &UserStoreGetUserUrlsTesterHelper::onGetUserUrlsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserUrlsTesterHelper::getUserUrlsRequestReady, + &server, + &UserStoreServer::onGetUserUrlsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + UserUrls res = userStore->getUserUrls( + ctx); + QVERIFY(res == response); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInGetUserUrls() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNKNOWN; + userException.parameter = generateRandomString(); + + UserStoreGetUserUrlsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> UserUrls + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequest, + &helper, + &UserStoreGetUserUrlsTesterHelper::onGetUserUrlsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserUrlsTesterHelper::getUserUrlsRequestReady, + &server, + &UserStoreServer::onGetUserUrlsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + UserUrls res = userStore->getUserUrls( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInGetUserUrls() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LEN_TOO_LONG; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreGetUserUrlsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> UserUrls + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequest, + &helper, + &UserStoreGetUserUrlsTesterHelper::onGetUserUrlsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserUrlsTesterHelper::getUserUrlsRequestReady, + &server, + &UserStoreServer::onGetUserUrlsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + UserUrls res = userStore->getUserUrls( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInGetUserUrls() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreGetUserUrlsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> UserUrls + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequest, + &helper, + &UserStoreGetUserUrlsTesterHelper::onGetUserUrlsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserUrlsTesterHelper::getUserUrlsRequestReady, + &server, + &UserStoreServer::onGetUserUrlsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + UserUrls res = userStore->getUserUrls( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteGetUserUrlsAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + UserUrls response = generateRandomUserUrls(); + + UserStoreGetUserUrlsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> UserUrls + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequest, + &helper, + &UserStoreGetUserUrlsTesterHelper::onGetUserUrlsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserUrlsTesterHelper::getUserUrlsRequestReady, + &server, + &UserStoreServer::onGetUserUrlsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->getUserUrlsAsync( + ctx); + + UserStoreGetUserUrlsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetUserUrlsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetUserUrlsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInGetUserUrlsAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + userException.parameter = generateRandomString(); + + UserStoreGetUserUrlsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> UserUrls + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequest, + &helper, + &UserStoreGetUserUrlsTesterHelper::onGetUserUrlsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserUrlsTesterHelper::getUserUrlsRequestReady, + &server, + &UserStoreServer::onGetUserUrlsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getUserUrlsAsync( + ctx); + + UserStoreGetUserUrlsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetUserUrlsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetUserUrlsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInGetUserUrlsAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreGetUserUrlsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> UserUrls + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequest, + &helper, + &UserStoreGetUserUrlsTesterHelper::onGetUserUrlsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserUrlsTesterHelper::getUserUrlsRequestReady, + &server, + &UserStoreServer::onGetUserUrlsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getUserUrlsAsync( + ctx); + + UserStoreGetUserUrlsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetUserUrlsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetUserUrlsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInGetUserUrlsAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreGetUserUrlsTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> UserUrls + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequest, + &helper, + &UserStoreGetUserUrlsTesterHelper::onGetUserUrlsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetUserUrlsTesterHelper::getUserUrlsRequestReady, + &server, + &UserStoreServer::onGetUserUrlsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getUserUrlsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getUserUrlsAsync( + ctx); + + UserStoreGetUserUrlsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetUserUrlsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetUserUrlsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteInviteToBusiness() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + UserStoreInviteToBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + return; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequest, + &helper, + &UserStoreInviteToBusinessTesterHelper::onInviteToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreInviteToBusinessTesterHelper::inviteToBusinessRequestReady, + &server, + &UserStoreServer::onInviteToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + userStore->inviteToBusiness( + emailAddress, + ctx); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInInviteToBusiness() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TAKEN_DOWN; + userException.parameter = generateRandomString(); + + UserStoreInviteToBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequest, + &helper, + &UserStoreInviteToBusinessTesterHelper::onInviteToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreInviteToBusinessTesterHelper::inviteToBusinessRequestReady, + &server, + &UserStoreServer::onInviteToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->inviteToBusiness( + emailAddress, + ctx); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInInviteToBusiness() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreInviteToBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequest, + &helper, + &UserStoreInviteToBusinessTesterHelper::onInviteToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreInviteToBusinessTesterHelper::inviteToBusinessRequestReady, + &server, + &UserStoreServer::onInviteToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->inviteToBusiness( + emailAddress, + ctx); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInInviteToBusiness() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreInviteToBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequest, + &helper, + &UserStoreInviteToBusinessTesterHelper::onInviteToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreInviteToBusinessTesterHelper::inviteToBusinessRequestReady, + &server, + &UserStoreServer::onInviteToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->inviteToBusiness( + emailAddress, + ctx); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteInviteToBusinessAsync() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + UserStoreInviteToBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + return; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequest, + &helper, + &UserStoreInviteToBusinessTesterHelper::onInviteToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreInviteToBusinessTesterHelper::inviteToBusinessRequestReady, + &server, + &UserStoreServer::onInviteToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->inviteToBusinessAsync( + emailAddress, + ctx); + + UserStoreInviteToBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreInviteToBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreInviteToBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInInviteToBusinessAsync() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_FEW; + userException.parameter = generateRandomString(); + + UserStoreInviteToBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequest, + &helper, + &UserStoreInviteToBusinessTesterHelper::onInviteToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreInviteToBusinessTesterHelper::inviteToBusinessRequestReady, + &server, + &UserStoreServer::onInviteToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->inviteToBusinessAsync( + emailAddress, + ctx); + + UserStoreInviteToBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreInviteToBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreInviteToBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInInviteToBusinessAsync() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreInviteToBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequest, + &helper, + &UserStoreInviteToBusinessTesterHelper::onInviteToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreInviteToBusinessTesterHelper::inviteToBusinessRequestReady, + &server, + &UserStoreServer::onInviteToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->inviteToBusinessAsync( + emailAddress, + ctx); + + UserStoreInviteToBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreInviteToBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreInviteToBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInInviteToBusinessAsync() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreInviteToBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequest, + &helper, + &UserStoreInviteToBusinessTesterHelper::onInviteToBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreInviteToBusinessTesterHelper::inviteToBusinessRequestReady, + &server, + &UserStoreServer::onInviteToBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::inviteToBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->inviteToBusinessAsync( + emailAddress, + ctx); + + UserStoreInviteToBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreInviteToBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreInviteToBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteRemoveFromBusiness() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + UserStoreRemoveFromBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + return; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequest, + &helper, + &UserStoreRemoveFromBusinessTesterHelper::onRemoveFromBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreRemoveFromBusinessTesterHelper::removeFromBusinessRequestReady, + &server, + &UserStoreServer::onRemoveFromBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + userStore->removeFromBusiness( + emailAddress, + ctx); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInRemoveFromBusiness() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LIMIT_REACHED; + userException.parameter = generateRandomString(); + + UserStoreRemoveFromBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequest, + &helper, + &UserStoreRemoveFromBusinessTesterHelper::onRemoveFromBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreRemoveFromBusinessTesterHelper::removeFromBusinessRequestReady, + &server, + &UserStoreServer::onRemoveFromBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->removeFromBusiness( + emailAddress, + ctx); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInRemoveFromBusiness() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::USER_ALREADY_ASSOCIATED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreRemoveFromBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequest, + &helper, + &UserStoreRemoveFromBusinessTesterHelper::onRemoveFromBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreRemoveFromBusinessTesterHelper::removeFromBusinessRequestReady, + &server, + &UserStoreServer::onRemoveFromBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->removeFromBusiness( + emailAddress, + ctx); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMNotFoundExceptionInRemoveFromBusiness() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + UserStoreRemoveFromBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw notFoundException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequest, + &helper, + &UserStoreRemoveFromBusinessTesterHelper::onRemoveFromBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreRemoveFromBusinessTesterHelper::removeFromBusinessRequestReady, + &server, + &UserStoreServer::onRemoveFromBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->removeFromBusiness( + emailAddress, + ctx); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInRemoveFromBusiness() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreRemoveFromBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequest, + &helper, + &UserStoreRemoveFromBusinessTesterHelper::onRemoveFromBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreRemoveFromBusinessTesterHelper::removeFromBusinessRequestReady, + &server, + &UserStoreServer::onRemoveFromBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->removeFromBusiness( + emailAddress, + ctx); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteRemoveFromBusinessAsync() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + UserStoreRemoveFromBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + return; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequest, + &helper, + &UserStoreRemoveFromBusinessTesterHelper::onRemoveFromBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreRemoveFromBusinessTesterHelper::removeFromBusinessRequestReady, + &server, + &UserStoreServer::onRemoveFromBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->removeFromBusinessAsync( + emailAddress, + ctx); + + UserStoreRemoveFromBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreRemoveFromBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreRemoveFromBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInRemoveFromBusinessAsync() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::ENML_VALIDATION; + userException.parameter = generateRandomString(); + + UserStoreRemoveFromBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequest, + &helper, + &UserStoreRemoveFromBusinessTesterHelper::onRemoveFromBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreRemoveFromBusinessTesterHelper::removeFromBusinessRequestReady, + &server, + &UserStoreServer::onRemoveFromBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->removeFromBusinessAsync( + emailAddress, + ctx); + + UserStoreRemoveFromBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreRemoveFromBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreRemoveFromBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInRemoveFromBusinessAsync() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LIMIT_REACHED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreRemoveFromBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequest, + &helper, + &UserStoreRemoveFromBusinessTesterHelper::onRemoveFromBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreRemoveFromBusinessTesterHelper::removeFromBusinessRequestReady, + &server, + &UserStoreServer::onRemoveFromBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->removeFromBusinessAsync( + emailAddress, + ctx); + + UserStoreRemoveFromBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreRemoveFromBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreRemoveFromBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMNotFoundExceptionInRemoveFromBusinessAsync() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + UserStoreRemoveFromBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw notFoundException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequest, + &helper, + &UserStoreRemoveFromBusinessTesterHelper::onRemoveFromBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreRemoveFromBusinessTesterHelper::removeFromBusinessRequestReady, + &server, + &UserStoreServer::onRemoveFromBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->removeFromBusinessAsync( + emailAddress, + ctx); + + UserStoreRemoveFromBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreRemoveFromBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreRemoveFromBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInRemoveFromBusinessAsync() +{ + QString emailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreRemoveFromBusinessTesterHelper helper( + [&] (const QString & emailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(emailAddress == emailAddressParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequest, + &helper, + &UserStoreRemoveFromBusinessTesterHelper::onRemoveFromBusinessRequestReceived); + QObject::connect( + &helper, + &UserStoreRemoveFromBusinessTesterHelper::removeFromBusinessRequestReady, + &server, + &UserStoreServer::onRemoveFromBusinessRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::removeFromBusinessRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->removeFromBusinessAsync( + emailAddress, + ctx); + + UserStoreRemoveFromBusinessAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreRemoveFromBusinessAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreRemoveFromBusinessAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteUpdateBusinessUserIdentifier() +{ + QString oldEmailAddress = generateRandomString(); + QString newEmailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + UserStoreUpdateBusinessUserIdentifierTesterHelper helper( + [&] (const QString & oldEmailAddressParam, + const QString & newEmailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oldEmailAddress == oldEmailAddressParam); + Q_ASSERT(newEmailAddress == newEmailAddressParam); + return; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequest, + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::onUpdateBusinessUserIdentifierRequestReceived); + QObject::connect( + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::updateBusinessUserIdentifierRequestReady, + &server, + &UserStoreServer::onUpdateBusinessUserIdentifierRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + userStore->updateBusinessUserIdentifier( + oldEmailAddress, + newEmailAddress, + ctx); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInUpdateBusinessUserIdentifier() +{ + QString oldEmailAddress = generateRandomString(); + QString newEmailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::LEN_TOO_SHORT; + userException.parameter = generateRandomString(); + + UserStoreUpdateBusinessUserIdentifierTesterHelper helper( + [&] (const QString & oldEmailAddressParam, + const QString & newEmailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oldEmailAddress == oldEmailAddressParam); + Q_ASSERT(newEmailAddress == newEmailAddressParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequest, + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::onUpdateBusinessUserIdentifierRequestReceived); + QObject::connect( + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::updateBusinessUserIdentifierRequestReady, + &server, + &UserStoreServer::onUpdateBusinessUserIdentifierRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->updateBusinessUserIdentifier( + oldEmailAddress, + newEmailAddress, + ctx); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInUpdateBusinessUserIdentifier() +{ + QString oldEmailAddress = generateRandomString(); + QString newEmailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::INVALID_AUTH; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreUpdateBusinessUserIdentifierTesterHelper helper( + [&] (const QString & oldEmailAddressParam, + const QString & newEmailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oldEmailAddress == oldEmailAddressParam); + Q_ASSERT(newEmailAddress == newEmailAddressParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequest, + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::onUpdateBusinessUserIdentifierRequestReceived); + QObject::connect( + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::updateBusinessUserIdentifierRequestReady, + &server, + &UserStoreServer::onUpdateBusinessUserIdentifierRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->updateBusinessUserIdentifier( + oldEmailAddress, + newEmailAddress, + ctx); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateBusinessUserIdentifier() +{ + QString oldEmailAddress = generateRandomString(); + QString newEmailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + UserStoreUpdateBusinessUserIdentifierTesterHelper helper( + [&] (const QString & oldEmailAddressParam, + const QString & newEmailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oldEmailAddress == oldEmailAddressParam); + Q_ASSERT(newEmailAddress == newEmailAddressParam); + throw notFoundException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequest, + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::onUpdateBusinessUserIdentifierRequestReceived); + QObject::connect( + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::updateBusinessUserIdentifierRequestReady, + &server, + &UserStoreServer::onUpdateBusinessUserIdentifierRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->updateBusinessUserIdentifier( + oldEmailAddress, + newEmailAddress, + ctx); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInUpdateBusinessUserIdentifier() +{ + QString oldEmailAddress = generateRandomString(); + QString newEmailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreUpdateBusinessUserIdentifierTesterHelper helper( + [&] (const QString & oldEmailAddressParam, + const QString & newEmailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oldEmailAddress == oldEmailAddressParam); + Q_ASSERT(newEmailAddress == newEmailAddressParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequest, + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::onUpdateBusinessUserIdentifierRequestReceived); + QObject::connect( + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::updateBusinessUserIdentifierRequestReady, + &server, + &UserStoreServer::onUpdateBusinessUserIdentifierRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + userStore->updateBusinessUserIdentifier( + oldEmailAddress, + newEmailAddress, + ctx); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteUpdateBusinessUserIdentifierAsync() +{ + QString oldEmailAddress = generateRandomString(); + QString newEmailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + UserStoreUpdateBusinessUserIdentifierTesterHelper helper( + [&] (const QString & oldEmailAddressParam, + const QString & newEmailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oldEmailAddress == oldEmailAddressParam); + Q_ASSERT(newEmailAddress == newEmailAddressParam); + return; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequest, + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::onUpdateBusinessUserIdentifierRequestReceived); + QObject::connect( + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::updateBusinessUserIdentifierRequestReady, + &server, + &UserStoreServer::onUpdateBusinessUserIdentifierRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->updateBusinessUserIdentifierAsync( + oldEmailAddress, + newEmailAddress, + ctx); + + UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInUpdateBusinessUserIdentifierAsync() +{ + QString oldEmailAddress = generateRandomString(); + QString newEmailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::DEVICE_LIMIT_REACHED; + userException.parameter = generateRandomString(); + + UserStoreUpdateBusinessUserIdentifierTesterHelper helper( + [&] (const QString & oldEmailAddressParam, + const QString & newEmailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oldEmailAddress == oldEmailAddressParam); + Q_ASSERT(newEmailAddress == newEmailAddressParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequest, + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::onUpdateBusinessUserIdentifierRequestReceived); + QObject::connect( + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::updateBusinessUserIdentifierRequestReady, + &server, + &UserStoreServer::onUpdateBusinessUserIdentifierRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->updateBusinessUserIdentifierAsync( + oldEmailAddress, + newEmailAddress, + ctx); + + UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInUpdateBusinessUserIdentifierAsync() +{ + QString oldEmailAddress = generateRandomString(); + QString newEmailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::UNKNOWN; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreUpdateBusinessUserIdentifierTesterHelper helper( + [&] (const QString & oldEmailAddressParam, + const QString & newEmailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oldEmailAddress == oldEmailAddressParam); + Q_ASSERT(newEmailAddress == newEmailAddressParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequest, + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::onUpdateBusinessUserIdentifierRequestReceived); + QObject::connect( + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::updateBusinessUserIdentifierRequestReady, + &server, + &UserStoreServer::onUpdateBusinessUserIdentifierRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->updateBusinessUserIdentifierAsync( + oldEmailAddress, + newEmailAddress, + ctx); + + UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMNotFoundExceptionInUpdateBusinessUserIdentifierAsync() +{ + QString oldEmailAddress = generateRandomString(); + QString newEmailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto notFoundException = EDAMNotFoundException(); + notFoundException.identifier = generateRandomString(); + notFoundException.key = generateRandomString(); + + UserStoreUpdateBusinessUserIdentifierTesterHelper helper( + [&] (const QString & oldEmailAddressParam, + const QString & newEmailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oldEmailAddress == oldEmailAddressParam); + Q_ASSERT(newEmailAddress == newEmailAddressParam); + throw notFoundException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequest, + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::onUpdateBusinessUserIdentifierRequestReceived); + QObject::connect( + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::updateBusinessUserIdentifierRequestReady, + &server, + &UserStoreServer::onUpdateBusinessUserIdentifierRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->updateBusinessUserIdentifierAsync( + oldEmailAddress, + newEmailAddress, + ctx); + + UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMNotFoundException & e) + { + caughtException = true; + QVERIFY(e == notFoundException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInUpdateBusinessUserIdentifierAsync() +{ + QString oldEmailAddress = generateRandomString(); + QString newEmailAddress = generateRandomString(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreUpdateBusinessUserIdentifierTesterHelper helper( + [&] (const QString & oldEmailAddressParam, + const QString & newEmailAddressParam, + IRequestContextPtr ctxParam) -> void + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(oldEmailAddress == oldEmailAddressParam); + Q_ASSERT(newEmailAddress == newEmailAddressParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequest, + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::onUpdateBusinessUserIdentifierRequestReceived); + QObject::connect( + &helper, + &UserStoreUpdateBusinessUserIdentifierTesterHelper::updateBusinessUserIdentifierRequestReady, + &server, + &UserStoreServer::onUpdateBusinessUserIdentifierRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::updateBusinessUserIdentifierRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->updateBusinessUserIdentifierAsync( + oldEmailAddress, + newEmailAddress, + ctx); + + UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreUpdateBusinessUserIdentifierAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteListBusinessUsers() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomUserProfile(); + response << generateRandomUserProfile(); + response << generateRandomUserProfile(); + + UserStoreListBusinessUsersTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequest, + &helper, + &UserStoreListBusinessUsersTesterHelper::onListBusinessUsersRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessUsersTesterHelper::listBusinessUsersRequestReady, + &server, + &UserStoreServer::onListBusinessUsersRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QList res = userStore->listBusinessUsers( + ctx); + QVERIFY(res == response); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInListBusinessUsers() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INVALID_OPENID_TOKEN; + userException.parameter = generateRandomString(); + + UserStoreListBusinessUsersTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequest, + &helper, + &UserStoreListBusinessUsersTesterHelper::onListBusinessUsersRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessUsersTesterHelper::listBusinessUsersRequestReady, + &server, + &UserStoreServer::onListBusinessUsersRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = userStore->listBusinessUsers( + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInListBusinessUsers() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::PERMISSION_DENIED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreListBusinessUsersTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequest, + &helper, + &UserStoreListBusinessUsersTesterHelper::onListBusinessUsersRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessUsersTesterHelper::listBusinessUsersRequestReady, + &server, + &UserStoreServer::onListBusinessUsersRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = userStore->listBusinessUsers( + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInListBusinessUsers() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreListBusinessUsersTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequest, + &helper, + &UserStoreListBusinessUsersTesterHelper::onListBusinessUsersRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessUsersTesterHelper::listBusinessUsersRequestReady, + &server, + &UserStoreServer::onListBusinessUsersRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = userStore->listBusinessUsers( + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteListBusinessUsersAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomUserProfile(); + response << generateRandomUserProfile(); + response << generateRandomUserProfile(); + + UserStoreListBusinessUsersTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequest, + &helper, + &UserStoreListBusinessUsersTesterHelper::onListBusinessUsersRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessUsersTesterHelper::listBusinessUsersRequestReady, + &server, + &UserStoreServer::onListBusinessUsersRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->listBusinessUsersAsync( + ctx); + + UserStoreListBusinessUsersAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreListBusinessUsersAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreListBusinessUsersAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInListBusinessUsersAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::INTERNAL_ERROR; + userException.parameter = generateRandomString(); + + UserStoreListBusinessUsersTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequest, + &helper, + &UserStoreListBusinessUsersTesterHelper::onListBusinessUsersRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessUsersTesterHelper::listBusinessUsersRequestReady, + &server, + &UserStoreServer::onListBusinessUsersRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->listBusinessUsersAsync( + ctx); + + UserStoreListBusinessUsersAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreListBusinessUsersAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreListBusinessUsersAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInListBusinessUsersAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::SSO_AUTHENTICATION_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreListBusinessUsersTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequest, + &helper, + &UserStoreListBusinessUsersTesterHelper::onListBusinessUsersRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessUsersTesterHelper::listBusinessUsersRequestReady, + &server, + &UserStoreServer::onListBusinessUsersRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->listBusinessUsersAsync( + ctx); + + UserStoreListBusinessUsersAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreListBusinessUsersAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreListBusinessUsersAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInListBusinessUsersAsync() +{ + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreListBusinessUsersTesterHelper helper( + [&] (IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequest, + &helper, + &UserStoreListBusinessUsersTesterHelper::onListBusinessUsersRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessUsersTesterHelper::listBusinessUsersRequestReady, + &server, + &UserStoreServer::onListBusinessUsersRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessUsersRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->listBusinessUsersAsync( + ctx); + + UserStoreListBusinessUsersAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreListBusinessUsersAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreListBusinessUsersAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteListBusinessInvitations() +{ + bool includeRequestedInvitations = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomBusinessInvitation(); + response << generateRandomBusinessInvitation(); + response << generateRandomBusinessInvitation(); + + UserStoreListBusinessInvitationsTesterHelper helper( + [&] (bool includeRequestedInvitationsParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(includeRequestedInvitations == includeRequestedInvitationsParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequest, + &helper, + &UserStoreListBusinessInvitationsTesterHelper::onListBusinessInvitationsRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessInvitationsTesterHelper::listBusinessInvitationsRequestReady, + &server, + &UserStoreServer::onListBusinessInvitationsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + QList res = userStore->listBusinessInvitations( + includeRequestedInvitations, + ctx); + QVERIFY(res == response); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInListBusinessInvitations() +{ + bool includeRequestedInvitations = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::TOO_FEW; + userException.parameter = generateRandomString(); + + UserStoreListBusinessInvitationsTesterHelper helper( + [&] (bool includeRequestedInvitationsParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(includeRequestedInvitations == includeRequestedInvitationsParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequest, + &helper, + &UserStoreListBusinessInvitationsTesterHelper::onListBusinessInvitationsRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessInvitationsTesterHelper::listBusinessInvitationsRequestReady, + &server, + &UserStoreServer::onListBusinessInvitationsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = userStore->listBusinessInvitations( + includeRequestedInvitations, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInListBusinessInvitations() +{ + bool includeRequestedInvitations = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreListBusinessInvitationsTesterHelper helper( + [&] (bool includeRequestedInvitationsParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(includeRequestedInvitations == includeRequestedInvitationsParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequest, + &helper, + &UserStoreListBusinessInvitationsTesterHelper::onListBusinessInvitationsRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessInvitationsTesterHelper::listBusinessInvitationsRequestReady, + &server, + &UserStoreServer::onListBusinessInvitationsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = userStore->listBusinessInvitations( + includeRequestedInvitations, + ctx); + Q_UNUSED(res) + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInListBusinessInvitations() +{ + bool includeRequestedInvitations = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreListBusinessInvitationsTesterHelper helper( + [&] (bool includeRequestedInvitationsParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(includeRequestedInvitations == includeRequestedInvitationsParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequest, + &helper, + &UserStoreListBusinessInvitationsTesterHelper::onListBusinessInvitationsRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessInvitationsTesterHelper::listBusinessInvitationsRequestReady, + &server, + &UserStoreServer::onListBusinessInvitationsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + QList res = userStore->listBusinessInvitations( + includeRequestedInvitations, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteListBusinessInvitationsAsync() +{ + bool includeRequestedInvitations = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + QList response; + response << generateRandomBusinessInvitation(); + response << generateRandomBusinessInvitation(); + response << generateRandomBusinessInvitation(); + + UserStoreListBusinessInvitationsTesterHelper helper( + [&] (bool includeRequestedInvitationsParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(includeRequestedInvitations == includeRequestedInvitationsParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequest, + &helper, + &UserStoreListBusinessInvitationsTesterHelper::onListBusinessInvitationsRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessInvitationsTesterHelper::listBusinessInvitationsRequestReady, + &server, + &UserStoreServer::onListBusinessInvitationsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->listBusinessInvitationsAsync( + includeRequestedInvitations, + ctx); + + UserStoreListBusinessInvitationsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreListBusinessInvitationsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreListBusinessInvitationsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInListBusinessInvitationsAsync() +{ + bool includeRequestedInvitations = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::BUSINESS_SECURITY_LOGIN_REQUIRED; + userException.parameter = generateRandomString(); + + UserStoreListBusinessInvitationsTesterHelper helper( + [&] (bool includeRequestedInvitationsParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(includeRequestedInvitations == includeRequestedInvitationsParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequest, + &helper, + &UserStoreListBusinessInvitationsTesterHelper::onListBusinessInvitationsRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessInvitationsTesterHelper::listBusinessInvitationsRequestReady, + &server, + &UserStoreServer::onListBusinessInvitationsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->listBusinessInvitationsAsync( + includeRequestedInvitations, + ctx); + + UserStoreListBusinessInvitationsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreListBusinessInvitationsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreListBusinessInvitationsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverEDAMSystemExceptionInListBusinessInvitationsAsync() +{ + bool includeRequestedInvitations = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto systemException = EDAMSystemException(); + systemException.errorCode = EDAMErrorCode::LEN_TOO_SHORT; + systemException.message = generateRandomString(); + systemException.rateLimitDuration = generateRandomInt32(); + + UserStoreListBusinessInvitationsTesterHelper helper( + [&] (bool includeRequestedInvitationsParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(includeRequestedInvitations == includeRequestedInvitationsParam); + throw systemException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequest, + &helper, + &UserStoreListBusinessInvitationsTesterHelper::onListBusinessInvitationsRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessInvitationsTesterHelper::listBusinessInvitationsRequestReady, + &server, + &UserStoreServer::onListBusinessInvitationsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->listBusinessInvitationsAsync( + includeRequestedInvitations, + ctx); + + UserStoreListBusinessInvitationsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreListBusinessInvitationsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreListBusinessInvitationsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMSystemException & e) + { + caughtException = true; + QVERIFY(e == systemException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInListBusinessInvitationsAsync() +{ + bool includeRequestedInvitations = generateRandomBool(); + IRequestContextPtr ctx = newRequestContext( + QStringLiteral("authenticationToken")); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreListBusinessInvitationsTesterHelper helper( + [&] (bool includeRequestedInvitationsParam, + IRequestContextPtr ctxParam) -> QList + { + Q_ASSERT(ctx->authenticationToken() == ctxParam->authenticationToken()); + Q_ASSERT(includeRequestedInvitations == includeRequestedInvitationsParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequest, + &helper, + &UserStoreListBusinessInvitationsTesterHelper::onListBusinessInvitationsRequestReceived); + QObject::connect( + &helper, + &UserStoreListBusinessInvitationsTesterHelper::listBusinessInvitationsRequestReady, + &server, + &UserStoreServer::onListBusinessInvitationsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::listBusinessInvitationsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->listBusinessInvitationsAsync( + includeRequestedInvitations, + ctx); + + UserStoreListBusinessInvitationsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreListBusinessInvitationsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreListBusinessInvitationsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +//////////////////////////////////////////////////////////////////////////////// + +void UserStoreTester::shouldExecuteGetAccountLimits() +{ + ServiceLevel serviceLevel = ServiceLevel::BASIC; + IRequestContextPtr ctx = newRequestContext(); + + AccountLimits response = generateRandomAccountLimits(); + + UserStoreGetAccountLimitsTesterHelper helper( + [&] (const ServiceLevel & serviceLevelParam, + IRequestContextPtr ctxParam) -> AccountLimits + { + Q_ASSERT(serviceLevel == serviceLevelParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getAccountLimitsRequest, + &helper, + &UserStoreGetAccountLimitsTesterHelper::onGetAccountLimitsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetAccountLimitsTesterHelper::getAccountLimitsRequestReady, + &server, + &UserStoreServer::onGetAccountLimitsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getAccountLimitsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AccountLimits res = userStore->getAccountLimits( + serviceLevel, + ctx); + QVERIFY(res == response); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInGetAccountLimits() +{ + ServiceLevel serviceLevel = ServiceLevel::PREMIUM; + IRequestContextPtr ctx = newRequestContext(); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNKNOWN; + userException.parameter = generateRandomString(); + + UserStoreGetAccountLimitsTesterHelper helper( + [&] (const ServiceLevel & serviceLevelParam, + IRequestContextPtr ctxParam) -> AccountLimits + { + Q_ASSERT(serviceLevel == serviceLevelParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getAccountLimitsRequest, + &helper, + &UserStoreGetAccountLimitsTesterHelper::onGetAccountLimitsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetAccountLimitsTesterHelper::getAccountLimitsRequestReady, + &server, + &UserStoreServer::onGetAccountLimitsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getAccountLimitsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AccountLimits res = userStore->getAccountLimits( + serviceLevel, + ctx); + Q_UNUSED(res) + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInGetAccountLimits() +{ + ServiceLevel serviceLevel = ServiceLevel::BASIC; + IRequestContextPtr ctx = newRequestContext(); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreGetAccountLimitsTesterHelper helper( + [&] (const ServiceLevel & serviceLevelParam, + IRequestContextPtr ctxParam) -> AccountLimits + { + Q_ASSERT(serviceLevel == serviceLevelParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getAccountLimitsRequest, + &helper, + &UserStoreGetAccountLimitsTesterHelper::onGetAccountLimitsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetAccountLimitsTesterHelper::getAccountLimitsRequestReady, + &server, + &UserStoreServer::onGetAccountLimitsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getAccountLimitsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AccountLimits res = userStore->getAccountLimits( + serviceLevel, + ctx); + Q_UNUSED(res) + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldExecuteGetAccountLimitsAsync() +{ + ServiceLevel serviceLevel = ServiceLevel::BASIC; + IRequestContextPtr ctx = newRequestContext(); + + AccountLimits response = generateRandomAccountLimits(); + + UserStoreGetAccountLimitsTesterHelper helper( + [&] (const ServiceLevel & serviceLevelParam, + IRequestContextPtr ctxParam) -> AccountLimits + { + Q_ASSERT(serviceLevel == serviceLevelParam); + return response; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getAccountLimitsRequest, + &helper, + &UserStoreGetAccountLimitsTesterHelper::onGetAccountLimitsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetAccountLimitsTesterHelper::getAccountLimitsRequestReady, + &server, + &UserStoreServer::onGetAccountLimitsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getAccountLimitsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + AsyncResult * result = userStore->getAccountLimitsAsync( + serviceLevel, + ctx); + + UserStoreGetAccountLimitsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetAccountLimitsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetAccountLimitsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_value == response); + QVERIFY(valueFetcher.m_exceptionData.get() == nullptr); +} + +void UserStoreTester::shouldDeliverEDAMUserExceptionInGetAccountLimitsAsync() +{ + ServiceLevel serviceLevel = ServiceLevel::PREMIUM; + IRequestContextPtr ctx = newRequestContext(); + + auto userException = EDAMUserException(); + userException.errorCode = EDAMErrorCode::UNSUPPORTED_OPERATION; + userException.parameter = generateRandomString(); + + UserStoreGetAccountLimitsTesterHelper helper( + [&] (const ServiceLevel & serviceLevelParam, + IRequestContextPtr ctxParam) -> AccountLimits + { + Q_ASSERT(serviceLevel == serviceLevelParam); + throw userException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getAccountLimitsRequest, + &helper, + &UserStoreGetAccountLimitsTesterHelper::onGetAccountLimitsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetAccountLimitsTesterHelper::getAccountLimitsRequestReady, + &server, + &UserStoreServer::onGetAccountLimitsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getAccountLimitsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getAccountLimitsAsync( + serviceLevel, + ctx); + + UserStoreGetAccountLimitsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetAccountLimitsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetAccountLimitsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const EDAMUserException & e) + { + caughtException = true; + QVERIFY(e == userException); + } + + QVERIFY(caughtException); +} + +void UserStoreTester::shouldDeliverThriftExceptionInGetAccountLimitsAsync() +{ + ServiceLevel serviceLevel = ServiceLevel::BASIC; + IRequestContextPtr ctx = newRequestContext(); + + auto thriftException = ThriftException( + ThriftException::Type::INTERNAL_ERROR, + QStringLiteral("Internal error")); + + UserStoreGetAccountLimitsTesterHelper helper( + [&] (const ServiceLevel & serviceLevelParam, + IRequestContextPtr ctxParam) -> AccountLimits + { + Q_ASSERT(serviceLevel == serviceLevelParam); + throw thriftException; + }); + + UserStoreServer server; + QObject::connect( + &server, + &UserStoreServer::getAccountLimitsRequest, + &helper, + &UserStoreGetAccountLimitsTesterHelper::onGetAccountLimitsRequestReceived); + QObject::connect( + &helper, + &UserStoreGetAccountLimitsTesterHelper::getAccountLimitsRequestReady, + &server, + &UserStoreServer::onGetAccountLimitsRequestReady); + + QTcpServer tcpServer; + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + quint16 port = tcpServer.serverPort(); + + QTcpSocket * pSocket = nullptr; + QObject::connect( + &tcpServer, + &QTcpServer::newConnection, + &tcpServer, + [&] { + pSocket = tcpServer.nextPendingConnection(); + Q_ASSERT(pSocket); + QObject::connect( + pSocket, + &QAbstractSocket::disconnected, + pSocket, + &QAbstractSocket::deleteLater); + if (!pSocket->waitForConnected()) { + QFAIL("Failed to establish connection"); + } + + QByteArray requestData = readRequestBodyFromSocket(*pSocket); + server.onRequest(requestData); + }); + + QObject::connect( + &server, + &UserStoreServer::getAccountLimitsRequestReady, + &server, + [&] (QByteArray responseData) + { + QByteArray buffer; + buffer.append("HTTP/1.1 200 OK\r\n"); + buffer.append("Content-Length: "); + buffer.append(QString::number(responseData.size()).toUtf8()); + buffer.append("\r\n"); + buffer.append("Content-Type: application/x-thrift\r\n\r\n"); + buffer.append(responseData); + + if (!writeBufferToSocket(buffer, *pSocket)) { + QFAIL("Failed to write response to socket"); + } + }); + + std::unique_ptr userStore( + newUserStore( + QStringLiteral("http://127.0.0.1:") + QString::number(port), + nullptr, + nullptr, + nullRetryPolicy())); + bool caughtException = false; + try + { + AsyncResult * result = userStore->getAccountLimitsAsync( + serviceLevel, + ctx); + + UserStoreGetAccountLimitsAsyncValueFetcher valueFetcher; + QObject::connect( + result, + &AsyncResult::finished, + &valueFetcher, + &UserStoreGetAccountLimitsAsyncValueFetcher::onFinished); + + QEventLoop loop; + QObject::connect( + &valueFetcher, + &UserStoreGetAccountLimitsAsyncValueFetcher::finished, + &loop, + &QEventLoop::quit); + + loop.exec(); + + QVERIFY(valueFetcher.m_exceptionData.get() != nullptr); + valueFetcher.m_exceptionData->throwException(); + } + catch(const ThriftException & e) + { + caughtException = true; + QVERIFY(e == thriftException); + } + + QVERIFY(caughtException); +} + +} // namespace qevercloud + +#include diff --git a/src/qevercloud/QEverCloud/src/tests/generated/TestUserStore.h b/src/qevercloud/QEverCloud/src/tests/generated/TestUserStore.h new file mode 100644 index 00000000..d10406a0 --- /dev/null +++ b/src/qevercloud/QEverCloud/src/tests/generated/TestUserStore.h @@ -0,0 +1,148 @@ +/** + * Original work: Copyright (c) 2014 Sergey Skoblikov + * Modified work: Copyright (c) 2015-2020 Dmitry Ivanov + * + * This file is a part of QEverCloud project and is distributed under the terms + * of MIT license: + * https://opensource.org/licenses/MIT + * + * This file was generated from Evernote Thrift API + */ + +#ifndef QEVERCLOUD_GENERATED_TESTUSERSTORE_H +#define QEVERCLOUD_GENERATED_TESTUSERSTORE_H + +#include + +namespace qevercloud { + +//////////////////////////////////////////////////////////////////////////////// + +class UserStoreTester: public QObject +{ + Q_OBJECT +public: + explicit UserStoreTester(QObject * parent = nullptr); + +private Q_SLOTS: + void shouldExecuteCheckVersion(); + void shouldDeliverThriftExceptionInCheckVersion(); + void shouldExecuteCheckVersionAsync(); + void shouldDeliverThriftExceptionInCheckVersionAsync(); + void shouldExecuteGetBootstrapInfo(); + void shouldDeliverThriftExceptionInGetBootstrapInfo(); + void shouldExecuteGetBootstrapInfoAsync(); + void shouldDeliverThriftExceptionInGetBootstrapInfoAsync(); + void shouldExecuteAuthenticateLongSession(); + void shouldDeliverEDAMUserExceptionInAuthenticateLongSession(); + void shouldDeliverEDAMSystemExceptionInAuthenticateLongSession(); + void shouldDeliverThriftExceptionInAuthenticateLongSession(); + void shouldExecuteAuthenticateLongSessionAsync(); + void shouldDeliverEDAMUserExceptionInAuthenticateLongSessionAsync(); + void shouldDeliverEDAMSystemExceptionInAuthenticateLongSessionAsync(); + void shouldDeliverThriftExceptionInAuthenticateLongSessionAsync(); + void shouldExecuteCompleteTwoFactorAuthentication(); + void shouldDeliverEDAMUserExceptionInCompleteTwoFactorAuthentication(); + void shouldDeliverEDAMSystemExceptionInCompleteTwoFactorAuthentication(); + void shouldDeliverThriftExceptionInCompleteTwoFactorAuthentication(); + void shouldExecuteCompleteTwoFactorAuthenticationAsync(); + void shouldDeliverEDAMUserExceptionInCompleteTwoFactorAuthenticationAsync(); + void shouldDeliverEDAMSystemExceptionInCompleteTwoFactorAuthenticationAsync(); + void shouldDeliverThriftExceptionInCompleteTwoFactorAuthenticationAsync(); + void shouldExecuteRevokeLongSession(); + void shouldDeliverEDAMUserExceptionInRevokeLongSession(); + void shouldDeliverEDAMSystemExceptionInRevokeLongSession(); + void shouldDeliverThriftExceptionInRevokeLongSession(); + void shouldExecuteRevokeLongSessionAsync(); + void shouldDeliverEDAMUserExceptionInRevokeLongSessionAsync(); + void shouldDeliverEDAMSystemExceptionInRevokeLongSessionAsync(); + void shouldDeliverThriftExceptionInRevokeLongSessionAsync(); + void shouldExecuteAuthenticateToBusiness(); + void shouldDeliverEDAMUserExceptionInAuthenticateToBusiness(); + void shouldDeliverEDAMSystemExceptionInAuthenticateToBusiness(); + void shouldDeliverThriftExceptionInAuthenticateToBusiness(); + void shouldExecuteAuthenticateToBusinessAsync(); + void shouldDeliverEDAMUserExceptionInAuthenticateToBusinessAsync(); + void shouldDeliverEDAMSystemExceptionInAuthenticateToBusinessAsync(); + void shouldDeliverThriftExceptionInAuthenticateToBusinessAsync(); + void shouldExecuteGetUser(); + void shouldDeliverEDAMUserExceptionInGetUser(); + void shouldDeliverEDAMSystemExceptionInGetUser(); + void shouldDeliverThriftExceptionInGetUser(); + void shouldExecuteGetUserAsync(); + void shouldDeliverEDAMUserExceptionInGetUserAsync(); + void shouldDeliverEDAMSystemExceptionInGetUserAsync(); + void shouldDeliverThriftExceptionInGetUserAsync(); + void shouldExecuteGetPublicUserInfo(); + void shouldDeliverEDAMNotFoundExceptionInGetPublicUserInfo(); + void shouldDeliverEDAMSystemExceptionInGetPublicUserInfo(); + void shouldDeliverEDAMUserExceptionInGetPublicUserInfo(); + void shouldDeliverThriftExceptionInGetPublicUserInfo(); + void shouldExecuteGetPublicUserInfoAsync(); + void shouldDeliverEDAMNotFoundExceptionInGetPublicUserInfoAsync(); + void shouldDeliverEDAMSystemExceptionInGetPublicUserInfoAsync(); + void shouldDeliverEDAMUserExceptionInGetPublicUserInfoAsync(); + void shouldDeliverThriftExceptionInGetPublicUserInfoAsync(); + void shouldExecuteGetUserUrls(); + void shouldDeliverEDAMUserExceptionInGetUserUrls(); + void shouldDeliverEDAMSystemExceptionInGetUserUrls(); + void shouldDeliverThriftExceptionInGetUserUrls(); + void shouldExecuteGetUserUrlsAsync(); + void shouldDeliverEDAMUserExceptionInGetUserUrlsAsync(); + void shouldDeliverEDAMSystemExceptionInGetUserUrlsAsync(); + void shouldDeliverThriftExceptionInGetUserUrlsAsync(); + void shouldExecuteInviteToBusiness(); + void shouldDeliverEDAMUserExceptionInInviteToBusiness(); + void shouldDeliverEDAMSystemExceptionInInviteToBusiness(); + void shouldDeliverThriftExceptionInInviteToBusiness(); + void shouldExecuteInviteToBusinessAsync(); + void shouldDeliverEDAMUserExceptionInInviteToBusinessAsync(); + void shouldDeliverEDAMSystemExceptionInInviteToBusinessAsync(); + void shouldDeliverThriftExceptionInInviteToBusinessAsync(); + void shouldExecuteRemoveFromBusiness(); + void shouldDeliverEDAMUserExceptionInRemoveFromBusiness(); + void shouldDeliverEDAMSystemExceptionInRemoveFromBusiness(); + void shouldDeliverEDAMNotFoundExceptionInRemoveFromBusiness(); + void shouldDeliverThriftExceptionInRemoveFromBusiness(); + void shouldExecuteRemoveFromBusinessAsync(); + void shouldDeliverEDAMUserExceptionInRemoveFromBusinessAsync(); + void shouldDeliverEDAMSystemExceptionInRemoveFromBusinessAsync(); + void shouldDeliverEDAMNotFoundExceptionInRemoveFromBusinessAsync(); + void shouldDeliverThriftExceptionInRemoveFromBusinessAsync(); + void shouldExecuteUpdateBusinessUserIdentifier(); + void shouldDeliverEDAMUserExceptionInUpdateBusinessUserIdentifier(); + void shouldDeliverEDAMSystemExceptionInUpdateBusinessUserIdentifier(); + void shouldDeliverEDAMNotFoundExceptionInUpdateBusinessUserIdentifier(); + void shouldDeliverThriftExceptionInUpdateBusinessUserIdentifier(); + void shouldExecuteUpdateBusinessUserIdentifierAsync(); + void shouldDeliverEDAMUserExceptionInUpdateBusinessUserIdentifierAsync(); + void shouldDeliverEDAMSystemExceptionInUpdateBusinessUserIdentifierAsync(); + void shouldDeliverEDAMNotFoundExceptionInUpdateBusinessUserIdentifierAsync(); + void shouldDeliverThriftExceptionInUpdateBusinessUserIdentifierAsync(); + void shouldExecuteListBusinessUsers(); + void shouldDeliverEDAMUserExceptionInListBusinessUsers(); + void shouldDeliverEDAMSystemExceptionInListBusinessUsers(); + void shouldDeliverThriftExceptionInListBusinessUsers(); + void shouldExecuteListBusinessUsersAsync(); + void shouldDeliverEDAMUserExceptionInListBusinessUsersAsync(); + void shouldDeliverEDAMSystemExceptionInListBusinessUsersAsync(); + void shouldDeliverThriftExceptionInListBusinessUsersAsync(); + void shouldExecuteListBusinessInvitations(); + void shouldDeliverEDAMUserExceptionInListBusinessInvitations(); + void shouldDeliverEDAMSystemExceptionInListBusinessInvitations(); + void shouldDeliverThriftExceptionInListBusinessInvitations(); + void shouldExecuteListBusinessInvitationsAsync(); + void shouldDeliverEDAMUserExceptionInListBusinessInvitationsAsync(); + void shouldDeliverEDAMSystemExceptionInListBusinessInvitationsAsync(); + void shouldDeliverThriftExceptionInListBusinessInvitationsAsync(); + void shouldExecuteGetAccountLimits(); + void shouldDeliverEDAMUserExceptionInGetAccountLimits(); + void shouldDeliverThriftExceptionInGetAccountLimits(); + void shouldExecuteGetAccountLimitsAsync(); + void shouldDeliverEDAMUserExceptionInGetAccountLimitsAsync(); + void shouldDeliverThriftExceptionInGetAccountLimitsAsync(); +}; + +} // namespace qevercloud + +#endif // QEVERCLOUD_GENERATED_TESTUSERSTORE_H diff --git a/src/qevercloud/QEverCloud/src/thumbnail.cpp b/src/qevercloud/QEverCloud/src/thumbnail.cpp deleted file mode 100644 index b6df409a..00000000 --- a/src/qevercloud/QEverCloud/src/thumbnail.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/** - * Original work: Copyright (c) 2014 Sergey Skoblikov - * Modified work: Copyright (c) 2015-2016 Dmitry Ivanov - * - * This file is a part of QEverCloud project and is distributed under the terms of MIT license: - * https://opensource.org/licenses/MIT - */ - -#include -#include "http.h" - -namespace qevercloud { - -class ThumbnailPrivate -{ -public: - QString m_host; - QString m_shardId; - QString m_authenticationToken; - int m_size; - Thumbnail::ImageType::type m_imageType; -}; - -Thumbnail::Thumbnail(): - d_ptr(new ThumbnailPrivate) -{ - d_ptr->m_size = 300; - d_ptr->m_imageType = ImageType::PNG; -} - - -Thumbnail::Thumbnail(QString host, QString shardId, QString authenticationToken, - int size, Thumbnail::ImageType::type imageType) : - d_ptr(new ThumbnailPrivate) -{ - d_ptr->m_host = host; - d_ptr->m_shardId = shardId; - d_ptr->m_authenticationToken = authenticationToken; - d_ptr->m_size = size; - d_ptr->m_imageType = imageType; -} - -Thumbnail::~Thumbnail() -{ - delete d_ptr; -} - -Thumbnail & Thumbnail::setHost(QString host) -{ - d_ptr->m_host = host; - return *this; -} - -Thumbnail & Thumbnail::setShardId(QString shardId) -{ - d_ptr->m_shardId = shardId; - return *this; -} - -Thumbnail & Thumbnail::setAuthenticationToken(QString authenticationToken) -{ - d_ptr->m_authenticationToken = authenticationToken; - return *this; -} - -Thumbnail & Thumbnail::setSize(int size) -{ - d_ptr->m_size = size; - return *this; -} - -Thumbnail & Thumbnail::setImageType(ImageType::type imageType) -{ - d_ptr->m_imageType = imageType; - return *this; -} - -QByteArray Thumbnail::download(Guid guid, bool isPublic, bool isResourceGuid) -{ - int httpStatusCode = 0; - QPair request = createPostRequest(guid, isPublic, isResourceGuid); - - QByteArray reply = simpleDownload(evernoteNetworkAccessManager(), request.first, - request.second, &httpStatusCode); - if (httpStatusCode != 200) { - throw EverCloudException(QStringLiteral("HTTP Status Code = %1").arg(httpStatusCode)); - } - - return reply; -} - -AsyncResult* Thumbnail::downloadAsync(Guid guid, bool isPublic, bool isResourceGuid) -{ - QPair pair = createPostRequest(guid, isPublic, isResourceGuid); - return new AsyncResult(pair.first, pair.second); -} - -QPair Thumbnail::createPostRequest(Guid guid, bool isPublic, bool isResourceGuid) -{ - Q_D(Thumbnail); - - QByteArray postData = ""; // not QByteArray()! or else ReplyFetcher will not work. - QNetworkRequest request; - - QString urlPattern; - if(isResourceGuid) { - urlPattern = QStringLiteral("https://%1/shard/%2/thm/res/%3"); - } - else { - urlPattern = QStringLiteral("https://%1/shard/%2/thm/note/%3"); - } - - QString url = urlPattern.arg(d->m_host, d->m_shardId, guid); - - QString ext; - switch(d->m_imageType) - { - case ImageType::BMP: - ext = QStringLiteral(".bmp"); - break; - case ImageType::GIF: - ext = QStringLiteral(".gif"); - break; - case ImageType::JPEG: - ext = QStringLiteral(".jpg"); - break; - default: - ext = QStringLiteral(".png"); - break; - } - url += ext; - - if (d->m_size != 300) { - url += QStringLiteral("?size=%1").arg(d->m_size); - } - - request.setUrl(QUrl(url)); - request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/x-www-form-urlencoded")); - - if (!isPublic) { - postData = QByteArray("auth=")+ QUrl::toPercentEncoding(d->m_authenticationToken); - } - - return qMakePair(request, postData); -} - -} // namespace qevercloud diff --git a/src/qevercloud/QEverCloud/translations/QEverCloud_ru_RU.ts b/src/qevercloud/QEverCloud/translations/QEverCloud_ru_RU.ts new file mode 100644 index 00000000..e9431a00 --- /dev/null +++ b/src/qevercloud/QEverCloud/translations/QEverCloud_ru_RU.ts @@ -0,0 +1,37 @@ + + + + + QObject + + Authentication + qevercloud::EvernoteOAuthWebViewPrivate + Аутентификация + + + Open the link below in your browser and authenticate the application to access the data in your Evernote account + qevercloud::EvernoteOAuthWebViewPrivate + Откройте ссылку ниже в браузере и авторизуйте приложения для доступа к данным в вашем Evernote аккаунте + + + Failed to establish connection between browser and local OAuth server + qevercloud::EvernoteOAuthWebViewPrivate + Не удалось установить соединение между системным браузером и локальным сервером авторизации + + + Authentification failed + qevercloud::EvernoteOAuthWebViewPrivate + Аутентификация завершилась неудачей + + + Authentication is complete! You can now close this page and return to the app + qevercloud::EvernoteOAuthWebViewPrivate + Аутентификация завершилась успешно! Теперь можно закрыть эту страницу и вернуться к приложению. + + + Authentication failed! + qevercloud::EvernoteOAuthWebViewPrivate + Аутентификация завершилась неудачей + + + diff --git a/src/sql/notebooktable.cpp b/src/sql/notebooktable.cpp index 1d10646a..c86a62b6 100644 --- a/src/sql/notebooktable.cpp +++ b/src/sql/notebooktable.cpp @@ -304,10 +304,10 @@ qint32 NotebookTable::add(qint32 l, Notebook &t, bool isDirty, bool isLocal) { } if (publishing.order.isSet()) { - NoteSortOrder::type order = publishing.order; + NoteSortOrder order = publishing.order; query.bindValue(":lid", lid); query.bindValue(":key", NOTEBOOK_PUBLISHING_ORDER); - query.bindValue(":data", order); + query.bindValue(":data", static_cast(order)); query.exec(); } @@ -394,10 +394,10 @@ bool NotebookTable::get(Notebook ¬ebook, qint32 lid) { if (notebook.publishing.isSet()) publishing = notebook.publishing; publishing.order = NoteSortOrder::CREATED; - if (value == NoteSortOrder::UPDATED) publishing.order = NoteSortOrder::UPDATED; - if (value == NoteSortOrder::RELEVANCE) publishing.order = NoteSortOrder::RELEVANCE; - if (value == NoteSortOrder::UPDATE_SEQUENCE_NUMBER) publishing.order = NoteSortOrder::UPDATE_SEQUENCE_NUMBER; - if (value == NoteSortOrder::TITLE) publishing.order = NoteSortOrder::TITLE; + if (value == static_cast(NoteSortOrder::UPDATED)) publishing.order = NoteSortOrder::UPDATED; + if (value == static_cast(NoteSortOrder::RELEVANCE)) publishing.order = NoteSortOrder::RELEVANCE; + if (value == static_cast(NoteSortOrder::UPDATE_SEQUENCE_NUMBER)) publishing.order = NoteSortOrder::UPDATE_SEQUENCE_NUMBER; + if (value == static_cast(NoteSortOrder::TITLE)) publishing.order = NoteSortOrder::TITLE; notebook.publishing = publishing; break; } diff --git a/src/sql/searchtable.cpp b/src/sql/searchtable.cpp index 46139a86..1ea7f7a8 100644 --- a/src/sql/searchtable.cpp +++ b/src/sql/searchtable.cpp @@ -192,7 +192,7 @@ void SearchTable::add(qint32 l, SavedSearch &t, bool isDirty) { } if (t.format.isSet()) { - int format = t.format; + int format = static_cast(t.format.ref()); query.bindValue(":lid", lid); query.bindValue(":key", SEARCH_FORMAT); query.bindValue(":data", format); @@ -247,7 +247,7 @@ bool SearchTable::get(SavedSearch &search ,qint32 lid) { case (SEARCH_FORMAT): qint32 value = query.value(1).toInt(); search.format = QueryFormat::USER; - if (value == QueryFormat::SEXP) search.format = QueryFormat::SEXP; + if (value == static_cast(QueryFormat::SEXP)) search.format = QueryFormat::SEXP; break; } } diff --git a/src/sql/sharednotebooktable.cpp b/src/sql/sharednotebooktable.cpp index 6f95ee5a..ddac147b 100644 --- a/src/sql/sharednotebooktable.cpp +++ b/src/sql/sharednotebooktable.cpp @@ -133,7 +133,7 @@ qint32 SharedNotebookTable::add(qint32 l, const SharedNotebook &t, bool isDirty) query.prepare("Insert into DataStore (lid, key, data) values (:lid, :key, :data)"); query.bindValue(":lid", lid); query.bindValue(":key", SHAREDNOTEBOOK_PRIVILEGE); - qint32 priv = t.privilege; + qint32 priv = static_cast(t.privilege.ref()); query.bindValue(":data", priv); query.exec(); } @@ -247,15 +247,15 @@ bool SharedNotebookTable::get(SharedNotebook ¬ebook, qint32 lid, QString user case (SHAREDNOTEBOOK_PRIVILEGE): { int priv = query.value(1).toInt(); notebook.privilege = SharedNotebookPrivilegeLevel::READ_NOTEBOOK; - if (priv == SharedNotebookPrivilegeLevel::FULL_ACCESS) + if (priv == static_cast(SharedNotebookPrivilegeLevel::FULL_ACCESS)) notebook.privilege = SharedNotebookPrivilegeLevel::FULL_ACCESS; - if (priv == SharedNotebookPrivilegeLevel::BUSINESS_FULL_ACCESS) + if (priv == static_cast(SharedNotebookPrivilegeLevel::BUSINESS_FULL_ACCESS)) notebook.privilege = SharedNotebookPrivilegeLevel::BUSINESS_FULL_ACCESS; - if (priv == SharedNotebookPrivilegeLevel::GROUP) + if (priv == static_cast(SharedNotebookPrivilegeLevel::GROUP)) notebook.privilege = SharedNotebookPrivilegeLevel::GROUP; - if (priv == SharedNotebookPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY) + if (priv == static_cast(SharedNotebookPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY)) notebook.privilege = SharedNotebookPrivilegeLevel::MODIFY_NOTEBOOK_PLUS_ACTIVITY; - if (priv == SharedNotebookPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY) + if (priv == static_cast(SharedNotebookPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY)) notebook.privilege = SharedNotebookPrivilegeLevel::READ_NOTEBOOK_PLUS_ACTIVITY; returnVal = true; break; diff --git a/src/sql/usertable.cpp b/src/sql/usertable.cpp index 005b4ad4..bfe1a2e6 100644 --- a/src/sql/usertable.cpp +++ b/src/sql/usertable.cpp @@ -142,7 +142,7 @@ void UserTable::updateUser(User &user) { if (user.privilege.isSet()) { query.prepare("Insert into UserTable (key, data) values (:key, :data);"); query.bindValue(":key", USER_PRIVILEGE); - int priv = user.privilege; + int priv = static_cast(user.privilege.ref()); query.bindValue(":data", priv); query.exec(); } @@ -463,13 +463,13 @@ void UserTable::getUser(User &user) { if (query.value(0) == USER_PRIVILEGE) { int priv = QVariant(query.value(1)).toInt(); user.privilege = PrivilegeLevel::NORMAL; - if (priv == PrivilegeLevel::ADMIN) + if (priv == static_cast(PrivilegeLevel::ADMIN)) user.privilege = PrivilegeLevel::ADMIN; - if (priv == PrivilegeLevel::PREMIUM) + if (priv == static_cast(PrivilegeLevel::PREMIUM)) user.privilege = PrivilegeLevel::PREMIUM; - if (priv == PrivilegeLevel::MANAGER) + if (priv == static_cast(PrivilegeLevel::MANAGER)) user.privilege = PrivilegeLevel::MANAGER; - if (priv == PrivilegeLevel::SUPPORT) + if (priv == static_cast(PrivilegeLevel::SUPPORT)) user.privilege = PrivilegeLevel::SUPPORT; } if (query.value(0) == USER_CREATED) { diff --git a/src/threads/syncrunner.cpp b/src/threads/syncrunner.cpp index 512d641e..c00695d7 100644 --- a/src/threads/syncrunner.cpp +++ b/src/threads/syncrunner.cpp @@ -1229,7 +1229,7 @@ void SyncRunner::communicationErrorHandler() { apiRateLimitExceeded = true; } if (type == CommunicationError::EDAMUserException) { - if (comm->getLastErrorCode() == EDAMErrorCode::AUTH_EXPIRED) { + if (comm->getLastErrorCode() == static_cast(EDAMErrorCode::AUTH_EXPIRED)) { global.accountsManager->setOAuthToken(""); } } diff --git a/src/utilities/debugtool.cpp b/src/utilities/debugtool.cpp index 4b4e6c33..28e5cbdc 100644 --- a/src/utilities/debugtool.cpp +++ b/src/utilities/debugtool.cpp @@ -182,8 +182,10 @@ void DebugTool::dumpNotebook(Notebook n) { BusinessNotebook b = n.businessNotebook; dumpField(b.notebookDescription, "notebookDescription"); dumpField(b.recommended, "recommended"); - int i = b.privilege; - QLOG_DEBUG() << "privilege:" << i; + if (b.privilege.isSet()) { + int i = static_cast(b.privilege.ref()); + QLOG_DEBUG() << "privilege:" << i; + } } else { QLOG_DEBUG() << "businessnotebooek data not found."; } diff --git a/src/xml/exportdata.cpp b/src/xml/exportdata.cpp index 7557a8df..7a990896 100644 --- a/src/xml/exportdata.cpp +++ b/src/xml/exportdata.cpp @@ -184,7 +184,7 @@ void ExportData::writeNotebooks() { if (book.businessNotebook.value().notebookDescription.isSet()) createNode("NotebookDescription", book.businessNotebook.value().notebookDescription); if (book.businessNotebook.value().privilege.isSet()) - createNode("NotebookDescription", book.businessNotebook.value().privilege); + createNode("NotebookDescription", static_cast(book.businessNotebook.value().privilege.ref())); if (book.businessNotebook.value().recommended.isSet()) createNode("NotebookDescription", book.businessNotebook.value().recommended); writer->writeEndElement(); @@ -199,7 +199,7 @@ void ExportData::writeNotebooks() { if (book.publishing.value().ascending.isSet()) createNode("Ascending", book.publishing.value().ascending); if (book.publishing.value().order.isSet()) - createNode("Uri", QString::number(book.publishing.value().order)); + createNode("Uri", QString::number(static_cast(book.publishing.value().order.ref()))); writer->writeEndElement(); } @@ -233,7 +233,7 @@ void ExportData::writeUser(User user) { if (user.timezone.isSet()) createNode("Timezone", user.timezone); if (user.privilege.isSet()) - createNode("Privilege", user.privilege); + createNode("Privilege", static_cast(user.privilege.ref())); if (user.created.isSet()) createTimestampNode("Created", user.created); if (user.updated.isSet()) @@ -304,7 +304,7 @@ void ExportData::writeUser(User user) { if (user.attributes.value().useEmailAutoFiling.isSet()) createNode("UseEmailAutoFiling", user.attributes.value().useEmailAutoFiling); if (user.attributes.value().reminderEmailConfig.isSet()) - createNode("ReminderEmailConfig", user.attributes.value().reminderEmailConfig); + createNode("ReminderEmailConfig", static_cast(user.attributes.value().reminderEmailConfig.ref())); writer->writeEndElement(); } @@ -331,7 +331,7 @@ void ExportData::writeUser(User user) { if (user.businessUserInfo.value().email.isSet()) createNode("Email", user.businessUserInfo.value().email); if (user.businessUserInfo.value().role.isSet()) - createNode("Role", user.businessUserInfo.value().role); + createNode("Role", static_cast(user.businessUserInfo.value().role.ref())); writer->writeEndElement(); } @@ -381,7 +381,7 @@ void ExportData::writeSavedSearches() { if (s.query.isSet()) createNode("Query", s.query); if (s.format.isSet()) - createNode("Format", s.format); + createNode("Format", static_cast(s.format.ref())); if (s.updateSequenceNum.isSet()) createNode("UpdateSequenceNumber", s.updateSequenceNum); if (s.scope.isSet()) { @@ -477,7 +477,7 @@ void ExportData::writeSharedNotebooks() { if (s.notebookModifiable.isSet()) createNode("NotebookModifiable", s.notebookModifiable); if (s.privilege.isSet()) - createNode("Privilege", s.privilege); + createNode("Privilege", static_cast(s.privilege.ref())); if (s.recipientSettings.isSet()) { writer->writeStartElement("RecipientSettings"); if (s.recipientSettings.value().reminderNotifyEmail.isSet()) From 8a5a4dd356f822b8976aa64d9a43e4198037259d Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Tue, 28 Mar 2023 18:30:30 +0300 Subject: [PATCH 2/7] Issue #171: default to using user own auth token for public linked notebooks --- src/communication/communicationmanager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/communication/communicationmanager.cpp b/src/communication/communicationmanager.cpp index 9e116594..b3a0de19 100644 --- a/src/communication/communicationmanager.cpp +++ b/src/communication/communicationmanager.cpp @@ -644,8 +644,8 @@ bool CommunicationManager::authenticateToLinkedNotebookShard(LinkedNotebook &boo delete linkedNoteStore; // Connect to the proper shard - linkedNoteStore = new NoteStore(book.noteStoreUrl, authToken); - linkedAuthToken = ""; + linkedNoteStore = newNoteStore(book.noteStoreUrl, newRequestContext(authToken, requestTimeout)); + linkedAuthToken = authToken; noteStore = linkedNoteStore; // Now, authenticate to the book. Books From deec900e112915db24db87973231adcecb0b4732 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Sun, 9 Apr 2023 19:36:46 +0300 Subject: [PATCH 3/7] Issue #171: use OAuth via system browser by default but support OAuth via QtWebKit or QtWebEngine as config options --- nixnote2.pro | 75 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 13 deletions(-) diff --git a/nixnote2.pro b/nixnote2.pro index 0f227b56..8995651d 100644 --- a/nixnote2.pro +++ b/nixnote2.pro @@ -43,21 +43,35 @@ OBJECTS_DIR = $${DESTDIR} MOC_DIR = $${DESTDIR} oauth_webengine { + oauth_webkit { + error("oauth_webengine and oauth_webkit are mutually exclusive!") + } + win32-g++ { error("Cannot use QtWebEngine with MinGW build") - } else { - message("Using QtWebEngine for OAuth") - QT += webengine webenginewidgets - QEVERCLOUD_USE_QT_WEB_ENGINE = 1 - DEFINES += QEVERCLOUD_USE_QT_WEB_ENGINE=1 } + + message("Using QtWebEngine for OAuth") + QT += webengine webenginewidgets + QEVERCLOUD_USE_QT_WEB_ENGINE = 1 + QEVERCLOUD_USE_SYSTEM_BROWSER = 0 + DEFINES += QEVERCLOUD_USE_QT_WEB_ENGINE=1 + DEFINES += QEVERCLOUD_USE_SYSTEM_BROWSER=0 } else { - message("Using QtWebKit for OAuth") - !win32-g++ { - warning("Consider adding CONFIG+=oauth_webengine to qmake invocation to use QtWebEngine for OAuth; QtWebKit has known problems with it, OAuth may not work!") + oauth_webkit { + message("Using QtWebKit for OAuth") + warning("QtWebKit has known problems with OAuth, it might not work well!") + QEVERCLOUD_USE_QT_WEB_ENGINE = 0 + QEVERCLOUD_USE_SYSTEM_BROWSER = 0 + DEFINES += QEVERCLOUD_USE_QT_WEB_ENGINE=0 + DEFINES += QEVERCLOUD_USE_SYSTEM_BROWSER=0 + } else { + message("Using system browser for OAuth") + QEVERCLOUD_USE_QT_WEB_ENGINE = 0 + QEVERCLOUD_USE_SYSTEM_BROWSER = 1 + DEFINES += QEVERCLOUD_USE_QT_WEB_ENGINE=0 + DEFINES += QEVERCLOUD_USE_SYSTEM_BROWSER=1 } - QEVERCLOUD_USE_QT_WEB_ENGINE = 0 - DEFINES += QEVERCLOUD_USE_QT_WEB_ENGINE=0 } qevercloud_version_info.input = src/qevercloud/QEverCloud/headers/VersionInfo.h.in @@ -213,12 +227,14 @@ SOURCES += \ src/qevercloud/QEverCloud/src/HttpUtils.cpp \ src/qevercloud/QEverCloud/src/InkNoteImageDownloader.cpp \ src/qevercloud/QEverCloud/src/Log.cpp \ - src/qevercloud/QEverCloud/src/NetworkCookieJar.cpp \ - src/qevercloud/QEverCloud/src/OAuth.cpp \ src/qevercloud/QEverCloud/src/Printable.cpp \ src/qevercloud/QEverCloud/src/RequestContext.cpp \ src/qevercloud/QEverCloud/src/Thumbnail.cpp \ src/qevercloud/QEverCloud/src/VersionInfo.cpp \ + src/qevercloud/QEverCloud/src/oauth/AbstractOAuthEngine.cpp \ + src/qevercloud/QEverCloud/src/oauth/NonceGenerator.cpp \ + src/qevercloud/QEverCloud/src/oauth/OAuth.cpp \ + src/qevercloud/QEverCloud/src/oauth/Utils.cpp \ src/reminders/reminderevent.cpp \ src/reminders/remindermanager.cpp \ src/settings/accountsmanager.cpp \ @@ -270,6 +286,20 @@ SOURCES += \ src/quentier/utility/StringUtils.cpp \ src/quentier/utility/StringUtils_p.cpp +oauth_webengine { + SOURCES += \ + src/qevercloud/QEverCloud/src/oauth/NetworkCookieJar.cpp \ + src/qevercloud/QEverCloud/src/oauth/OAuthWebEngine.cpp +} else { + oauth_webkit { + SOURCES += \ + src/qevercloud/QEverCloud/src/oauth/OAuthWebKit.cpp + } else { + SOURCES += \ + src/qevercloud/QEverCloud/src/oauth/OAuthSystemBrowser.cpp + } +} + HEADERS += \ src/application.h \ src/nixnote.h \ @@ -427,9 +457,15 @@ HEADERS += \ src/qevercloud/QEverCloud/src/generated/Types_io.h \ src/qevercloud/QEverCloud/src/AsyncResult_p.h \ src/qevercloud/QEverCloud/src/Http.h \ + src/qevercloud/QEverCloud/src/HttpRequestData.h \ + src/qevercloud/QEverCloud/src/HttpRequestParser.h \ + src/qevercloud/QEverCloud/src/HttpUtils.h \ src/qevercloud/QEverCloud/src/Impl.h \ - src/qevercloud/QEverCloud/src/NetworkCookieJar.h \ src/qevercloud/QEverCloud/src/Thrift.h \ + src/qevercloud/QEverCloud/src/oauth/AbstractOAuthEngine.h \ + src/qevercloud/QEverCloud/src/oauth/NetworkCookieJar.h \ + src/qevercloud/QEverCloud/src/oauth/NonceGenerator.h \ + src/qevercloud/QEverCloud/src/oauth/Utils.h \ src/reminders/reminderevent.h \ src/reminders/remindermanager.h \ src/settings/accountsmanager.h \ @@ -481,6 +517,19 @@ HEADERS += \ src/quentier/utility/StringUtils.h \ src/quentier/utility/StringUtils_p.h +oauth_webengine { + HEADERS += \ + src/qevercloud/QEverCloud/src/oauth/OAuthWebEngine.h +} else { + oauth_webkit { + HEADERS += \ + src/qevercloud/QEverCloud/src/oauth/OAuthWebKit.h + } else { + HEADERS += \ + src/qevercloud/QEverCloud/src/oauth/OAuthSystemBrowser.h + } +} + # http://doc.qt.io/qt-5/qmake-function-reference.html#str-member-arg-start-end # $$left(VAR, len) #left = $$str_member(VAR, 0, $$num_add($$len, -1)) From 03837e6b619007e6f733635223d0ec4e6ee17cfa Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Thu, 30 Mar 2023 17:38:21 +0300 Subject: [PATCH 4/7] Issue #171: switch docker build to Ubuntu focal and using system browser for OAuth --- development/build-with-docker.sh | 36 ++----------------- development/build-with-qmake.sh | 17 ++++++--- development/create-AppImage-linuxdeploy.sh | 29 +++++++++++++++ development/docker/Dockerfile.ubuntu_focal | 41 ++++++++++++++++++++++ 4 files changed, 86 insertions(+), 37 deletions(-) create mode 100755 development/create-AppImage-linuxdeploy.sh create mode 100644 development/docker/Dockerfile.ubuntu_focal diff --git a/development/build-with-docker.sh b/development/build-with-docker.sh index d3b14489..e1d561e2 100755 --- a/development/build-with-docker.sh +++ b/development/build-with-docker.sh @@ -3,12 +3,8 @@ PROJECTBRANCH=${1} PROJECTDIR=`pwd` set -xe -# note: all with DOCKERMODIFIER != "" is highly experimental and needs "someway" to include webkit binaries -# so without it will fail -#DOCKERMODIFIER=_qt562 - -DOCKERTAG=nixnote2/xenial${DOCKERMODIFIER} -DOCKERFILE=./development/docker/Dockerfile.ubuntu_xenial${DOCKERMODIFIER} +DOCKERTAG=nixnote2/focal +DOCKERFILE=./development/docker/Dockerfile.ubuntu_focal function error_exit { echo "$0: ***********error_exit***********" @@ -33,12 +29,6 @@ cd $PROJECTDIR docker build -t ${DOCKERTAG} -f ${DOCKERFILE} ./development/docker # stop after creating the image (e.g. you want to do the build manually) -if [ ! -z ${DOCKERMODIFIER} ] ; then - echo "Docker image ${DOCKERTAG} created.. " - echo "DOCKERMODIFIER set to $DOCKERMODIFIER .. you need to provide webkit manually.." - exit 1 -fi - if [ ! -d appdir ] ; then mkdir appdir || error_exit "mkdir appdir" fi @@ -53,33 +43,13 @@ if [ ! -d docker-build-${BUILD_TYPE} ]; then fi # start container (note: each call creates new container) - - - -# to try manually: -# DOCKERTAG=.. -# docker run --rm -it ${DOCKERTAG} /bin/bash -# then -# PROJECTBRANCH=feature/rc1 -# BUILD_TYPE=release -# ...copy command from bellow & paste.. -# -------------------- - -# **TEMPORARY** for beineri PPA recompile ################# -# PROJECTBRANCH=feature/rc1;BUILD_TYPE=release -# source /opt/qt*/bin/qt*-env.sh -# git fetch && git checkout $PROJECTBRANCH && git pull && ./development/build-with-qmake.sh ${BUILD_TYPE} noclean /usr/lib/nixnote2/tidy -# unset QTDIR; unset QT_PLUGIN_PATH ; unset LD_LIBRARY_PATH -# ./development/create-AppImage.sh -# mv *.AppImage appdir2 && chmod -R a+rwx appdir/*.AppImage - time docker run \ --rm \ -v $PROJECTDIR/appdir:/opt/nixnote2/appdir \ -v $PROJECTDIR/docker-build-${BUILD_TYPE}:/opt/nixnote2/qmake-build-${BUILD_TYPE} \ -v $PROJECTDIR/docker-build-${BUILD_TYPE}-t:/opt/nixnote2/qmake-build-${BUILD_TYPE}-t \ -it ${DOCKERTAG} \ - /bin/bash -c "cd nixnote2 && git fetch && git checkout $PROJECTBRANCH && git pull && ./development/build-with-qmake.sh ${BUILD_TYPE} noclean /usr/lib/nixnote2/tidy && ./development/run-tests.sh ${BUILD_TYPE} noclean /usr/lib/nixnote2/tidy && ./development/create-AppImage.sh && mv *.AppImage appdir && chmod -R a+rwx appdir/*.AppImage" + /bin/bash -c "cd nixnote2 && git fetch && git checkout $PROJECTBRANCH && git reset --hard origin/$PROJECTBRANCH && ./development/build-with-qmake.sh ${BUILD_TYPE} noclean /usr/lib/nixnote2/tidy browser && ./development/run-tests.sh ${BUILD_TYPE} noclean /usr/lib/nixnote2/tidy && ./development/create-AppImage-linuxdeploy.sh && mv *.AppImage appdir && chmod -R a+rwx appdir/*.AppImage" ls appdir/*.AppImage echo "If all got well then AppImage file in appdir is your binary" diff --git a/development/build-with-qmake.sh b/development/build-with-qmake.sh index aa2dea52..0153e495 100755 --- a/development/build-with-qmake.sh +++ b/development/build-with-qmake.sh @@ -6,6 +6,7 @@ set -xe BUILD_TYPE=${1} CLEAN=${2} TIDY_LIB_DIR=${3} +OAUTH_BACKEND=${4} CDIR=`pwd` function error_exit { @@ -44,6 +45,15 @@ if [ ! -d "${TIDY_LIB_DIR}" ]; then fi echo "$0: libtidy is expected in: ${TIDY_LIB_DIR}" +if [ -z "${OAUTH_BACKEND}" ] || [ "${OAUTH_BACKEND}" == "browser" ]; then + # by default will use system browser for OAuth because it's the simplest and working option + OAUTH_CONFIG="" +elif [ "${OAUTH_BACKEND}" == "webengine" ]; then + OAUTH_CONFIG="CONFIG+=oauth_webengine" +else + OAUTH_CONFIG="CONFIG+=oauth_webkit" +fi + if [ ! -d "${BUILD_DIR}" ]; then mkdir ${BUILD_DIR} fi @@ -56,7 +66,6 @@ if [ -d "${APPDIR}" ]; then rm *.AppImage 2>/dev/null || echo "failed to remove" fi - QMAKE_BINARY=qmake if [ "${TIDY_LIB_DIR}" == "/usr/lib" ] ; then @@ -71,10 +80,10 @@ elif [ -d ${TIDY_LIB_DIR}/pkgconfig ] ; then export PKG_CONFIG_PATH=${TIDY_LIB_DIR}/pkgconfig fi +echo ${QMAKE_BINARY} CONFIG+=${BUILD_TYPE} ${OAUTH_CONFIG} PREFIX=appdir/usr QMAKE_RPATHDIR+=${TIDY_LIB_DIR} QMAKE_CXX="ccache g++" || error_exit "$0: qmake" +${QMAKE_BINARY} CONFIG+=${BUILD_TYPE} ${OAUTH_CONFIG} PREFIX=appdir/usr QMAKE_RPATHDIR+=${TIDY_LIB_DIR} QMAKE_CXX="ccache g++" || error_exit "$0: qmake" -echo ${QMAKE_BINARY} CONFIG+=${BUILD_TYPE} PREFIX=appdir/usr QMAKE_RPATHDIR+=${TIDY_LIB_DIR} || error_exit "$0: qmake" -${QMAKE_BINARY} CONFIG+=${BUILD_TYPE} PREFIX=appdir/usr QMAKE_RPATHDIR+=${TIDY_LIB_DIR} || error_exit "$0: qmake" - +make clean make -j$(nproc) || error_exit "$0: make" make -j$(nproc) install || error_exit "$0: make install" diff --git a/development/create-AppImage-linuxdeploy.sh b/development/create-AppImage-linuxdeploy.sh new file mode 100755 index 00000000..07f8b640 --- /dev/null +++ b/development/create-AppImage-linuxdeploy.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +PROG=nixnote2 +DESKTOP_FILE=appdir/usr/share/applications/${PROG}.desktop + +BUILD_DIR=$(cat _build_dir_.txt) +echo Build dir: ${BUILD_DIR} + +if [ ! -f "$DESKTOP_FILE" ]; then + echo "$DESKTOP_FILE not found!" + exit 1 +fi + +export VERSIONX=$(cat appdir/usr/share/nixnote2/version.txt) +echo Version: ${VERSIONX} + +# First, create appdir with bundled binaries +CMD="linuxdeploy --desktop-file=$DESKTOP_FILE --appdir=appdir --plugin qt" +echo About to run: $CMD +$CMD + +# Then remove nss libs from the AppDir as they are known to cause troubles, see +# https://github.com/probonopd/linuxdeployqt/issues/35 +rm -f appdir/usr/lib/libnss3.so +rm -f appdir/usr/lib/libnssutil3.so + +# Now create the actual appimage +echo "Creating AppImage" +appimagetool -n appdir diff --git a/development/docker/Dockerfile.ubuntu_focal b/development/docker/Dockerfile.ubuntu_focal new file mode 100644 index 00000000..17ffc493 --- /dev/null +++ b/development/docker/Dockerfile.ubuntu_focal @@ -0,0 +1,41 @@ +FROM ubuntu:focal + +ARG wdir="/opt" +WORKDIR $wdir + +ARG make_core=4 +ENV PATH="${wdir}/linuxdeploy:${wdir}/linuxdeploy-plugin-qt:${wdir}/appimagetool:${PATH}" +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y software-properties-common +RUN add-apt-repository ppa:nixnote/nixnote2-stable -y && apt-get update -qq +RUN apt-get update && apt-get install -y git-core qt5-default build-essential ccache p7zip-full libssl1.1 libcrypt1 libnss3 \ + wget curl make pkg-config \ + qtwebengine5-dev qtwebengine5-dev-tools \ + libboost-dev libboost-test-dev libboost-program-options-dev libevent-dev libcurl4-openssl-dev \ + libpoppler-qt5-dev libqt5webkit5-dev qt5-qmake qttools5-dev-tools libhunspell-dev nixnote2-tidy + +# install linuxdeploy +RUN wget -nv "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage" && \ + chmod a+x ./linuxdeploy-x86_64.AppImage && \ + ./linuxdeploy-x86_64.AppImage --appimage-extract && \ + mv squashfs-root linuxdeploy && \ + mv linuxdeploy/AppRun linuxdeploy/linuxdeploy + +# install linuxdeploy-plugin-qt +RUN wget -nv "https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage" && \ + chmod a+x ./linuxdeploy-plugin-qt-x86_64.AppImage && \ + ./linuxdeploy-plugin-qt-x86_64.AppImage --appimage-extract && \ + mv squashfs-root linuxdeploy-plugin-qt && \ + mv linuxdeploy-plugin-qt/AppRun linuxdeploy-plugin-qt/linuxdeploy-plugin-qt + +# install appimagetool +RUN wget -nv "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" && \ + chmod a+x appimagetool-x86_64.AppImage && \ + ./appimagetool-x86_64.AppImage --appimage-extract && \ + mv squashfs-root appimagetool && \ + mv appimagetool/AppRun appimagetool/appimagetool + +RUN cd $wdir && git clone "https://github.com/robert7/nixnote2.git" && cd nixnote2 && git checkout master + +CMD /bin/bash From bc01c36c4113c4eaede65f25dbdea85c26e7064f Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Mon, 17 Apr 2023 22:41:13 +0300 Subject: [PATCH 5/7] Issue #171: fix UserStore initialization --- src/communication/communicationmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/communication/communicationmanager.cpp b/src/communication/communicationmanager.cpp index b3a0de19..00892bc3 100644 --- a/src/communication/communicationmanager.cpp +++ b/src/communication/communicationmanager.cpp @@ -173,7 +173,7 @@ bool CommunicationManager::getUserInfo(User &user) { QLOG_DEBUG() << "CommunicationManager.getUserInfo(): new UserStore(); host=" << evernoteHost; QLOG_TRACE() << "token=" << authToken; - userStore = newUserStore(evernoteHost, newRequestContext(authToken, requestTimeout)); + userStore = newUserStore(QString("https://") + evernoteHost + QString("/edam/user"), newRequestContext(authToken, requestTimeout)); bool res = true; try { From c3c024ead21dc140b038a25d26f99ca7d508775f Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Mon, 17 Apr 2023 22:48:02 +0300 Subject: [PATCH 6/7] Issue #171: Update Travis CI configuration --- .travis.yml | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index a3eda34c..cbe23077 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,9 @@ language: cpp compiler: gcc sudo: require -dist: xenial +dist: focal before_install: - - sudo add-apt-repository ppa:nixnote/nixnote2-stable -y - sudo apt-get update -qq install: @@ -13,35 +12,44 @@ install: wget curl make pkg-config \ libboost-dev libboost-test-dev libboost-program-options-dev libevent-dev libcurl4-openssl-dev \ libpoppler-qt5-dev libqt5webkit5-dev qt5-qmake qttools5-dev-tools libqt5sql5-sqlite \ - libhunspell-dev \ - nixnote2-tidy + libhunspell-dev libtidy-dev libqt5positioning5-plugins script: - - #ls -lR /opt/tidy56 - - export TIDY_LIB_DIR=/usr/lib/nixnote2/tidy - - export PKG_CONFIG_PATH=$TIDY_LIB_DIR/pkgconfig - - echo PKG_CONFIG_PATH=$PKG_CONFIG_PATH - - echo qmake CONFIG+=release PREFIX=/usr QMAKE_RPATHDIR+=$TIDY_LIB_DIR + - echo qmake CONFIG+=release PREFIX=/usr - | - qmake CONFIG+=release PREFIX=/usr QMAKE_RPATHDIR+=$TIDY_LIB_DIR && + qmake CONFIG+=release PREFIX=/usr && ls -l ./development && make -j$(nproc) && make INSTALL_ROOT=appdir -j$(nproc) install && find appdir/ && - qmake testsrc/tests.pro CONFIG+=release PREFIX=/usr QMAKE_RPATHDIR+=$TIDY_LIB_DIR && + qmake testsrc/tests.pro CONFIG+=release PREFIX=/usr && make && ./qmake-build-release-t/tests -platform offscreen - - wget -c "https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage" - - chmod a+x linuxdeployqt*.AppImage - - unset QTDIR; unset QT_PLUGIN_PATH ; unset LD_LIBRARY_PATH - - ./linuxdeployqt*.AppImage ./appdir/usr/share/applications/*.desktop -bundle-non-qt-libs - - ./linuxdeployqt*.AppImage --appimage-extract - - export PATH=$(readlink -f ./squashfs-root/usr/bin/):$PATH - - ./squashfs-root/usr/bin/appimagetool appdir/ - + - | + wget -nv "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage" && \ + chmod a+x ./linuxdeploy-x86_64.AppImage && \ + ./linuxdeploy-x86_64.AppImage --appimage-extract && \ + mv squashfs-root linuxdeploy && \ + mv linuxdeploy/AppRun linuxdeploy/linuxdeploy + - | + wget -nv "https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage" && \ + chmod a+x ./linuxdeploy-plugin-qt-x86_64.AppImage && \ + ./linuxdeploy-plugin-qt-x86_64.AppImage --appimage-extract && \ + mv squashfs-root linuxdeploy-plugin-qt && \ + mv linuxdeploy-plugin-qt/AppRun linuxdeploy-plugin-qt/linuxdeploy-plugin-qt + - | + wget -nv "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" && \ + chmod a+x appimagetool-x86_64.AppImage && \ + ./appimagetool-x86_64.AppImage --appimage-extract && \ + mv squashfs-root appimagetool && \ + mv appimagetool/AppRun appimagetool/appimagetool + - export PATH=linuxdeploy:linuxdeploy-plugin-qt:appimagetool:$PATH + - linuxdeploy --desktop-file=./appdir/usr/share/applications/nixnote2.desktop --appdir=appdir --plugin qt + - rm -f appdir/usr/lib/libnss3.so + - rm -f appdir/usr/lib/libnssutil3.so + - appimagetool -n appdir after_success: - - find appdir -executable -type f -exec ldd {} \; | grep " => /usr" | cut -d " " -f 2-3 | sort | uniq - wget -c https://github.com/probonopd/uploadtool/raw/master/upload.sh - #wget -c https://raw.githubusercontent.com/robert7/uploadtool/temp/upload.sh - | From 1a75e6c093fe08329899a28ee7d8272dfae1ed41 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Mon, 17 Apr 2023 23:21:53 +0300 Subject: [PATCH 7/7] Issue #171: attempt to fix checkout for build-with-docker.sh --- development/build-with-docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/development/build-with-docker.sh b/development/build-with-docker.sh index e1d561e2..76d5b381 100755 --- a/development/build-with-docker.sh +++ b/development/build-with-docker.sh @@ -49,7 +49,7 @@ time docker run \ -v $PROJECTDIR/docker-build-${BUILD_TYPE}:/opt/nixnote2/qmake-build-${BUILD_TYPE} \ -v $PROJECTDIR/docker-build-${BUILD_TYPE}-t:/opt/nixnote2/qmake-build-${BUILD_TYPE}-t \ -it ${DOCKERTAG} \ - /bin/bash -c "cd nixnote2 && git fetch && git checkout $PROJECTBRANCH && git reset --hard origin/$PROJECTBRANCH && ./development/build-with-qmake.sh ${BUILD_TYPE} noclean /usr/lib/nixnote2/tidy browser && ./development/run-tests.sh ${BUILD_TYPE} noclean /usr/lib/nixnote2/tidy && ./development/create-AppImage-linuxdeploy.sh && mv *.AppImage appdir && chmod -R a+rwx appdir/*.AppImage" + /bin/bash -c "cd nixnote2 && git fetch && git checkout --track origin/$PROJECTBRANCH && git reset --hard origin/$PROJECTBRANCH && ./development/build-with-qmake.sh ${BUILD_TYPE} noclean /usr/lib/nixnote2/tidy browser && ./development/run-tests.sh ${BUILD_TYPE} noclean /usr/lib/nixnote2/tidy && ./development/create-AppImage-linuxdeploy.sh && mv *.AppImage appdir && chmod -R a+rwx appdir/*.AppImage" ls appdir/*.AppImage echo "If all got well then AppImage file in appdir is your binary"