ctkXnatObject.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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(bool forceFetch = false);
  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 a new resource folder with the given foldername, format, content and tags
  95. /// for this ctkXnatObject on the server.
  96. /// @param foldername the name of the resource folder on the server (mandatory)
  97. /// @param format the text of the format field of a resource (optional)
  98. /// @param content the text of the content field of a resource (optional)
  99. /// @param tags the content of the tags field of a resource (optional)
  100. /// @returns ctkXnatResource the created resource
  101. virtual ctkXnatResource* addResourceFolder(QString foldername,
  102. QString format = "", QString content = "", QString tags = "");
  103. //QObject* asyncObject() const;
  104. // *********************
  105. // Add signals for async API
  106. //Q_SIGNAL downloadFinished(const QString&);
  107. // *********************
  108. // SLOTS for async error handling
  109. //Q_SLOT serverError(XnatError errorType, const QString& message);
  110. // *********************
  111. // Add blocking methods
  112. // throws ctkXnatTimeoutException
  113. //bool waitForDownloadFinished(const QString&);
  114. static const QString ID;
  115. static const QString NAME;
  116. static const QString LABEL;
  117. static const QString URI;
  118. static const QString XSI_SCHEMA_TYPE;
  119. protected:
  120. ctkXnatObject(const ctkXnatObject&);
  121. /// Constructs the ctkXnatObject.
  122. ctkXnatObject(ctkXnatObject* parent = 0, const QString& schemaType = QString::null);
  123. /// Constructs the ctkXnatObject with the given private part.
  124. ctkXnatObject(ctkXnatObjectPrivate& dd, ctkXnatObject* parent = 0, const QString& schemaType = QString::null);
  125. /// Gets the object that represents the connection to the XNAT server
  126. /// that stores the current object.
  127. ctkXnatSession* session() const;
  128. /// Fetches the resources of the object
  129. virtual void fetchResources(const QString &path = "/resources");
  130. /// The private implementation part of the object.
  131. const QScopedPointer<ctkXnatObjectPrivate> d_ptr;
  132. private:
  133. friend class ctkXnatSessionPrivate;
  134. void setSchemaType(const QString& schemaType);
  135. /// The implementation of the fetch mechanism, called by the fetch() function.
  136. virtual void fetchImpl() = 0;
  137. /// The implementation of the download mechanism, called by the download(const QString&) function.
  138. virtual void downloadImpl(const QString&) = 0;
  139. /// The implementation of the upload mechanism, called by the save() function.
  140. /// Subclasses of ctkXnatObject can overwrite this function if needed
  141. /// @param overwrite, if true and the object already exists on the server
  142. /// it will be overwritten by the changes
  143. virtual void saveImpl(bool overwrite = true);
  144. Q_DECLARE_PRIVATE(ctkXnatObject)
  145. };
  146. Q_DECLARE_METATYPE(ctkXnatObject*)
  147. #endif