ctkXnatSession.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 ctkXnatScanResource;
  30. class ctkXnatReconstructionResource;
  31. /**
  32. * @ingroup XNAT_Core
  33. *
  34. * @brief The ctkXnatSession class reprents a session object associated
  35. * with a specific XNAT connection.
  36. */
  37. class CTK_XNAT_CORE_EXPORT ctkXnatSession : public QObject
  38. {
  39. Q_OBJECT
  40. public:
  41. typedef QMap<QString, QString> UrlParameters;
  42. typedef QMap<QByteArray, QByteArray> HttpRawHeaders;
  43. ctkXnatSession(const ctkXnatLoginProfile& loginProfile);
  44. ~ctkXnatSession();
  45. /**
  46. * @brief Open a new XNAT session.
  47. *
  48. * This method must be called on all ctkXnatSession objects before
  49. * any of the methods which communicate with an XNAT server are called.
  50. *
  51. * If the session has already been opened, this method does nothing.
  52. *
  53. * @throws ctkXnatAuthenticationException if the user credentials are invalid.
  54. * @throws ctkXnatException (or one of its subclasses) if a network error occurred.
  55. */
  56. void open();
  57. /**
  58. * @brief Closes this XNAT session.
  59. */
  60. void close();
  61. /**
  62. * @brief Returns the open state of this XNAT session.
  63. * @return \c true if the session is open, \c false otherwise.
  64. */
  65. bool isOpen() const;
  66. /**
  67. * @brief Get the XNAT server version.
  68. * @return The XNAT version running on the remote server. Returns a null string
  69. * if the session is not open.
  70. */
  71. QString version() const;
  72. /**
  73. * @brief Get the expiration date for this XNAT session.
  74. *
  75. * @sa renew()
  76. * @throws ctkXnatInvalidSessionException if the session is closed.
  77. * @return The session expiration date.
  78. */
  79. QDateTime expirationDate() const;
  80. /**
  81. * @brief Re-new the XNAT session.
  82. * @throws ctkXnatInvalidSessionException if the session is closed.
  83. * @return The new session expiration data.
  84. */
  85. QDateTime renew();
  86. /**
  87. * @brief Get the current login profile for this session object.
  88. * @return A copy of the currently used login profile.
  89. */
  90. ctkXnatLoginProfile loginProfile() const;
  91. /**
  92. * @brief Get XNAT server url.
  93. *
  94. * The url is the one specified by the login profile.
  95. *
  96. * @return The XNAT server url.
  97. */
  98. QUrl url() const;
  99. /**
  100. * @brief Get the user name for this XNAT session.
  101. *
  102. * The user name is the one specified by the login profile.
  103. *
  104. * @return The XNAT session user name.
  105. */
  106. QString userName() const;
  107. /**
  108. * @brief Get the password for this XNAT session.
  109. *
  110. * The password is the one specified by the login profile.
  111. *
  112. * @return The XNAT session password.
  113. */
  114. QString password() const;
  115. ctkXnatDataModel* dataModel() const;
  116. /**
  117. * @brief TODO
  118. * @param resource
  119. * @param parameters
  120. * @param rawHeaders
  121. *
  122. * @throws ctkXnatInvalidSessionException if the session is closed.
  123. * @return
  124. */
  125. QUuid httpGet(const QString& resource,
  126. const UrlParameters& parameters = UrlParameters(),
  127. const HttpRawHeaders& rawHeaders = HttpRawHeaders());
  128. /**
  129. * @brief TODO
  130. * @param uuid
  131. * @param schemaType
  132. *
  133. * @throws ctkXnatInvalidSessionException if the session is closed.
  134. * @return
  135. */
  136. QList<ctkXnatObject*> httpResults(const QUuid& uuid, const QString& schemaType);
  137. /**
  138. * @brief TODO
  139. * @param uuid
  140. *
  141. * @throws ctkXnatInvalidSessionException if the session is closed.
  142. * @return
  143. */
  144. QList<QVariantMap> httpSync(const QUuid& uuid);
  145. /**
  146. * @brief Reads the result of a head request
  147. * @param uuid the uid of the related query
  148. *
  149. * @throws ctkXnatInvalidSessionException if the session is closed.
  150. * @return a QMap containing the retrieved header information
  151. */
  152. const QMap<QByteArray, QByteArray> httpHeadSync(const QUuid& uuid);
  153. bool exists(const ctkXnatObject* object);
  154. void save(ctkXnatObject* object);
  155. void remove(ctkXnatObject* object);
  156. void download(ctkXnatFile* file, const QString& fileName);
  157. // void downloadScanFiles(ctkXnatExperiment* experiment, const QString& zipFileName);
  158. // void downloadReconstructionFiles(ctkXnatExperiment* experiment, const QString& zipFileName);
  159. // void download(ctkXnatScan* scan, const QString& zipFileName);
  160. void download(ctkXnatScanResource* scanResource, const QString& zipFileName);
  161. void download(ctkXnatReconstructionResource* reconstructionResource, const QString& zipFileName);
  162. /**
  163. * @brief Sends a http HEAD request to the xnat instance
  164. * @param resourceUri the URL to the server
  165. * @return the query uid
  166. */
  167. QUuid httpHead(const QString& resourceUri);
  168. // void downloadReconstruction(ctkXnatReconstruction* reconstruction, const QString& zipFilename);
  169. // void downloadReconstructionResourceFiles(ctkXnatReconstructionResource* reconstructionResource, const QString& zipFilename);
  170. // void download(ctkXnatReconstructionResourceFile* reconstructionResourceFile, const QString& zipFileName);
  171. /**
  172. * @brief Signals that the session was re-newed.
  173. * @param expirationDate The new session expiration date.
  174. */
  175. Q_SIGNAL void sessionRenewed(const QDateTime& expirationDate);
  176. public slots:
  177. void processResult(QUuid queryId, QList<QVariantMap> parameters);
  178. void progress(QUuid queryId, double progress);
  179. protected:
  180. QScopedPointer<ctkXnatSessionPrivate> d_ptr;
  181. private:
  182. Q_DECLARE_PRIVATE(ctkXnatSession)
  183. Q_DISABLE_COPY(ctkXnatSession)
  184. };
  185. #endif