Mercurial > hg > orthanc
annotate OrthancServer/Plugins/Samples/AdvancedStorage/Plugin.cpp @ 5082:4af5f496a0dd attach-custom-data
fix
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 14 Sep 2022 17:11:05 +0200 |
parents | c673997507ea |
children | 79f98ee4f04b |
rev | line source |
---|---|
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
1 /** |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
7 * |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
9 * modify it under the terms of the GNU General Public License as |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
10 * published by the Free Software Foundation, either version 3 of the |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
11 * License, or (at your option) any later version. |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
12 * |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
16 * General Public License for more details. |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
17 * |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
20 **/ |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
21 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
22 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
23 #include "../../../../OrthancFramework/Sources/Compatibility.h" |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
24 #include "../../../../OrthancFramework/Sources/OrthancException.h" |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
25 #include "../../../../OrthancFramework/Sources/SystemToolbox.h" |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
26 #include "../../../../OrthancFramework/Sources/Toolbox.h" |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
27 #include "../../../../OrthancFramework/Sources/Logging.h" |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
28 #include "../Common/OrthancPluginCppWrapper.h" |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
29 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
30 #include <boost/filesystem.hpp> |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
31 #include <boost/filesystem/fstream.hpp> |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
32 #include <boost/iostreams/device/file_descriptor.hpp> |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
33 #include <boost/iostreams/stream.hpp> |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
34 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
35 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
36 #include <json/value.h> |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
37 #include <json/writer.h> |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
38 #include <string.h> |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
39 #include <iostream> |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
40 #include <algorithm> |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
41 #include <map> |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
42 #include <list> |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
43 #include <time.h> |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
44 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
45 namespace fs = boost::filesystem; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
46 |
5081 | 47 fs::path rootPath_; |
48 bool multipleStoragesEnabled_ = false; | |
49 std::map<std::string, fs::path> rootPaths_; | |
50 std::string currentStorageId_; | |
51 std::string namingScheme_; | |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
52 bool fsyncOnWrite_ = true; |
5081 | 53 size_t maxPathLength_ = 256; |
54 size_t legacyPathLength = 39; // ex "/00/f7/00f7fd8b-47bd8c3a-ff917804-d180cdbc-40cf9527" | |
55 | |
56 fs::path GetRootPath() | |
57 { | |
58 if (multipleStoragesEnabled_) | |
59 { | |
60 return rootPaths_[currentStorageId_]; | |
61 } | |
62 | |
63 return rootPath_; | |
64 } | |
65 | |
66 fs::path GetRootPath(const std::string& storageId) | |
67 { | |
68 if (multipleStoragesEnabled_) | |
69 { | |
70 if (rootPaths_.find(storageId) == rootPaths_.end()) | |
71 { | |
72 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, std::string("Advanced Storage - storage '" + storageId + "' is not defined in configuration")); | |
73 } | |
74 return rootPaths_[storageId]; | |
75 } | |
76 | |
77 return rootPath_; | |
78 } | |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
79 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
80 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
81 fs::path GetLegacyRelativePath(const std::string& uuid) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
82 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
83 if (!Orthanc::Toolbox::IsUuid(uuid)) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
84 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
85 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
86 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
87 |
5081 | 88 fs::path path; |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
89 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
90 path /= std::string(&uuid[0], &uuid[2]); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
91 path /= std::string(&uuid[2], &uuid[4]); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
92 path /= uuid; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
93 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
94 #if BOOST_HAS_FILESYSTEM_V3 == 1 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
95 path.make_preferred(); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
96 #endif |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
97 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
98 return path; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
99 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
100 |
5081 | 101 fs::path GetPath(const std::string& uuid, const std::string& customDataString) |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
102 { |
5081 | 103 fs::path path; |
104 | |
105 if (!customDataString.empty()) | |
106 { | |
107 Json::Value customData; | |
108 Orthanc::Toolbox::ReadJson(customData, customDataString); | |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
109 |
5081 | 110 if (customData["Version"].asInt() == 1) |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
111 { |
5081 | 112 if (customData.isMember("StorageId")) |
113 { | |
114 path = GetRootPath(customData["StorageId"].asString()); | |
115 } | |
116 else | |
117 { | |
118 path = GetRootPath(); | |
119 } | |
120 | |
121 if (customData.isMember("Path")) | |
122 { | |
123 path /= customData["Path"].asString(); | |
124 } | |
125 else | |
126 { // we are in "legacy mode" for the path part | |
127 path /= GetLegacyRelativePath(uuid); | |
128 } | |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
129 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
130 else |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
131 { |
5081 | 132 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, std::string("Advanced Storage - unknown version for custom data '" + boost::lexical_cast<std::string>(customData["Version"].asInt()) + "'")); |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
133 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
134 } |
5081 | 135 else // we are in "legacy mode" |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
136 { |
5081 | 137 path = GetRootPath(); |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
138 path /= GetLegacyRelativePath(uuid); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
139 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
140 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
141 path.make_preferred(); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
142 return path; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
143 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
144 |
5081 | 145 void GetCustomData(std::string& output, const fs::path& path) |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
146 { |
5081 | 147 // if we use defaults, non need to store anything in the metadata, the plugin has the same behavior as the core of Orthanc |
148 if (namingScheme_ == "OrthancDefault" && !multipleStoragesEnabled_) | |
149 { | |
150 return; | |
151 } | |
152 | |
153 Json::Value customDataJson; | |
154 customDataJson["Version"] = 1; | |
155 | |
156 if (namingScheme_ != "OrthancDefault") | |
157 { // no need to store the pathc since we are in the default mode | |
158 customDataJson["Path"] = path.string(); | |
159 } | |
160 | |
161 if (multipleStoragesEnabled_) | |
162 { | |
163 customDataJson["StorageId"] = currentStorageId_; | |
164 } | |
165 | |
166 return Orthanc::Toolbox::WriteFastJson(output, customDataJson); | |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
167 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
168 |
5081 | 169 void AddSplitDateDicomTagToPath(fs::path& path, const Json::Value& tags, const char* tagName, const char* defaultValue = NULL) |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
170 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
171 if (tags.isMember(tagName) && tags[tagName].asString().size() == 8) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
172 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
173 std::string date = tags[tagName].asString(); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
174 path /= date.substr(0, 4); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
175 path /= date.substr(4, 2); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
176 path /= date.substr(6, 2); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
177 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
178 else if (defaultValue != NULL) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
179 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
180 path /= defaultValue; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
181 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
182 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
183 |
5081 | 184 void AddStringDicomTagToPath(fs::path& path, const Json::Value& tags, const char* tagName, const char* defaultValue = NULL) |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
185 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
186 if (tags.isMember(tagName) && tags[tagName].isString() && tags[tagName].asString().size() > 0) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
187 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
188 path /= tags[tagName].asString(); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
189 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
190 else if (defaultValue != NULL) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
191 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
192 path /= defaultValue; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
193 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
194 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
195 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
196 void AddIntDicomTagToPath(fs::path& path, const Json::Value& tags, const char* tagName, size_t zeroPaddingWidth = 0, const char* defaultValue = NULL) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
197 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
198 if (tags.isMember(tagName) && tags[tagName].isString() && tags[tagName].asString().size() > 0) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
199 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
200 std::string tagValue = tags[tagName].asString(); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
201 if (zeroPaddingWidth > 0 && tagValue.size() < zeroPaddingWidth) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
202 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
203 std::string padding(zeroPaddingWidth - tagValue.size(), '0'); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
204 path /= padding + tagValue; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
205 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
206 else |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
207 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
208 path /= tagValue; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
209 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
210 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
211 else if (defaultValue != NULL) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
212 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
213 path /= defaultValue; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
214 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
215 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
216 |
5081 | 217 std::string GetExtension(OrthancPluginContentType type, bool isCompressed) |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
218 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
219 std::string extension; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
220 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
221 switch (type) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
222 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
223 case OrthancPluginContentType_Dicom: |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
224 extension = ".dcm"; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
225 break; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
226 case OrthancPluginContentType_DicomUntilPixelData: |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
227 extension = ".dcm.head"; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
228 break; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
229 default: |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
230 extension = ".unk"; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
231 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
232 if (isCompressed) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
233 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
234 extension = extension + ".cmp"; // compression is zlib + size -> we can not use the .zip extension |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
235 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
236 |
5081 | 237 return extension; |
238 } | |
239 | |
240 fs::path GetRelativePathFromTags(const Json::Value& tags, const char* uuid, OrthancPluginContentType type, bool isCompressed) | |
241 { | |
242 fs::path path; | |
243 | |
244 if (!tags.isNull()) | |
245 { | |
246 if (namingScheme_ == "Preset1-StudyDatePatientID") | |
247 { | |
248 if (!tags.isMember("StudyDate")) | |
249 { | |
250 LOG(WARNING) << "AdvancedStorage - No 'StudyDate' in attachment " << uuid << ". Attachment will be stored in NO_STUDY_DATE folder"; | |
251 } | |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
252 |
5081 | 253 AddSplitDateDicomTagToPath(path, tags, "StudyDate", "NO_STUDY_DATE"); |
254 AddStringDicomTagToPath(path, tags, "PatientID"); // no default value, tag is always present if the instance is accepted by Orthanc | |
255 | |
256 if (tags.isMember("PatientName") && tags["PatientName"].isString() && !tags["PatientName"].asString().empty()) | |
257 { | |
258 path += std::string(" - ") + tags["PatientName"].asString(); | |
259 } | |
260 | |
261 AddStringDicomTagToPath(path, tags, "StudyDescription"); | |
262 AddStringDicomTagToPath(path, tags, "SeriesInstanceUID"); | |
263 | |
264 path /= uuid; | |
265 path += GetExtension(type, isCompressed); | |
266 return path; | |
267 } | |
268 } | |
269 | |
270 return GetLegacyRelativePath(uuid); | |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
271 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
272 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
273 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
274 OrthancPluginErrorCode StorageCreate(OrthancPluginMemoryBuffer* customData, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
275 const char* uuid, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
276 const Json::Value& tags, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
277 const void* content, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
278 int64_t size, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
279 OrthancPluginContentType type, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
280 bool isCompressed) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
281 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
282 fs::path relativePath = GetRelativePathFromTags(tags, uuid, type, isCompressed); |
5081 | 283 std::string customDataString; |
284 GetCustomData(customDataString, relativePath); | |
285 | |
286 fs::path rootPath = GetRootPath(); | |
287 fs::path path = rootPath / relativePath; | |
288 | |
289 LOG(INFO) << "Advanced Storage - creating attachment \"" << uuid << "\" of type " << static_cast<int>(type) << " (path = " + path.string() + ")"; | |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
290 |
5081 | 291 // check that the final path is not 'above' the root path (this could happen if e.g., a PatientName is ../../../../toto) |
5082 | 292 // fs::canonical() can not be used for that since the file needs to exist |
293 // so far, we'll just forbid path containing '..' since they might be suspicious | |
294 if (path.string().find("..") != std::string::npos) | |
5081 | 295 { |
5082 | 296 fs::path legacyPath = rootPath / GetLegacyRelativePath(uuid); |
297 LOG(WARNING) << "Advanced Storage - WAS02 - Path is suspicious since it contains '..': '" << path.string() << "' will be stored in '" << legacyPath << "'"; | |
298 path = legacyPath; | |
5081 | 299 } |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
300 |
5081 | 301 // check path length !!!!!, if too long, go back to legacy path and issue a warning |
302 if (path.string().size() > maxPathLength_) | |
303 { | |
304 fs::path legacyPath = rootPath / GetLegacyRelativePath(uuid); | |
305 LOG(WARNING) << "Advanced Storage - WAS01 - Path is too long: '" << path.string() << "' will be stored in '" << legacyPath << "'"; | |
306 path = legacyPath; | |
307 } | |
308 | |
309 if (fs::exists(path)) | |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
310 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
311 // Extremely unlikely case if uuid is included in the path: This Uuid has already been created |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
312 // in the past. |
5081 | 313 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "Advanced Storage - path already exists"); |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
314 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
315 // TODO for the future: handle duplicates path (e.g: there's no uuid in the path and we are uploading the same file again) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
316 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
317 |
5081 | 318 if (fs::exists(path.parent_path())) |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
319 { |
5081 | 320 if (!fs::is_directory(path.parent_path())) |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
321 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
322 throw Orthanc::OrthancException(Orthanc::ErrorCode_DirectoryOverFile); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
323 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
324 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
325 else |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
326 { |
5081 | 327 if (!fs::create_directories(path.parent_path())) |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
328 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
329 throw Orthanc::OrthancException(Orthanc::ErrorCode_FileStorageCannotWrite); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
330 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
331 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
332 |
5081 | 333 Orthanc::SystemToolbox::WriteFile(content, size, path.string(), fsyncOnWrite_); |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
334 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
335 OrthancPluginCreateMemoryBuffer(OrthancPlugins::GetGlobalContext(), customData, customDataString.size()); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
336 memcpy(customData->data, customDataString.data(), customDataString.size()); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
337 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
338 return OrthancPluginErrorCode_Success; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
339 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
340 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
341 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
342 OrthancPluginErrorCode StorageCreateInstance(OrthancPluginMemoryBuffer* customData, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
343 const char* uuid, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
344 const OrthancPluginDicomInstance* instance, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
345 const void* content, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
346 int64_t size, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
347 OrthancPluginContentType type, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
348 bool isCompressed) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
349 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
350 try |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
351 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
352 OrthancPlugins::DicomInstance dicomInstance(instance); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
353 Json::Value tags; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
354 dicomInstance.GetSimplifiedJson(tags); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
355 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
356 return StorageCreate(customData, uuid, tags, content, size, type, isCompressed); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
357 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
358 catch (Orthanc::OrthancException& e) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
359 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
360 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
361 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
362 catch (...) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
363 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
364 return OrthancPluginErrorCode_StorageAreaPlugin; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
365 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
366 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
367 return OrthancPluginErrorCode_Success; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
368 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
369 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
370 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
371 OrthancPluginErrorCode StorageCreateAttachment(OrthancPluginMemoryBuffer* customData, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
372 const char* uuid, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
373 const char* resourceId, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
374 OrthancPluginResourceType resourceType, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
375 const void* content, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
376 int64_t size, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
377 OrthancPluginContentType type, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
378 bool isCompressed) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
379 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
380 try |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
381 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
382 OrthancPlugins::LogInfo(std::string("Creating attachment \"") + uuid + "\""); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
383 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
384 //TODO_CUSTOM_DATA: get tags from the Rest API... |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
385 Json::Value tags; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
386 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
387 return StorageCreate(customData, uuid, tags, content, size, type, isCompressed); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
388 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
389 catch (Orthanc::OrthancException& e) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
390 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
391 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
392 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
393 catch (...) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
394 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
395 return OrthancPluginErrorCode_StorageAreaPlugin; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
396 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
397 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
398 return OrthancPluginErrorCode_Success; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
399 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
400 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
401 OrthancPluginErrorCode StorageReadWhole(OrthancPluginMemoryBuffer64* target, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
402 const char* uuid, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
403 const char* customData, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
404 OrthancPluginContentType type) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
405 { |
5081 | 406 std::string path = GetPath(uuid, customData).string(); |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
407 |
5081 | 408 LOG(INFO) << "Advanced Storage - Reading whole attachment \"" << uuid << "\" of type " << static_cast<int>(type) << " (path = " + path + ")"; |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
409 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
410 if (!Orthanc::SystemToolbox::IsRegularFile(path)) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
411 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
412 OrthancPlugins::LogError(std::string("The path does not point to a regular file: ") + path); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
413 return OrthancPluginErrorCode_InexistentFile; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
414 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
415 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
416 try |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
417 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
418 fs::ifstream f; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
419 f.open(path, std::ifstream::in | std::ifstream::binary); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
420 if (!f.good()) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
421 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
422 OrthancPlugins::LogError(std::string("The path does not point to a regular file: ") + path); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
423 return OrthancPluginErrorCode_InexistentFile; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
424 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
425 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
426 // get file size |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
427 f.seekg(0, std::ios::end); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
428 std::streamsize fileSize = f.tellg(); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
429 f.seekg(0, std::ios::beg); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
430 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
431 // The ReadWhole must allocate the buffer itself |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
432 if (OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), target, fileSize) != OrthancPluginErrorCode_Success) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
433 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
434 OrthancPlugins::LogError(std::string("Unable to allocate memory to read file: ") + path); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
435 return OrthancPluginErrorCode_NotEnoughMemory; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
436 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
437 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
438 if (fileSize != 0) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
439 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
440 f.read(reinterpret_cast<char*>(target->data), fileSize); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
441 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
442 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
443 f.close(); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
444 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
445 catch (...) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
446 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
447 OrthancPlugins::LogError(std::string("Unexpected error while reading: ") + path); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
448 return OrthancPluginErrorCode_StorageAreaPlugin; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
449 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
450 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
451 return OrthancPluginErrorCode_Success; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
452 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
453 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
454 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
455 OrthancPluginErrorCode StorageReadRange (OrthancPluginMemoryBuffer64* target, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
456 const char* uuid, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
457 const char* customData, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
458 OrthancPluginContentType type, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
459 uint64_t rangeStart) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
460 { |
5081 | 461 std::string path = GetPath(uuid, customData).string(); |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
462 |
5081 | 463 LOG(INFO) << "Advanced Storage - Reading range of attachment \"" << uuid << "\" of type " << static_cast<int>(type) << " (path = " + path + ")"; |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
464 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
465 if (!Orthanc::SystemToolbox::IsRegularFile(path)) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
466 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
467 OrthancPlugins::LogError(std::string("The path does not point to a regular file: ") + path); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
468 return OrthancPluginErrorCode_InexistentFile; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
469 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
470 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
471 try |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
472 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
473 fs::ifstream f; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
474 f.open(path, std::ifstream::in | std::ifstream::binary); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
475 if (!f.good()) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
476 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
477 OrthancPlugins::LogError(std::string("The path does not point to a regular file: ") + path); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
478 return OrthancPluginErrorCode_InexistentFile; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
479 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
480 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
481 f.seekg(rangeStart, std::ios::beg); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
482 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
483 // The ReadRange uses a target that has already been allocated by orthanc |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
484 f.read(reinterpret_cast<char*>(target->data), target->size); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
485 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
486 f.close(); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
487 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
488 catch (...) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
489 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
490 OrthancPlugins::LogError(std::string("Unexpected error while reading: ") + path); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
491 return OrthancPluginErrorCode_StorageAreaPlugin; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
492 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
493 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
494 return OrthancPluginErrorCode_Success; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
495 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
496 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
497 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
498 OrthancPluginErrorCode StorageRemove (const char* uuid, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
499 const char* customData, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
500 OrthancPluginContentType type) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
501 { |
5081 | 502 fs::path path = GetPath(uuid, customData); |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
503 |
5081 | 504 LOG(INFO) << "Advanced Storage - Deleting attachment \"" << uuid << "\" of type " << static_cast<int>(type) << " (path = " + path.string() + ")"; |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
505 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
506 try |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
507 { |
5081 | 508 fs::remove(path); |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
509 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
510 catch (...) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
511 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
512 // Ignore the error |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
513 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
514 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
515 // Remove the empty parent directories, (ignoring the error code if these directories are not empty) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
516 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
517 try |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
518 { |
5081 | 519 fs::path parent = path.parent_path(); |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
520 |
5081 | 521 while (parent != GetRootPath()) |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
522 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
523 fs::remove(parent); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
524 parent = parent.parent_path(); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
525 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
526 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
527 catch (...) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
528 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
529 // Ignore the error |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
530 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
531 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
532 return OrthancPluginErrorCode_Success; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
533 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
534 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
535 extern "C" |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
536 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
537 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
538 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
539 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
540 OrthancPlugins::SetGlobalContext(context); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
541 Orthanc::Logging::InitializePluginContext(context); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
542 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
543 /* Check the version of the Orthanc core */ |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
544 if (OrthancPluginCheckVersion(context) == 0) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
545 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
546 OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
547 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
548 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
549 return -1; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
550 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
551 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
552 OrthancPlugins::LogWarning("AdvancedStorage plugin is initializing"); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
553 OrthancPluginSetDescription(context, "Provides alternative layout for your storage."); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
554 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
555 OrthancPlugins::OrthancConfiguration orthancConfiguration; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
556 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
557 OrthancPlugins::OrthancConfiguration advancedStorage; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
558 orthancConfiguration.GetSection(advancedStorage, "AdvancedStorage"); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
559 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
560 bool enabled = advancedStorage.GetBooleanValue("Enable", false); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
561 if (enabled) |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
562 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
563 /* |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
564 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
565 "AdvancedStorage": { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
566 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
567 // Enables/disables the plugin |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
568 "Enable": false, |
5081 | 569 |
570 // Enables/disables support for multiple StorageDirectories | |
571 "MultipleStorages" : { | |
572 "Storages" : { | |
573 // The storgae ids below may never change since they are stored in DB | |
574 // The storage path may change in case you move your data from one place to the other | |
575 "1" : "/var/lib/orthanc/db", | |
576 "2" : "/mnt/disk2/orthanc" | |
577 }, | |
578 | |
579 // the storage on which new data is stored. | |
580 // There's currently no automatic changes of disks | |
581 "CurrentStorage" : "2", | |
582 }, | |
583 | |
584 // Defines the storage structure and file namings. Right now, | |
585 // only the "OrthancDefault" value shall be used in a production environment. | |
586 // All other values are currently experimental | |
587 // "OrthancDefault" = same structure and file naming as default orthanc, | |
588 // "Preset1-StudyDatePatientID" = split(StudyDate)/PatientID - PatientName/StudyDescription/SeriesInstanceUID/uuid.ext | |
589 "NamingScheme" : "OrthancDefault", | |
590 | |
591 // Defines the maximum length for path used in the storage. If a file is longer | |
592 // than this limit, it is stored with the default orthanc naming scheme | |
593 // (and a warning is issued). | |
594 // Note, on Windows, the maximum path length is 260 bytes by default but can be increased | |
595 // through a configuration. | |
596 "MaxPathLength" : 256 | |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
597 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
598 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
599 */ |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
600 |
5081 | 601 fsyncOnWrite_ = orthancConfiguration.GetBooleanValue("SyncStorageArea", true); |
602 | |
603 const Json::Value& pluginJson = advancedStorage.GetJson(); | |
604 | |
605 namingScheme_ = advancedStorage.GetStringValue("NamingScheme", "OrthancDefault"); | |
606 | |
607 // if we have enabled multiple storage after files have been saved without this plugin, we still need the default StorageDirectory | |
608 rootPath_ = fs::path(orthancConfiguration.GetStringValue("StorageDirectory", "OrthancStorage")); | |
609 LOG(WARNING) << "AdvancedStorage - Path to the default storage area: " << rootPath_.string(); | |
610 | |
611 maxPathLength_ = orthancConfiguration.GetIntegerValue("MaxPathLength", 256); | |
612 LOG(WARNING) << "AdvancedStorage - Maximum path length: " << maxPathLength_; | |
613 | |
614 if (!rootPath_.is_absolute()) | |
615 { | |
616 LOG(ERROR) << "AdvancedStorage - Path to the default storage area should be an absolute path"; | |
617 return -1; | |
618 } | |
619 | |
620 if (rootPath_.size() > (maxPathLength_ - legacyPathLength)) | |
621 { | |
622 LOG(ERROR) << "AdvancedStorage - Path to the default storage is too long"; | |
623 return -1; | |
624 } | |
625 | |
626 if (pluginJson.isMember("MultipleStorages")) | |
627 { | |
628 multipleStoragesEnabled_ = true; | |
629 const Json::Value& multipleStoragesJson = pluginJson["MultipleStorages"]; | |
630 | |
631 if (multipleStoragesJson.isMember("Storages") && multipleStoragesJson.isObject() && multipleStoragesJson.isMember("CurrentStorage") && multipleStoragesJson["CurrentStorage"].isString()) | |
632 { | |
633 const Json::Value& storagesJson = multipleStoragesJson["Storages"]; | |
634 Json::Value::Members storageIds = storagesJson.getMemberNames(); | |
635 | |
636 for (Json::Value::Members::const_iterator it = storageIds.begin(); it != storageIds.end(); ++it) | |
637 { | |
638 const Json::Value& storagePath = storagesJson[*it]; | |
639 if (!storagePath.isString()) | |
640 { | |
641 LOG(ERROR) << "AdvancedStorage - Storage path is not a string " << *it; | |
642 return -1; | |
643 } | |
644 | |
645 rootPaths_[*it] = storagePath.asString(); | |
646 | |
647 if (!rootPaths_[*it].is_absolute()) | |
648 { | |
649 LOG(ERROR) << "AdvancedStorage - Storage path shall be absolute path '" << storagePath.asString() << "'"; | |
650 return -1; | |
651 } | |
652 | |
653 if (storagePath.asString().size() > (maxPathLength_ - legacyPathLength)) | |
654 { | |
655 LOG(ERROR) << "AdvancedStorage - Storage path is too long '" << storagePath.asString() << "'"; | |
656 return -1; | |
657 } | |
658 } | |
659 | |
660 currentStorageId_ = multipleStoragesJson["CurrentStorage"].asString(); | |
661 | |
662 if (rootPaths_.find(currentStorageId_) == rootPaths_.end()) | |
663 { | |
664 LOG(ERROR) << "AdvancedStorage - CurrentStorage is not defined in Storages list: " << currentStorageId_; | |
665 return -1; | |
666 } | |
667 | |
668 LOG(WARNING) << "AdvancedStorage - multiple storages enabled. Current storage : " << rootPaths_[currentStorageId_].string(); | |
669 } | |
670 } | |
5080
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
671 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
672 OrthancPluginRegisterStorageArea3(context, StorageCreateInstance, StorageCreateAttachment, StorageReadWhole, StorageReadRange, StorageRemove); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
673 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
674 else |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
675 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
676 OrthancPlugins::LogWarning("AdvancedStorage plugin is disabled by the configuration file"); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
677 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
678 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
679 return 0; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
680 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
681 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
682 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
683 ORTHANC_PLUGINS_API void OrthancPluginFinalize() |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
684 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
685 OrthancPlugins::LogWarning("AdvancedStorage plugin is finalizing"); |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
686 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
687 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
688 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
689 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
690 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
691 return "advanced-storage"; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
692 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
693 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
694 |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
695 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
696 { |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
697 return ORTHANC_PLUGIN_VERSION; |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
698 } |
d7274e43ea7c
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
699 } |