ctkXnatDataModel.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #include "ctkXnatDataModel.h"
  16. #include "ctkXnatObjectPrivate.h"
  17. #include "ctkXnatSession.h"
  18. #include "ctkXnatProject.h"
  19. #include "ctkXnatDefaultSchemaTypes.h"
  20. #include <QDebug>
  21. // --------------------------------------------------------------------------
  22. class ctkXnatDataModelPrivate : public ctkXnatObjectPrivate
  23. {
  24. explicit ctkXnatDataModelPrivate(ctkXnatSession* session);
  25. virtual ~ctkXnatDataModelPrivate();
  26. private:
  27. friend class ctkXnatDataModel;
  28. ctkXnatSession* session;
  29. };
  30. // --------------------------------------------------------------------------
  31. ctkXnatDataModelPrivate::ctkXnatDataModelPrivate(ctkXnatSession* connection)
  32. : ctkXnatObjectPrivate()
  33. , session(connection)
  34. {
  35. }
  36. // --------------------------------------------------------------------------
  37. ctkXnatDataModelPrivate::~ctkXnatDataModelPrivate()
  38. {
  39. }
  40. // --------------------------------------------------------------------------
  41. ctkXnatDataModel::ctkXnatDataModel(ctkXnatSession* session)
  42. : ctkXnatObject(*new ctkXnatDataModelPrivate(session))
  43. {
  44. }
  45. // --------------------------------------------------------------------------
  46. QList<ctkXnatProject*> ctkXnatDataModel::projects() const
  47. {
  48. QList<ctkXnatProject*> result;
  49. foreach(ctkXnatObject* obj, this->children())
  50. {
  51. result.push_back(static_cast<ctkXnatProject*>(obj));
  52. }
  53. return result;
  54. }
  55. // --------------------------------------------------------------------------
  56. QString ctkXnatDataModel::resourceUri() const
  57. {
  58. return "";
  59. }
  60. // --------------------------------------------------------------------------
  61. QString ctkXnatDataModel::childDataType() const
  62. {
  63. return "Projects";
  64. }
  65. // --------------------------------------------------------------------------
  66. ctkXnatSession* ctkXnatDataModel::session() const
  67. {
  68. Q_D(const ctkXnatDataModel);
  69. return d->session;
  70. }
  71. // --------------------------------------------------------------------------
  72. void ctkXnatDataModel::fetchImpl()
  73. {
  74. Q_D(ctkXnatDataModel);
  75. QString projectsUri("/data/archive/projects");
  76. QUuid queryId = d->session->httpGet(projectsUri);
  77. QList<ctkXnatObject*> projects = d->session->httpResults(queryId,
  78. ctkXnatDefaultSchemaTypes::XSI_PROJECT);
  79. qDebug() << "ctkXnatDataModel::fetchImpl(): project number:" << projects.size();
  80. foreach (ctkXnatObject* project, projects)
  81. {
  82. this->add(project);
  83. }
  84. }
  85. //----------------------------------------------------------------------------
  86. void ctkXnatDataModel::downloadImpl(const QString& filename)
  87. {
  88. qDebug() << "ctkXnatDataModel::downloadImpl(const QString& filename) not yet implemented or not available by REST API";
  89. }