ctkXnatSession.h 5.9 KB

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