ctkXnatSession.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*=============================================================================
  2. Library: XNAT/Core
  3. Copyright (c) University College London,
  4. Centre for Medical Image Computing
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKXNATSESSION_H
  16. #define CTKXNATSESSION_H
  17. #include "ctkXNATCoreExport.h"
  18. #include <QScopedPointer>
  19. #include <QString>
  20. #include <QObject>
  21. #include <QVariantMap>
  22. #include <QUuid>
  23. class QDateTime;
  24. class ctkXnatSessionPrivate;
  25. class ctkXnatFile;
  26. class ctkXnatLoginProfile;
  27. class ctkXnatDataModel;
  28. class ctkXnatObject;
  29. class ctkXnatResource;
  30. /**
  31. * @ingroup XNAT_Core
  32. *
  33. * @brief The ctkXnatSession class reprents a session object associated
  34. * with a specific XNAT connection.
  35. */
  36. class CTK_XNAT_CORE_EXPORT ctkXnatSession : public QObject
  37. {
  38. Q_OBJECT
  39. public:
  40. typedef QMap<QString, QString> UrlParameters;
  41. typedef QMap<QByteArray, QByteArray> HttpRawHeaders;
  42. ctkXnatSession(const ctkXnatLoginProfile& loginProfile);
  43. ~ctkXnatSession();
  44. /**
  45. * @brief Open a new XNAT session.
  46. *
  47. * This method must be called on all ctkXnatSession objects before
  48. * any of the methods which communicate with an XNAT server are called.
  49. *
  50. * If the session has already been opened, this method does nothing.
  51. *
  52. * @throws ctkXnatAuthenticationException if the user credentials are invalid.
  53. * @throws ctkXnatException (or one of its subclasses) if a network error occurred.
  54. */
  55. void open();
  56. /**
  57. * @brief Closes this XNAT session.
  58. */
  59. void close();
  60. /**
  61. * @brief Returns the open state of this XNAT session.
  62. * @return \c true if the session is open, \c false otherwise.
  63. */
  64. bool isOpen() const;
  65. /**
  66. * @brief Get the XNAT server version.
  67. * @return The XNAT version running on the remote server. Returns a null string
  68. * if the session is not open.
  69. */
  70. QString version() const;
  71. /**
  72. * @brief Get the expiration date for this XNAT session.
  73. *
  74. * @sa renew()
  75. * @throws ctkXnatInvalidSessionException if the session is closed.
  76. * @return The session expiration date.
  77. */
  78. QDateTime expirationDate() const;
  79. /**
  80. * @brief Re-new the XNAT session.
  81. * @throws ctkXnatInvalidSessionException if the session is closed.
  82. * @return The new session expiration data.
  83. */
  84. QDateTime renew();
  85. /**
  86. * @brief Get the current login profile for this session object.
  87. * @return A copy of the currently used login profile.
  88. */
  89. ctkXnatLoginProfile loginProfile() const;
  90. /**
  91. * @brief Get XNAT server url.
  92. *
  93. * The url is the one specified by the login profile.
  94. *
  95. * @return The XNAT server url.
  96. */
  97. QUrl url() const;
  98. /**
  99. * @brief Get the user name for this XNAT session.
  100. *
  101. * The user name is the one specified by the login profile.
  102. *
  103. * @return The XNAT session user name.
  104. */
  105. QString userName() const;
  106. /**
  107. * @brief Get the password for this XNAT session.
  108. *
  109. * The password is the one specified by the login profile.
  110. *
  111. * @return The XNAT session password.
  112. */
  113. QString password() const;
  114. /**
  115. * @brief Get the sessionId for this XNAT session.
  116. *
  117. * @return The XNAT sessionId.
  118. */
  119. QString sessionId() const;
  120. ctkXnatDataModel* dataModel() const;
  121. /**
  122. * @brief TODO
  123. * @param resource
  124. * @param parameters
  125. * @param rawHeaders
  126. *
  127. * @throws ctkXnatInvalidSessionException if the session is closed.
  128. * @return
  129. */
  130. QUuid httpGet(const QString& resource,
  131. const UrlParameters& parameters = UrlParameters(),
  132. const HttpRawHeaders& rawHeaders = HttpRawHeaders());
  133. /**
  134. * @brief TODO
  135. * @param uuid
  136. * @param schemaType
  137. *
  138. * @throws ctkXnatInvalidSessionException if the session is closed.
  139. * @return
  140. */
  141. QList<ctkXnatObject*> httpResults(const QUuid& uuid, const QString& schemaType);
  142. /**
  143. * @brief TODO
  144. * @param uuid
  145. *
  146. * @throws ctkXnatInvalidSessionException if the session is closed.
  147. * @return
  148. */
  149. QList<QVariantMap> httpSync(const QUuid& uuid);
  150. /**
  151. * @brief Reads the result of a head request
  152. * @param uuid the uid of the related query
  153. *
  154. * @throws ctkXnatInvalidSessionException if the session is closed.
  155. * @return a QMap containing the retrieved header information
  156. */
  157. const QMap<QByteArray, QByteArray> httpHeadSync(const QUuid& uuid);
  158. bool exists(const ctkXnatObject* object);
  159. void save(ctkXnatObject* object);
  160. void remove(ctkXnatObject* object);
  161. void download(ctkXnatFile* file, const QString& fileName);
  162. // void downloadScanFiles(ctkXnatExperiment* experiment, const QString& zipFileName);
  163. // void downloadReconstructionFiles(ctkXnatExperiment* experiment, const QString& zipFileName);
  164. // void download(ctkXnatScan* scan, const QString& zipFileName);
  165. void download(ctkXnatResource* resource, const QString& zipFileName);
  166. /**
  167. * @brief Sends a http HEAD request to the xnat instance
  168. * @param resourceUri the URL to the server
  169. * @return the query uid
  170. */
  171. QUuid httpHead(const QString& resourceUri);
  172. // void downloadReconstruction(ctkXnatReconstruction* reconstruction, const QString& zipFilename);
  173. // void downloadReconstructionResourceFiles(ctkXnatReconstructionResource* reconstructionResource, const QString& zipFilename);
  174. // void download(ctkXnatReconstructionResourceFile* reconstructionResourceFile, const QString& zipFileName);
  175. /**
  176. * @brief Signals that the session was re-newed.
  177. * @param expirationDate The new session expiration date.
  178. */
  179. Q_SIGNAL void sessionRenewed(const QDateTime& expirationDate);
  180. /**
  181. * @brief Signals that the session was just opened.
  182. */
  183. Q_SIGNAL void sessionOpened();
  184. /**
  185. * @brief Signals that the session is about to be closed.
  186. */
  187. Q_SIGNAL void sessionAboutToBeClosed();
  188. public slots:
  189. void processResult(QUuid queryId, QList<QVariantMap> parameters);
  190. void progress(QUuid queryId, double progress);
  191. protected:
  192. QScopedPointer<ctkXnatSessionPrivate> d_ptr;
  193. private:
  194. Q_DECLARE_PRIVATE(ctkXnatSession)
  195. Q_DISABLE_COPY(ctkXnatSession)
  196. };
  197. #endif