annotate OrthancServer/Sources/OrthancWebDav.cpp @ 4262:9a01e0f89b6d

ServeFolders plugin: mime type for ".map" file extension
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 30 Oct 2020 09:00:24 +0100
parents 2221051b42df
children d31cba1e27ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "OrthancWebDav.h"
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "../../OrthancFramework/Sources/HttpServer/WebDavStorage.h"
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "Search/DatabaseLookup.h"
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include "ServerContext.h"
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <boost/regex.hpp>
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include <boost/algorithm/string/predicate.hpp>
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 static const char* const BY_PATIENTS = "by-patients";
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 static const char* const BY_STUDIES = "by-studies";
4241
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4240
diff changeset
48 static const char* const BY_DATES = "by-dates";
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 static const char* const BY_UIDS = "by-uids";
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 static const char* const UPLOADS = "uploads";
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 static const char* const MAIN_DICOM_TAGS = "MainDicomTags";
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
52 static const char* const STUDY_INFO = "study.json";
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
53 static const char* const SERIES_INFO = "series.json";
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 namespace Orthanc
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 static boost::posix_time::ptime GetNow()
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 return boost::posix_time::second_clock::universal_time();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 static void LookupTime(boost::posix_time::ptime& target,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 ServerContext& context,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 const std::string& publicId,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 MetadataType metadata)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 std::string value;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 if (context.GetIndex().LookupMetadata(value, publicId, metadata))
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 try
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 target = boost::posix_time::from_iso_string(value);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 return;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 catch (std::exception& e)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 target = GetNow();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 class OrthancWebDav::DicomIdentifiersVisitor : public ServerContext::ILookupVisitor
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 ServerContext& context_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 bool isComplete_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 Collection& target_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 ResourceType level_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 DicomIdentifiersVisitor(ServerContext& context,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 Collection& target,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 ResourceType level) :
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 context_(context),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 isComplete_(false),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 target_(target),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 level_(level)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 return false; // (*)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 virtual void MarkAsComplete() ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 isComplete_ = true; // TODO
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 virtual void Visit(const std::string& publicId,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 const std::string& instanceId /* unused */,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 const DicomMap& mainDicomTags,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 DicomTag tag(0, 0);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 MetadataType timeMetadata;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 switch (level_)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 case ResourceType_Study:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 tag = DICOM_TAG_STUDY_INSTANCE_UID;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 timeMetadata = MetadataType_LastUpdate;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 break;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 case ResourceType_Series:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 tag = DICOM_TAG_SERIES_INSTANCE_UID;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 timeMetadata = MetadataType_LastUpdate;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 break;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 case ResourceType_Instance:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 tag = DICOM_TAG_SOP_INSTANCE_UID;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 timeMetadata = MetadataType_Instance_ReceptionDate;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 break;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 default:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 throw OrthancException(ErrorCode_InternalError);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 std::string s;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 if (mainDicomTags.LookupStringValue(s, tag, false) &&
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 !s.empty())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 std::unique_ptr<Resource> resource;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 if (level_ == ResourceType_Instance)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 FileInfo info;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 if (context_.GetIndex().LookupAttachment(info, publicId, FileContentType_Dicom))
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 std::unique_ptr<File> f(new File(s + ".dcm"));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 f->SetMimeType(MimeType_Dicom);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 f->SetContentLength(info.GetUncompressedSize());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 resource.reset(f.release());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 resource.reset(new Folder(s));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 if (resource.get() != NULL)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 boost::posix_time::ptime t;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 LookupTime(t, context_, publicId, timeMetadata);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 resource->SetCreationTime(t);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 target_.AddResource(resource.release());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 class OrthancWebDav::DicomFileVisitor : public ServerContext::ILookupVisitor
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 ServerContext& context_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 bool success_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 std::string& target_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 boost::posix_time::ptime& time_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 DicomFileVisitor(ServerContext& context,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 std::string& target,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 boost::posix_time::ptime& time) :
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 context_(context),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 success_(false),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 target_(target),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 time_(time)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 bool IsSuccess() const
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 return success_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 return false; // (*)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 virtual void MarkAsComplete() ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 virtual void Visit(const std::string& publicId,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 const std::string& instanceId /* unused */,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 const DicomMap& mainDicomTags,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 if (success_)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 success_ = false; // Two matches => Error
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 LookupTime(time_, context_, publicId, MetadataType_Instance_ReceptionDate);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 context_.ReadDicom(target_, publicId);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 success_ = true;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 class OrthancWebDav::OrthancJsonVisitor : public ServerContext::ILookupVisitor
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 ServerContext& context_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 bool success_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 std::string& target_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 ResourceType level_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 OrthancJsonVisitor(ServerContext& context,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 std::string& target,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 ResourceType level) :
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 context_(context),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 success_(false),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 target_(target),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 level_(level)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 bool IsSuccess() const
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 return success_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 return false; // (*)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 virtual void MarkAsComplete() ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 virtual void Visit(const std::string& publicId,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 const std::string& instanceId /* unused */,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 const DicomMap& mainDicomTags,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 Json::Value info;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 if (context_.GetIndex().LookupResource(info, publicId, level_))
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 if (success_)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 success_ = false; // Two matches => Error
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 target_ = info.toStyledString();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 // Replace UNIX newlines with DOS newlines
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 boost::replace_all(target_, "\n", "\r\n");
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 success_ = true;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 class OrthancWebDav::ResourcesIndex : public boost::noncopyable
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 typedef std::map<std::string, std::string> Map;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 ServerContext& context_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 ResourceType level_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 std::string template_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 Map pathToResource_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 Map resourceToPath_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 void CheckInvariants()
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 #ifndef NDEBUG
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 assert(pathToResource_.size() == resourceToPath_.size());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 for (Map::const_iterator it = pathToResource_.begin(); it != pathToResource_.end(); ++it)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 assert(resourceToPath_[it->second] == it->first);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 for (Map::const_iterator it = resourceToPath_.begin(); it != resourceToPath_.end(); ++it)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 assert(pathToResource_[it->second] == it->first);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 #endif
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 void AddTags(DicomMap& target,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 const std::string& resourceId,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 ResourceType tagsFromLevel)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 DicomMap tags;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 if (context_.GetIndex().GetMainDicomTags(tags, resourceId, level_, tagsFromLevel))
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 target.Merge(tags);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 void Register(const std::string& resourceId)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 // Don't register twice the same resource
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 if (resourceToPath_.find(resourceId) == resourceToPath_.end())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 std::string name = template_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 DicomMap tags;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 AddTags(tags, resourceId, level_);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 if (level_ == ResourceType_Study)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 AddTags(tags, resourceId, ResourceType_Patient);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 DicomArray arr(tags);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 for (size_t i = 0; i < arr.GetSize(); i++)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 const DicomElement& element = arr.GetElement(i);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 if (!element.GetValue().IsNull() &&
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 !element.GetValue().IsBinary())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 const std::string tag = FromDcmtkBridge::GetTagName(element.GetTag(), "");
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 boost::replace_all(name, "{{" + tag + "}}", element.GetValue().GetContent());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 // Blank the tags that were not matched
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 static const boost::regex REGEX_BLANK_TAGS("{{.*?}}"); // non-greedy match
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 name = boost::regex_replace(name, REGEX_BLANK_TAGS, "");
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 // UTF-8 characters cannot be used on Windows XP
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 name = Toolbox::ConvertToAscii(name);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 boost::replace_all(name, "/", "");
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 boost::replace_all(name, "\\", "");
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 // Trim sequences of spaces as one single space
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 static const boost::regex REGEX_TRIM_SPACES("{{.*?}}");
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 name = boost::regex_replace(name, REGEX_TRIM_SPACES, " ");
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 name = Toolbox::StripSpaces(name);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 size_t count = 0;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 for (;;)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 std::string path = name;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 if (count > 0)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 path += " (" + boost::lexical_cast<std::string>(count) + ")";
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 if (pathToResource_.find(path) == pathToResource_.end())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 pathToResource_[path] = resourceId;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 resourceToPath_[resourceId] = path;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 return;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 count++;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 throw OrthancException(ErrorCode_InternalError);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 ResourcesIndex(ServerContext& context,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 ResourceType level,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 const std::string& templateString) :
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 context_(context),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 level_(level),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 template_(templateString)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 ResourceType GetLevel() const
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 return level_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 void Refresh(std::set<std::string>& removedPaths /* out */,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 const std::set<std::string>& resources)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 CheckInvariants();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 // Detect the resources that have been removed since last refresh
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 removedPaths.clear();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 std::set<std::string> removedResources;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 for (Map::iterator it = resourceToPath_.begin(); it != resourceToPath_.end(); ++it)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 if (resources.find(it->first) == resources.end())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 const std::string& path = it->second;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 assert(pathToResource_.find(path) != pathToResource_.end());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 pathToResource_.erase(path);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 removedPaths.insert(path);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 removedResources.insert(it->first); // Delay the removal to avoid disturbing the iterator
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 // Remove the missing resources
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 for (std::set<std::string>::const_iterator it = removedResources.begin(); it != removedResources.end(); ++it)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 assert(resourceToPath_.find(*it) != resourceToPath_.end());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 resourceToPath_.erase(*it);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 CheckInvariants();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 for (std::set<std::string>::const_iterator it = resources.begin(); it != resources.end(); ++it)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 Register(*it);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 CheckInvariants();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 const Map& GetPathToResource() const
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 return pathToResource_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 class OrthancWebDav::InstancesOfSeries : public INode
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 ServerContext& context_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 std::string parentSeries_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
462 static bool LookupInstanceId(std::string& instanceId,
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
463 const UriComponents& path)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
464 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
465 if (path.size() == 1 &&
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
466 boost::ends_with(path[0], ".dcm"))
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
467 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
468 instanceId = path[0].substr(0, path[0].size() - 4);
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
469 return true;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
470 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
471 else
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
472 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
473 return false;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
474 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
475 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
476
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 InstancesOfSeries(ServerContext& context,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 const std::string& parentSeries) :
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 context_(context),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 parentSeries_(parentSeries)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 virtual bool ListCollection(IWebDavBucket::Collection& target,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 const UriComponents& path) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 if (path.empty())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 std::list<std::string> resources;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 try
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 context_.GetIndex().GetChildren(resources, parentSeries_);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 catch (OrthancException&)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 // Unknown (or deleted) parent series
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 for (std::list<std::string>::const_iterator
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 it = resources.begin(); it != resources.end(); ++it)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 boost::posix_time::ptime time;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 LookupTime(time, context_, *it, MetadataType_Instance_ReceptionDate);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 FileInfo info;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 if (context_.GetIndex().LookupAttachment(info, *it, FileContentType_Dicom))
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 std::unique_ptr<File> resource(new File(*it + ".dcm"));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 resource->SetMimeType(MimeType_Dicom);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 resource->SetContentLength(info.GetUncompressedSize());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 resource->SetCreationTime(time);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 target.AddResource(resource.release());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 return true;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 virtual bool GetFileContent(MimeType& mime,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 std::string& content,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 boost::posix_time::ptime& time,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 const UriComponents& path) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 {
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
531 std::string instanceId;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
532 if (LookupInstanceId(instanceId, path))
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 try
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 mime = MimeType_Dicom;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 context_.ReadDicom(content, instanceId);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 LookupTime(time, context_, instanceId, MetadataType_Instance_ReceptionDate);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 return true;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 catch (OrthancException&)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 // File was removed
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 }
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
552
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
553 virtual bool DeleteItem(const UriComponents& path) ORTHANC_OVERRIDE
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
554 {
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
555 if (path.empty())
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
556 {
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
557 // Delete all
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
558 std::list<std::string> resources;
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
559 try
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
560 {
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
561 context_.GetIndex().GetChildren(resources, parentSeries_);
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
562 }
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
563 catch (OrthancException&)
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
564 {
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
565 // Unknown (or deleted) parent series
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
566 return true;
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
567 }
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
568
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
569 for (std::list<std::string>::const_iterator it = resources.begin();
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
570 it != resources.end(); ++it)
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
571 {
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
572 Json::Value info;
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
573 context_.DeleteResource(info, *it, ResourceType_Instance);
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
574 }
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
575
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
576 return true;
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
577 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
578 else
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
579 {
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
580 std::string instanceId;
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
581 if (LookupInstanceId(instanceId, path))
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
582 {
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
583 Json::Value info;
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
584 return context_.DeleteResource(info, instanceId, ResourceType_Instance);
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
585 }
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
586 else
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
587 {
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
588 return false;
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
589 }
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
590 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
591 }
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 /**
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 * The "InternalNode" class corresponds to a non-leaf node in the
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 * WebDAV tree, that only contains subfolders (no file).
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 *
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 * TODO: Implement a LRU index to dynamically remove the oldest
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 * children on high RAM usage.
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 **/
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 class OrthancWebDav::InternalNode : public INode
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 typedef std::map<std::string, INode*> Children;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 Children children_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 INode* GetChild(const std::string& path) // Don't delete the result pointer!
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 Children::const_iterator child = children_.find(path);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 if (child == children_.end())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 {
4253
2221051b42df cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4252
diff changeset
615 INode* node = CreateSubfolder(path);
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616
4253
2221051b42df cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4252
diff changeset
617 if (node == NULL)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 return NULL;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 {
4253
2221051b42df cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4252
diff changeset
623 children_[path] = node;
2221051b42df cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4252
diff changeset
624 return node;
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 assert(child->second != NULL);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 return child->second;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 protected:
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
635 void InvalidateSubfolder(const std::string& path)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 Children::iterator child = children_.find(path);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 if (child != children_.end())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 assert(child->second != NULL);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 delete child->second;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 children_.erase(child);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 virtual void Refresh() = 0;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 virtual bool ListSubfolders(IWebDavBucket::Collection& target) = 0;
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
649
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
650 virtual INode* CreateSubfolder(const std::string& path) = 0;
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 virtual ~InternalNode()
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 for (Children::iterator it = children_.begin(); it != children_.end(); ++it)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 assert(it->second != NULL);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 delete it->second;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 virtual bool ListCollection(IWebDavBucket::Collection& target,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 const UriComponents& path)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 ORTHANC_OVERRIDE ORTHANC_FINAL
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 Refresh();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 if (path.empty())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 return ListSubfolders(target);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 // Recursivity
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 INode* child = GetChild(path[0]);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 if (child == NULL)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 {
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
678 // Must be "true" to allow DELETE on folders that are
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
679 // automatically removed through recursive deletion
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
680 return true;
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 UriComponents subpath(path.begin() + 1, path.end());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685 return child->ListCollection(target, subpath);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 virtual bool GetFileContent(MimeType& mime,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 std::string& content,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 boost::posix_time::ptime& time,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 const UriComponents& path)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 ORTHANC_OVERRIDE ORTHANC_FINAL
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 if (path.empty())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 return false; // An internal node doesn't correspond to a file
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 // Recursivity
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 Refresh();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 INode* child = GetChild(path[0]);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 if (child == NULL)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 UriComponents subpath(path.begin() + 1, path.end());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 return child->GetFileContent(mime, content, time, subpath);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 }
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
717
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
718
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
719 virtual bool DeleteItem(const UriComponents& path) ORTHANC_OVERRIDE ORTHANC_FINAL
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
720 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
721 Refresh();
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
722
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
723 if (path.empty())
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
724 {
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
725 IWebDavBucket::Collection collection;
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
726 if (ListSubfolders(collection))
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
727 {
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
728 std::set<std::string> content;
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
729 collection.ListDisplayNames(content);
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
730
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
731 for (std::set<std::string>::const_iterator
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
732 it = content.begin(); it != content.end(); ++it)
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
733 {
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
734 INode* node = GetChild(*it);
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
735 if (node)
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
736 {
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
737 node->DeleteItem(path);
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
738 }
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
739 }
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
740
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
741 return true;
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
742 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
743 else
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
744 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
745 return false;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
746 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
747 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
748 else
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
749 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
750 INode* child = GetChild(path[0]);
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
751 if (child == NULL)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
752 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
753 return true;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
754 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
755 else
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
756 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
757 // Recursivity
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
758 UriComponents subpath(path.begin() + 1, path.end());
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
759 return child->DeleteItem(subpath);
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
760 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
761 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
762 }
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 class OrthancWebDav::ListOfResources : public InternalNode
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 ServerContext& context_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 const Templates& templates_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 std::unique_ptr<ResourcesIndex> index_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 MetadataType timeMetadata_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 protected:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 virtual void Refresh() ORTHANC_OVERRIDE ORTHANC_FINAL
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 std::list<std::string> resources;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 GetCurrentResources(resources);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 std::set<std::string> removedPaths;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 index_->Refresh(removedPaths, std::set<std::string>(resources.begin(), resources.end()));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 // Remove the children whose associated resource doesn't exist anymore
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 for (std::set<std::string>::const_iterator
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 it = removedPaths.begin(); it != removedPaths.end(); ++it)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 {
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
787 InvalidateSubfolder(*it);
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 virtual bool ListSubfolders(IWebDavBucket::Collection& target) ORTHANC_OVERRIDE ORTHANC_FINAL
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 if (index_->GetLevel() == ResourceType_Instance)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 // Not a collection, no subfolders
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 const ResourcesIndex::Map& paths = index_->GetPathToResource();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 for (ResourcesIndex::Map::const_iterator it = paths.begin(); it != paths.end(); ++it)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 boost::posix_time::ptime time;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805 LookupTime(time, context_, it->second, timeMetadata_);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 std::unique_ptr<IWebDavBucket::Resource> resource(new IWebDavBucket::Folder(it->first));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 resource->SetCreationTime(time);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 target.AddResource(resource.release());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 return true;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
816 virtual INode* CreateSubfolder(const std::string& path) ORTHANC_OVERRIDE ORTHANC_FINAL
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818 ResourcesIndex::Map::const_iterator resource = index_->GetPathToResource().find(path);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819 if (resource == index_->GetPathToResource().end())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 return NULL;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 return CreateResourceNode(resource->second);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 ServerContext& GetContext() const
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 return context_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 }
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
833
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 virtual void GetCurrentResources(std::list<std::string>& resources) = 0;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 virtual INode* CreateResourceNode(const std::string& resource) = 0;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 ListOfResources(ServerContext& context,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840 ResourceType level,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 const Templates& templates) :
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 context_(context),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 templates_(templates)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 Templates::const_iterator t = templates.find(level);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 if (t == templates.end())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848 throw OrthancException(ErrorCode_ParameterOutOfRange);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 index_.reset(new ResourcesIndex(context, level, t->second));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 if (level == ResourceType_Instance)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 timeMetadata_ = MetadataType_Instance_ReceptionDate;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 timeMetadata_ = MetadataType_LastUpdate;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 ResourceType GetLevel() const
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 return index_->GetLevel();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 const Templates& GetTemplates() const
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870 return templates_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 class OrthancWebDav::SingleDicomResource : public ListOfResources
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 std::string parentId_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881 protected:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882 virtual void GetCurrentResources(std::list<std::string>& resources) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 try
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 GetContext().GetIndex().GetChildren(resources, parentId_);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 catch (OrthancException&)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 // Unknown parent resource
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891 resources.clear();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 virtual INode* CreateResourceNode(const std::string& resource) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 if (GetLevel() == ResourceType_Instance)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899 return NULL;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901 else if (GetLevel() == ResourceType_Series)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 return new InstancesOfSeries(GetContext(), resource);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 ResourceType l = GetChildResourceType(GetLevel());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 return new SingleDicomResource(GetContext(), l, resource, GetTemplates());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 SingleDicomResource(ServerContext& context,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914 ResourceType level,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915 const std::string& parentId,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 const Templates& templates) :
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 ListOfResources(context, level, templates),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 parentId_(parentId)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924 class OrthancWebDav::RootNode : public ListOfResources
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 protected:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927 virtual void GetCurrentResources(std::list<std::string>& resources) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 GetContext().GetIndex().GetAllUuids(resources, GetLevel());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932 virtual INode* CreateResourceNode(const std::string& resource) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 if (GetLevel() == ResourceType_Series)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 return new InstancesOfSeries(GetContext(), resource);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 ResourceType l = GetChildResourceType(GetLevel());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941 return new SingleDicomResource(GetContext(), l, resource, GetTemplates());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 RootNode(ServerContext& context,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947 ResourceType level,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948 const Templates& templates) :
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949 ListOfResources(context, level, templates)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 class OrthancWebDav::ListOfStudiesByDate : public ListOfResources
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 std::string year_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 std::string month_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 class Visitor : public ServerContext::ILookupVisitor
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964 std::list<std::string>& resources_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966 public:
4253
2221051b42df cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4252
diff changeset
967 explicit Visitor(std::list<std::string>& resources) :
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 resources_(resources)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 return false; // (*)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977 virtual void MarkAsComplete() ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 virtual void Visit(const std::string& publicId,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 const std::string& instanceId /* unused */,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 const DicomMap& mainDicomTags,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986 resources_.push_back(publicId);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
988 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
990 protected:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991 virtual void GetCurrentResources(std::list<std::string>& resources) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
992 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
993 DatabaseLookup query;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
994 query.AddRestConstraint(DICOM_TAG_STUDY_DATE, year_ + month_ + "01-" + year_ + month_ + "31",
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
995 true /* case sensitive */, true /* mandatory tag */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
996
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
997 Visitor visitor(resources);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998 GetContext().Apply(visitor, query, ResourceType_Study, 0 /* since */, 0 /* no limit */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
999 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1000
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1001 virtual INode* CreateResourceNode(const std::string& resource) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1002 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1003 return new SingleDicomResource(GetContext(), ResourceType_Series, resource, GetTemplates());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1004 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1006 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1007 ListOfStudiesByDate(ServerContext& context,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1008 const std::string& year,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1009 const std::string& month,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1010 const Templates& templates) :
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1011 ListOfResources(context, ResourceType_Study, templates),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1012 year_(year),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1013 month_(month)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1014 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1015 if (year.size() != 4 ||
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1016 month.size() != 2)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1017 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1018 throw OrthancException(ErrorCode_ParameterOutOfRange);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1023
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1024 class OrthancWebDav::ListOfStudiesByMonth : public InternalNode
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1025 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1026 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027 ServerContext& context_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1028 std::string year_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1029 const Templates& templates_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1030
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1031 class Visitor : public ServerContext::ILookupVisitor
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1032 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1033 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1034 std::set<std::string> months_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1036 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1037 const std::set<std::string>& GetMonths() const
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1038 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1039 return months_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1040 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1041
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1042 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1043 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1044 return false; // (*)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1045 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1046
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1047 virtual void MarkAsComplete() ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1048 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1049 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1050
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1051 virtual void Visit(const std::string& publicId,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1052 const std::string& instanceId /* unused */,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1053 const DicomMap& mainDicomTags,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1054 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1055 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1056 std::string s;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057 if (mainDicomTags.LookupStringValue(s, DICOM_TAG_STUDY_DATE, false) &&
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1058 s.size() == 8)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1059 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1060 months_.insert(s.substr(4, 2)); // Get the month from "YYYYMMDD"
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1061 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1062 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1063 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1064
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1065 protected:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1066 virtual void Refresh() ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1067 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1068 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1069
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1070 virtual bool ListSubfolders(IWebDavBucket::Collection& target) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1071 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1072 DatabaseLookup query;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1073 query.AddRestConstraint(DICOM_TAG_STUDY_DATE, year_ + "0101-" + year_ + "1231",
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1074 true /* case sensitive */, true /* mandatory tag */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1075
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1076 Visitor visitor;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1077 context_.Apply(visitor, query, ResourceType_Study, 0 /* since */, 0 /* no limit */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1078
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1079 for (std::set<std::string>::const_iterator it = visitor.GetMonths().begin();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1080 it != visitor.GetMonths().end(); ++it)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1081 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1082 target.AddResource(new IWebDavBucket::Folder(year_ + "-" + *it));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1083 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1084
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1085 return true;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1086 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1087
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1088 virtual INode* CreateSubfolder(const std::string& path) ORTHANC_OVERRIDE
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1089 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 if (path.size() != 7) // Format: "YYYY-MM"
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1092 throw OrthancException(ErrorCode_InternalError);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1094 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096 const std::string year = path.substr(0, 4);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1097 const std::string month = path.substr(5, 2);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098 return new ListOfStudiesByDate(context_, year, month, templates_);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1100 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1101
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1102 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1103 ListOfStudiesByMonth(ServerContext& context,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1104 const std::string& year,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1105 const Templates& templates) :
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1106 context_(context),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1107 year_(year),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108 templates_(templates)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110 if (year_.size() != 4)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1112 throw OrthancException(ErrorCode_ParameterOutOfRange);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1113 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1114 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1115 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1116
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1117
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1118 class OrthancWebDav::ListOfStudiesByYear : public InternalNode
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1119 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120 private:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1121 ServerContext& context_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1122 const Templates& templates_;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1123
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124 protected:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1125 virtual void Refresh() ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1126 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1127 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1128
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1129 virtual bool ListSubfolders(IWebDavBucket::Collection& target) ORTHANC_OVERRIDE
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1130 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1131 std::list<std::string> resources;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1132 context_.GetIndex().GetAllUuids(resources, ResourceType_Study);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1133
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1134 std::set<std::string> years;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1135
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1136 for (std::list<std::string>::const_iterator it = resources.begin(); it != resources.end(); ++it)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1137 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1138 DicomMap tags;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1139 std::string studyDate;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1140 if (context_.GetIndex().GetMainDicomTags(tags, *it, ResourceType_Study, ResourceType_Study) &&
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1141 tags.LookupStringValue(studyDate, DICOM_TAG_STUDY_DATE, false) &&
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1142 studyDate.size() == 8)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1144 years.insert(studyDate.substr(0, 4)); // Get the year from "YYYYMMDD"
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1145 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1146 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1147
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 for (std::set<std::string>::const_iterator it = years.begin(); it != years.end(); ++it)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 target.AddResource(new IWebDavBucket::Folder(*it));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153 return true;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1154 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1156 virtual INode* CreateSubfolder(const std::string& path) ORTHANC_OVERRIDE
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1157 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 return new ListOfStudiesByMonth(context_, path, templates_);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161 public:
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162 ListOfStudiesByYear(ServerContext& context,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163 const Templates& templates) :
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164 context_(context),
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165 templates_(templates)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1166 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168 };
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1169
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1170
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1171 class OrthancWebDav::DicomDeleteVisitor : public ServerContext::ILookupVisitor
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1172 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1173 private:
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1174 ServerContext& context_;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1175 ResourceType level_;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1176
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1177 public:
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1178 DicomDeleteVisitor(ServerContext& context,
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1179 ResourceType level) :
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1180 context_(context),
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1181 level_(level)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1182 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1183 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1184
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1185 virtual bool IsDicomAsJsonNeeded() const ORTHANC_OVERRIDE
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1186 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1187 return false; // (*)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1188 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1189
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1190 virtual void MarkAsComplete() ORTHANC_OVERRIDE
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1191 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1192 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1193
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1194 virtual void Visit(const std::string& publicId,
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1195 const std::string& instanceId /* unused */,
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1196 const DicomMap& mainDicomTags /* unused */,
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1197 const Json::Value* dicomAsJson /* unused (*) */) ORTHANC_OVERRIDE
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1198 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1199 Json::Value info;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1200 context_.DeleteResource(info, publicId, level_);
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1201 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1202 };
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1203
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1204
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1205 void OrthancWebDav::AddVirtualFile(Collection& collection,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1206 const UriComponents& path,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1207 const std::string& filename)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1208 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1209 MimeType mime;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1210 std::string content;
4246
6c3721ff284c simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4245
diff changeset
1211 boost::posix_time::ptime modification; // Unused, let the date be set to "GetNow()"
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1212
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1213 UriComponents p = path;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1214 p.push_back(filename);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1216 if (GetFileContent(mime, content, modification, p))
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1217 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1218 std::unique_ptr<File> f(new File(filename));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1219 f->SetMimeType(mime);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1220 f->SetContentLength(content.size());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1221 collection.AddResource(f.release());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1222 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1223 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1224
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1225
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1226 void OrthancWebDav::UploadWorker(OrthancWebDav* that)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1227 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1228 assert(that != NULL);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1229
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230 boost::posix_time::ptime lastModification = GetNow();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1232 while (that->uploadRunning_)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1234 std::unique_ptr<IDynamicObject> obj(that->uploadQueue_.Dequeue(100));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1235 if (obj.get() != NULL)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237 that->Upload(reinterpret_cast<const SingleValueObject<std::string>&>(*obj).GetValue());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1238 lastModification = GetNow();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239 }
4245
c70df925151e RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4244
diff changeset
1240 else if (GetNow() - lastModification > boost::posix_time::seconds(30))
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1241 {
4245
c70df925151e RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4244
diff changeset
1242 /**
c70df925151e RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4244
diff changeset
1243 * After every 30 seconds of inactivity, remove the empty
c70df925151e RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4244
diff changeset
1244 * folders. This delay is needed to avoid removing
c70df925151e RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4244
diff changeset
1245 * just-created folders before the remote WebDAV has time to
c70df925151e RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4244
diff changeset
1246 * write files into it.
c70df925151e RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4244
diff changeset
1247 **/
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248 LOG(INFO) << "Cleaning up the empty WebDAV upload folders";
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1249 that->uploads_.RemoveEmptyFolders();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1250 lastModification = GetNow();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1251 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1252 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1253 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1254
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1255
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1256 void OrthancWebDav::Upload(const std::string& path)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1257 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1258 UriComponents uri;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1259 Toolbox::SplitUriComponents(uri, path);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1260
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1261 LOG(INFO) << "Upload from WebDAV: " << path;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1262
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1263 MimeType mime;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1264 std::string content;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1265 boost::posix_time::ptime time;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1266 if (uploads_.GetFileContent(mime, content, time, uri))
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1267 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1268 DicomInstanceToStore instance;
4245
c70df925151e RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4244
diff changeset
1269 instance.SetOrigin(DicomInstanceOrigin::FromWebDav());
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1270 instance.SetBuffer(content.c_str(), content.size());
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1271
4244
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1272 bool success = false;
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1273
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1274 try
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1275 {
4244
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1276 std::string publicId;
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1277 StoreStatus status = context_.Store(publicId, instance, StoreInstanceMode_Default);
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1278 if (status == StoreStatus_Success ||
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1279 status == StoreStatus_AlreadyStored)
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1280 {
4245
c70df925151e RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4244
diff changeset
1281 LOG(INFO) << "Successfully imported DICOM instance from WebDAV: "
c70df925151e RequestOrigin_WebDav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4244
diff changeset
1282 << path << " (Orthanc ID: " << publicId << ")";
4244
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1283 success = true;
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1284 }
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1285 }
4244
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1286 catch (OrthancException& e)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1287 {
4244
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1288 }
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1289
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1290 uploads_.DeleteItem(uri);
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1291
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1292 if (!success)
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1293 {
416c35da7d25 robustness against non-dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4243
diff changeset
1294 LOG(WARNING) << "Cannot import DICOM instance from WebWAV (maybe not a DICOM file): " << path;
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1295 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1296 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1297 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1298
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1299
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1300 OrthancWebDav::INode& OrthancWebDav::GetRootNode(const std::string& rootPath)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1301 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1302 if (rootPath == BY_PATIENTS)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1303 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1304 return *patients_;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1305 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1306 else if (rootPath == BY_STUDIES)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1307 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1308 return *studies_;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1309 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1310 else if (rootPath == BY_DATES)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1311 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1312 return *dates_;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1313 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1314 else
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1315 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1316 throw OrthancException(ErrorCode_InternalError);
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1317 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1318 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1319
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1320
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1321 OrthancWebDav::OrthancWebDav(ServerContext& context,
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1322 bool allowDicomDelete,
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1323 bool allowUpload) :
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1324 context_(context),
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1325 allowDicomDelete_(allowDicomDelete),
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1326 allowUpload_(allowUpload),
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1327 uploads_(false /* store uploads as temporary files */),
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1328 uploadRunning_(false)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1329 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1330 patientsTemplates_[ResourceType_Patient] = "{{PatientID}} - {{PatientName}}";
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1331 patientsTemplates_[ResourceType_Study] = "{{StudyDate}} - {{StudyDescription}}";
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1332 patientsTemplates_[ResourceType_Series] = "{{Modality}} - {{SeriesDescription}}";
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1333
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1334 studiesTemplates_[ResourceType_Study] = "{{PatientID}} - {{PatientName}} - {{StudyDescription}}";
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1335 studiesTemplates_[ResourceType_Series] = patientsTemplates_[ResourceType_Series];
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1336
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1337 patients_.reset(new RootNode(context, ResourceType_Patient, patientsTemplates_));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1338 studies_.reset(new RootNode(context, ResourceType_Study, studiesTemplates_));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1339 dates_.reset(new ListOfStudiesByYear(context, studiesTemplates_));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1340 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1341
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1342
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1343 bool OrthancWebDav::IsExistingFolder(const UriComponents& path)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1344 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1345 if (path.empty())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1346 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1347 return true;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1348 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1349 else if (path[0] == BY_UIDS)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1350 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1351 return (path.size() <= 3 &&
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1352 (path.size() != 3 || path[2] != STUDY_INFO));
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1353 }
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1354 else if (path[0] == BY_PATIENTS ||
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1355 path[0] == BY_STUDIES ||
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1356 path[0] == BY_DATES)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1357 {
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
1358 IWebDavBucket::Collection collection;
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
1359 return GetRootNode(path[0]).ListCollection(collection, UriComponents(path.begin() + 1, path.end()));
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1360 }
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1361 else if (allowUpload_ &&
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1362 path[0] == UPLOADS)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1363 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1364 return uploads_.IsExistingFolder(UriComponents(path.begin() + 1, path.end()));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1365 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1366 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1367 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1368 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1369 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1370 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1371
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1372
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1373 bool OrthancWebDav::ListCollection(Collection& collection,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1374 const UriComponents& path)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1375 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1376 if (path.empty())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1377 {
4241
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4240
diff changeset
1378 collection.AddResource(new Folder(BY_DATES));
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1379 collection.AddResource(new Folder(BY_PATIENTS));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1380 collection.AddResource(new Folder(BY_STUDIES));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1381 collection.AddResource(new Folder(BY_UIDS));
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1382
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1383 if (allowUpload_)
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1384 {
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1385 collection.AddResource(new Folder(UPLOADS));
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1386 }
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1387
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1388 return true;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1389 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1390 else if (path[0] == BY_UIDS)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1391 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1392 DatabaseLookup query;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1393 ResourceType level;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1394 size_t limit = 0; // By default, no limits
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1395
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1396 if (path.size() == 1)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1397 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1398 level = ResourceType_Study;
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1399 limit = 0; // TODO - Should we limit here?
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1400 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1401 else if (path.size() == 2)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1402 {
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1403 AddVirtualFile(collection, path, STUDY_INFO);
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1404
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1405 level = ResourceType_Series;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1406 query.AddRestConstraint(DICOM_TAG_STUDY_INSTANCE_UID, path[1],
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1407 true /* case sensitive */, true /* mandatory tag */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1408 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1409 else if (path.size() == 3)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1410 {
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1411 AddVirtualFile(collection, path, SERIES_INFO);
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1412
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1413 level = ResourceType_Instance;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1414 query.AddRestConstraint(DICOM_TAG_STUDY_INSTANCE_UID, path[1],
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1415 true /* case sensitive */, true /* mandatory tag */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1416 query.AddRestConstraint(DICOM_TAG_SERIES_INSTANCE_UID, path[2],
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1417 true /* case sensitive */, true /* mandatory tag */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1418 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1419 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1420 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1421 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1422 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1423
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1424 DicomIdentifiersVisitor visitor(context_, collection, level);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1425 context_.Apply(visitor, query, level, 0 /* since */, limit);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1426
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1427 return true;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1428 }
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1429 else if (path[0] == BY_PATIENTS ||
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1430 path[0] == BY_STUDIES ||
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1431 path[0] == BY_DATES)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1432 {
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1433 return GetRootNode(path[0]).ListCollection(collection, UriComponents(path.begin() + 1, path.end()));
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1434 }
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1435 else if (allowUpload_ &&
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1436 path[0] == UPLOADS)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1437 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1438 return uploads_.ListCollection(collection, UriComponents(path.begin() + 1, path.end()));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1439 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1440 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1441 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1442 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1443 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1444 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1445
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1446
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1447 bool OrthancWebDav::GetFileContent(MimeType& mime,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1448 std::string& content,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1449 boost::posix_time::ptime& modificationTime,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1450 const UriComponents& path)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1451 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1452 if (path.empty())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1453 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1454 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1455 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1456 else if (path[0] == BY_UIDS)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1457 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1458 if (path.size() == 3 &&
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1459 path[2] == STUDY_INFO)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1460 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1461 DatabaseLookup query;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1462 query.AddRestConstraint(DICOM_TAG_STUDY_INSTANCE_UID, path[1],
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1463 true /* case sensitive */, true /* mandatory tag */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1464
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1465 OrthancJsonVisitor visitor(context_, content, ResourceType_Study);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1466 context_.Apply(visitor, query, ResourceType_Study, 0 /* since */, 0 /* no limit */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1467
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1468 mime = MimeType_Json;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1469 return visitor.IsSuccess();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1470 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1471 else if (path.size() == 4 &&
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1472 path[3] == SERIES_INFO)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1473 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1474 DatabaseLookup query;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1475 query.AddRestConstraint(DICOM_TAG_STUDY_INSTANCE_UID, path[1],
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1476 true /* case sensitive */, true /* mandatory tag */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1477 query.AddRestConstraint(DICOM_TAG_SERIES_INSTANCE_UID, path[2],
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1478 true /* case sensitive */, true /* mandatory tag */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1479
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1480 OrthancJsonVisitor visitor(context_, content, ResourceType_Series);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1481 context_.Apply(visitor, query, ResourceType_Series, 0 /* since */, 0 /* no limit */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1482
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1483 mime = MimeType_Json;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1484 return visitor.IsSuccess();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1485 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1486 else if (path.size() == 4 &&
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1487 boost::ends_with(path[3], ".dcm"))
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1488 {
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1489 const std::string sopInstanceUid = path[3].substr(0, path[3].size() - 4);
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1490
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1491 DatabaseLookup query;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1492 query.AddRestConstraint(DICOM_TAG_STUDY_INSTANCE_UID, path[1],
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1493 true /* case sensitive */, true /* mandatory tag */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1494 query.AddRestConstraint(DICOM_TAG_SERIES_INSTANCE_UID, path[2],
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1495 true /* case sensitive */, true /* mandatory tag */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1496 query.AddRestConstraint(DICOM_TAG_SOP_INSTANCE_UID, sopInstanceUid,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1497 true /* case sensitive */, true /* mandatory tag */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1498
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1499 DicomFileVisitor visitor(context_, content, modificationTime);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1500 context_.Apply(visitor, query, ResourceType_Instance, 0 /* since */, 0 /* no limit */);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1501
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1502 mime = MimeType_Dicom;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1503 return visitor.IsSuccess();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1504 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1505 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1506 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1507 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1508 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1509 }
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1510 else if (path[0] == BY_PATIENTS ||
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1511 path[0] == BY_STUDIES ||
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1512 path[0] == BY_DATES)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1513 {
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1514 return GetRootNode(path[0]).GetFileContent(mime, content, modificationTime, UriComponents(path.begin() + 1, path.end()));
4241
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4240
diff changeset
1515 }
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1516 else if (allowUpload_ &&
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1517 path[0] == UPLOADS)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1518 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1519 return uploads_.GetFileContent(mime, content, modificationTime, UriComponents(path.begin() + 1, path.end()));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1520 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1521 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1522 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1523 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1524 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1525 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1526
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1527
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1528 bool OrthancWebDav::StoreFile(const std::string& content,
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1529 const UriComponents& path)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1530 {
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1531 if (allowUpload_ &&
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1532 path.size() >= 1 &&
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1533 path[0] == UPLOADS)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1534 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1535 UriComponents subpath(UriComponents(path.begin() + 1, path.end()));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1536
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1537 if (uploads_.StoreFile(content, subpath))
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1538 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1539 if (!content.empty())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1540 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1541 uploadQueue_.Enqueue(new SingleValueObject<std::string>(Toolbox::FlattenUri(subpath)));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1542 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1543 return true;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1544 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1545 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1546 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1547 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1548 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1549 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1550 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1551 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1552 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1553 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1554 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1555
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1556
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1557 bool OrthancWebDav::CreateFolder(const UriComponents& path)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1558 {
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1559 if (allowUpload_ &&
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1560 path.size() >= 1 &&
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1561 path[0] == UPLOADS)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1562 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1563 return uploads_.CreateFolder(UriComponents(path.begin() + 1, path.end()));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1564 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1565 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1566 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1567 return false;
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1568 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1569 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1570
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1571
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1572 bool OrthancWebDav::DeleteItem(const std::vector<std::string>& path)
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1573 {
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1574 if (path.empty())
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1575 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1576 return false;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1577 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1578 else if (path[0] == BY_UIDS &&
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1579 path.size() >= 2 &&
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1580 path.size() <= 4)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1581 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1582 if (allowDicomDelete_)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1583 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1584 ResourceType level;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1585 DatabaseLookup query;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1586
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1587 query.AddRestConstraint(DICOM_TAG_STUDY_INSTANCE_UID, path[1],
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1588 true /* case sensitive */, true /* mandatory tag */);
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1589 level = ResourceType_Study;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1590
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1591 if (path.size() >= 3)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1592 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1593 if (path[2] == STUDY_INFO)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1594 {
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
1595 return true; // Allow deletion of virtual files (to avoid blocking recursive DELETE)
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1596 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1597
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1598 query.AddRestConstraint(DICOM_TAG_SERIES_INSTANCE_UID, path[2],
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1599 true /* case sensitive */, true /* mandatory tag */);
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1600 level = ResourceType_Series;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1601 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1602
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1603 if (path.size() == 4)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1604 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1605 if (path[3] == SERIES_INFO)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1606 {
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
1607 return true; // Allow deletion of virtual files (to avoid blocking recursive DELETE)
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1608 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1609 else if (boost::ends_with(path[3], ".dcm"))
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1610 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1611 const std::string sopInstanceUid = path[3].substr(0, path[3].size() - 4);
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1612
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1613 query.AddRestConstraint(DICOM_TAG_SOP_INSTANCE_UID, sopInstanceUid,
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1614 true /* case sensitive */, true /* mandatory tag */);
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1615 level = ResourceType_Instance;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1616 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1617 else
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1618 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1619 return false;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1620 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1621 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1622
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1623 DicomDeleteVisitor visitor(context_, level);
4252
f047e2734655 fix webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4246
diff changeset
1624 context_.Apply(visitor, query, level, 0 /* since */, 0 /* no limit */);
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1625 return true;
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1626 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1627 else
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1628 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1629 return false; // read-only
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1630 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1631 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1632 else if (path[0] == BY_PATIENTS ||
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1633 path[0] == BY_STUDIES ||
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1634 path[0] == BY_DATES)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1635 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1636 if (allowDicomDelete_)
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1637 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1638 return GetRootNode(path[0]).DeleteItem(UriComponents(path.begin() + 1, path.end()));
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1639 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1640 else
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1641 {
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1642 return false; // read-only
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1643 }
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1644 }
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1645 else if (allowUpload_ &&
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1646 path[0] == UPLOADS)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1647 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1648 return uploads_.DeleteItem(UriComponents(path.begin() + 1, path.end()));
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1649 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1650 else
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1651 {
4242
5cfa6ba75dfc deleting resources from Orthanc WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4241
diff changeset
1652 return false;
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1653 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1654 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1655
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1656
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1657 void OrthancWebDav::Start()
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1658 {
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1659 if (uploadRunning_)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1660 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1661 throw OrthancException(ErrorCode_BadSequenceOfCalls);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1662 }
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1663 else if (allowUpload_)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1664 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1665 LOG(INFO) << "Starting the WebDAV upload thread";
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1666 uploadRunning_ = true;
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1667 uploadThread_ = boost::thread(UploadWorker, this);
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1668 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1669 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1670
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1671
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1672 void OrthancWebDav::Stop()
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1673 {
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1674 if (uploadRunning_)
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1675 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1676 LOG(INFO) << "Stopping the WebDAV upload thread";
4243
64f57c9d5f79 configuration options for webdav
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4242
diff changeset
1677 uploadRunning_ = false;
4240
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1678 if (uploadThread_.joinable())
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1679 {
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1680 uploadThread_.join();
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1681 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1682 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1683 }
799c0c527ced reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1684 }