ctkXnatObject.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 ctkXnatObject_h
  16. #define ctkXnatObject_h
  17. #include "ctkXNATCoreExport.h"
  18. #include "ctkException.h"
  19. #include <QList>
  20. #include <QObject>
  21. #include <QString>
  22. #include <QMetaType>
  23. class ctkXnatResource;
  24. class ctkXnatSession;
  25. class ctkXnatObjectPrivate;
  26. /**
  27. * @ingroup XNAT_Core
  28. *
  29. * ctkXnatObject is the base class of the objects that represent the nodes in
  30. * the XNAT data hierarchy.
  31. */
  32. class CTK_XNAT_CORE_EXPORT ctkXnatObject
  33. {
  34. public:
  35. /// Destructs the ctkXnatObject.
  36. virtual ~ctkXnatObject();
  37. /// Gets the global ID of the object.
  38. virtual QString id() const;
  39. /// Sets the ID of the object.
  40. /// @warning You must not change the ID of an existing object
  41. virtual void setId(const QString& id);
  42. /// Gets the resource URI of the object that can be used to access it through
  43. /// the REST API.
  44. virtual QString resourceUri() const = 0;
  45. /// Gets the name of the object.
  46. virtual QString name() const;
  47. /// Sets the name of the object.
  48. virtual void setName(const QString& name);
  49. /// Gets the description of the object.
  50. QString description() const;
  51. /// Sets the description of the object.
  52. void setDescription(const QString& description);
  53. /// Gets the value of the property with the given name.
  54. QString property(const QString& name) const;
  55. /// Sets the value of the property with the given name.
  56. void setProperty(const QString& name, const QVariant& value);
  57. /// Gets the last modification time from the server
  58. virtual QDateTime lastModifiedTimeOnServer();
  59. /// Sets the last modfication time on the server
  60. void setLastModifiedTime(const QDateTime& lastModifiedTime);
  61. /// Gets the properties of the object.
  62. const QMap<QString, QString>& properties() const;
  63. /// Gets the parent of the object in the data hierarchy. The returned pointer
  64. /// is 0 for the ctkXnatServer objects and different for any other type of
  65. /// XNAT objects.
  66. ctkXnatObject* parent() const;
  67. /// Sets the parent of the object in the data hierarchy.
  68. void setParent(ctkXnatObject* parent);
  69. /// Gets the children of the object.
  70. QList<ctkXnatObject*> children() const;
  71. /// Adds an object to the children of the current one.
  72. void add(ctkXnatObject* child);
  73. /// Removes the object from the children of the current object.
  74. void remove(ctkXnatObject* child);
  75. /// Tells if the children and the properties of the objects have been fetched.
  76. bool isFetched() const;
  77. QString schemaType() const;
  78. /// Gets a human readable name of the child object type.
  79. virtual QString childDataType() const;
  80. /// Resets the object so that its properties and children needs to be fetched
  81. /// again at the next request.
  82. virtual void reset();
  83. /// Fetches the children and the properties of the object.
  84. void fetch();
  85. /// Checks if the object exists on the XNAT server.
  86. bool exists() const;
  87. /// Creates the object on the XNAT server and sets the new ID.
  88. /// @param overwrite, if true and the object already exists on the server
  89. /// it will be overwritten by the changes
  90. void save(bool overwrite = true);
  91. /// Deletes the object on the XNAT server and removes it from its parent.
  92. void erase();
  93. void download(const QString&);
  94. /// Creates the object on the XNAT server and sets the new ID.
  95. virtual ctkXnatResource* addResourceFolder(QString foldername,
  96. QString format = "", QString content = "", QString tags = "");
  97. //QObject* asyncObject() const;
  98. // *********************
  99. // Add signals for async API
  100. //Q_SIGNAL downloadFinished(const QString&);
  101. // *********************
  102. // SLOTS for async error handling
  103. //Q_SLOT serverError(XnatError errorType, const QString& message);
  104. // *********************
  105. // Add blocking methods
  106. // throws ctkXnatTimeoutException
  107. //bool waitForDownloadFinished(const QString&);
  108. static const QString ID;
  109. static const QString NAME;
  110. static const QString LABEL;
  111. protected:
  112. ctkXnatObject(const ctkXnatObject&);
  113. /// Constructs the ctkXnatObject.
  114. ctkXnatObject(ctkXnatObject* parent = 0, const QString& schemaType = QString::null);
  115. /// Constructs the ctkXnatObject with the given private part.
  116. ctkXnatObject(ctkXnatObjectPrivate& dd, ctkXnatObject* parent = 0, const QString& schemaType = QString::null);
  117. /// Gets the object that represents the connection to the XNAT server
  118. /// that stores the current object.
  119. ctkXnatSession* session() const;
  120. /// Fetches the resources of the object
  121. virtual void fetchResources(const QString &path = "/resources");
  122. /// The private implementation part of the object.
  123. const QScopedPointer<ctkXnatObjectPrivate> d_ptr;
  124. private:
  125. friend class ctkXnatSessionPrivate;
  126. void setSchemaType(const QString& schemaType);
  127. /// The implementation of the fetch mechanism, called by the fetch() function.
  128. virtual void fetchImpl() = 0;
  129. /// The implementation of the download mechanism, called by the download(const QString&) function.
  130. virtual void downloadImpl(const QString&) = 0;
  131. /// The implementation of the upload mechanism, called by the save() function.
  132. /// Subclasses of ctkXnatObject can overwrite this function if needed
  133. /// @param overwrite, if true and the object already exists on the server
  134. /// it will be overwritten by the changes
  135. virtual void saveImpl(bool overwrite = true);
  136. Q_DECLARE_PRIVATE(ctkXnatObject)
  137. };
  138. Q_DECLARE_METATYPE(ctkXnatObject*)
  139. #endif