annotate OrthancServer/Sources/OrthancWebDav.cpp @ 5854:65f8c6dfba50 find-refactoring

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