ctkXnatSession.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. ctkXnatDataModel* dataModel() const;
  115. /**
  116. * @brief TODO
  117. * @param resource
  118. * @param parameters
  119. * @param rawHeaders
  120. *
  121. * @throws ctkXnatInvalidSessionException if the session is closed.
  122. * @return
  123. */
  124. QUuid httpGet(const QString& resource,
  125. const UrlParameters& parameters = UrlParameters(),
  126. const HttpRawHeaders& rawHeaders = HttpRawHeaders());
  127. /**
  128. * @brief TODO
  129. * @param uuid
  130. * @param schemaType
  131. *
  132. * @throws ctkXnatInvalidSessionException if the session is closed.
  133. * @return
  134. */
  135. QList<ctkXnatObject*> httpResults(const QUuid& uuid, const QString& schemaType);
  136. /**
  137. * @brief TODO
  138. * @param uuid
  139. *
  140. * @throws ctkXnatInvalidSessionException if the session is closed.
  141. * @return
  142. */
  143. QList<QVariantMap> httpSync(const QUuid& uuid);
  144. /**
  145. * @brief Reads the result of a head request
  146. * @param uuid the uid of the related query
  147. *
  148. * @throws ctkXnatInvalidSessionException if the session is closed.
  149. * @return a QMap containing the retrieved header information
  150. */
  151. const QMap<QByteArray, QByteArray> httpHeadSync(const QUuid& uuid);
  152. bool exists(const ctkXnatObject* object);
  153. void save(ctkXnatObject* object);
  154. void remove(ctkXnatObject* object);
  155. void download(ctkXnatFile* file, const QString& fileName);
  156. // void downloadScanFiles(ctkXnatExperiment* experiment, const QString& zipFileName);
  157. // void downloadReconstructionFiles(ctkXnatExperiment* experiment, const QString& zipFileName);
  158. // void download(ctkXnatScan* scan, const QString& zipFileName);
  159. void download(ctkXnatResource* resource, const QString& zipFileName);
  160. /**
  161. * @brief Sends a http HEAD request to the xnat instance
  162. * @param resourceUri the URL to the server
  163. * @return the query uid
  164. */
  165. QUuid httpHead(const QString& resourceUri);
  166. // void downloadReconstruction(ctkXnatReconstruction* reconstruction, const QString& zipFilename);
  167. // void downloadReconstructionResourceFiles(ctkXnatReconstructionResource* reconstructionResource, const QString& zipFilename);
  168. // void download(ctkXnatReconstructionResourceFile* reconstructionResourceFile, const QString& zipFileName);
  169. /**
  170. * @brief Signals that the session was re-newed.
  171. * @param expirationDate The new session expiration date.
  172. */
  173. Q_SIGNAL void sessionRenewed(const QDateTime& expirationDate);
  174. public slots:
  175. void processResult(QUuid queryId, QList<QVariantMap> parameters);
  176. void progress(QUuid queryId, double progress);
  177. protected:
  178. QScopedPointer<ctkXnatSessionPrivate> d_ptr;
  179. private:
  180. Q_DECLARE_PRIVATE(ctkXnatSession)
  181. Q_DISABLE_COPY(ctkXnatSession)
  182. };
  183. #endif