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