ctkXnatResource.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 "ctkXnatResource.h"
  16. #include "ctkXnatConstants.h"
  17. #include "ctkXnatObjectPrivate.h"
  18. #include "ctkXnatSession.h"
  19. //----------------------------------------------------------------------------
  20. class ctkXnatResourcePrivate : public ctkXnatObjectPrivate
  21. {
  22. public:
  23. ctkXnatResourcePrivate()
  24. : ctkXnatObjectPrivate()
  25. {
  26. }
  27. };
  28. //----------------------------------------------------------------------------
  29. ctkXnatResource::ctkXnatResource(ctkXnatObject* parent, const QString& schemaType)
  30. : ctkXnatObject(*new ctkXnatResourcePrivate(), parent, schemaType)
  31. {
  32. }
  33. //----------------------------------------------------------------------------
  34. ctkXnatResource::~ctkXnatResource()
  35. {
  36. }
  37. //----------------------------------------------------------------------------
  38. QString ctkXnatResource::resourceUri() const
  39. {
  40. return QString("%1/resources/%2").arg(parent()->resourceUri(), this->id());
  41. }
  42. //----------------------------------------------------------------------------
  43. QString ctkXnatResource::id() const
  44. {
  45. return property(ctkXnatObjectFields::ABSTRACT_RESOURCE_ID);
  46. }
  47. //----------------------------------------------------------------------------
  48. void ctkXnatResource::setId(const QString &id)
  49. {
  50. setProperty(ctkXnatObjectFields::ABSTRACT_RESOURCE_ID, id);
  51. }
  52. //----------------------------------------------------------------------------
  53. QString ctkXnatResource::name() const
  54. {
  55. return property(ctkXnatObjectFields::LABEL);
  56. }
  57. //----------------------------------------------------------------------------
  58. void ctkXnatResource::setName(const QString &name)
  59. {
  60. setProperty(ctkXnatObjectFields::LABEL, name);
  61. }
  62. //----------------------------------------------------------------------------
  63. void ctkXnatResource::reset()
  64. {
  65. ctkXnatObject::reset();
  66. }
  67. //----------------------------------------------------------------------------
  68. void ctkXnatResource::fetchImpl()
  69. {
  70. QString resourceFilesUri = this->resourceUri() + "/files";
  71. ctkXnatSession* const session = this->session();
  72. QUuid queryId = session->httpGet(resourceFilesUri);
  73. QList<ctkXnatObject*> files = session->httpResults(queryId,
  74. ctkXnatDefaultSchemaTypes::XSI_FILE);
  75. foreach (ctkXnatObject* file, files)
  76. {
  77. QString label = file->name();
  78. if (label.isEmpty())
  79. {
  80. label = "NO NAME";
  81. }
  82. file->setProperty(ctkXnatObjectFields::FILE_NAME, label);
  83. this->add(file);
  84. }
  85. }
  86. //----------------------------------------------------------------------------
  87. void ctkXnatResource::download(const QString& /*filename*/)
  88. {
  89. // this->session()->download(this, filename);
  90. }