annotate Framework/Oracle/GenericOracleRunner.cpp @ 1128:8e3763d1736a broker

removing CustomOracleCommand
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 05 Nov 2019 22:39:25 +0100
parents a8bf81756839
children 87fbeb823375
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "GenericOracleRunner.h"
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
24 #if !defined(ORTHANC_ENABLE_DCMTK)
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
25 # error The macro ORTHANC_ENABLE_DCMTK must be defined
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
26 #endif
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
27
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "GetOrthancImageCommand.h"
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "GetOrthancWebViewerJpegCommand.h"
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "HttpCommand.h"
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include "OracleCommandExceptionMessage.h"
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include "OrthancRestApiCommand.h"
1104
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
33 #include "ReadFileCommand.h"
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
35 #if ORTHANC_ENABLE_DCMTK == 1
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
36 # include "ParseDicomFileCommand.h"
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
37 # include <dcmtk/dcmdata/dcdeftag.h>
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
38 #endif
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
39
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <Core/Compression/GzipCompressor.h>
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <Core/HttpClient.h>
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <Core/OrthancException.h>
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 #include <Core/Toolbox.h>
1104
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
44 #include <Core/SystemToolbox.h>
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
45
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
46 #include <boost/filesystem.hpp>
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
48
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 namespace OrthancStone
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 static void CopyHttpHeaders(Orthanc::HttpClient& client,
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 const Orthanc::HttpClient::HttpHeaders& headers)
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 for (Orthanc::HttpClient::HttpHeaders::const_iterator
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 it = headers.begin(); it != headers.end(); it++ )
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 client.AddHeader(it->first, it->second);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 static void DecodeAnswer(std::string& answer,
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 const Orthanc::HttpClient::HttpHeaders& headers)
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 Orthanc::HttpCompression contentEncoding = Orthanc::HttpCompression_None;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 for (Orthanc::HttpClient::HttpHeaders::const_iterator it = headers.begin();
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 it != headers.end(); ++it)
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 std::string s;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 Orthanc::Toolbox::ToLowerCase(s, it->first);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 if (s == "content-encoding")
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 if (it->second == "gzip")
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 contentEncoding = Orthanc::HttpCompression_Gzip;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 else
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol,
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 "Unsupported HTTP Content-Encoding: " + it->second);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 break;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 if (contentEncoding == Orthanc::HttpCompression_Gzip)
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 std::string compressed;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 answer.swap(compressed);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 Orthanc::GzipCompressor compressor;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 compressor.Uncompress(answer, compressed.c_str(), compressed.size());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 LOG(INFO) << "Uncompressing gzip Encoding: from " << compressed.size()
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 << " to " << answer.size() << " bytes";
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
103 static IMessage* Execute(const HttpCommand& command)
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 Orthanc::HttpClient client;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 client.SetUrl(command.GetUrl());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 client.SetMethod(command.GetMethod());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 client.SetTimeout(command.GetTimeout());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 CopyHttpHeaders(client, command.GetHttpHeaders());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
1079
e6d2ff8f1ab4 credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1077
diff changeset
112 if (command.HasCredentials())
e6d2ff8f1ab4 credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1077
diff changeset
113 {
e6d2ff8f1ab4 credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1077
diff changeset
114 client.SetCredentials(command.GetUsername().c_str(), command.GetPassword().c_str());
e6d2ff8f1ab4 credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1077
diff changeset
115 }
e6d2ff8f1ab4 credentials in HttpCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1077
diff changeset
116
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 if (command.GetMethod() == Orthanc::HttpMethod_Post ||
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 command.GetMethod() == Orthanc::HttpMethod_Put)
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 client.SetBody(command.GetBody());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 std::string answer;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 Orthanc::HttpClient::HttpHeaders answerHeaders;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 client.ApplyAndThrowException(answer, answerHeaders);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 DecodeAnswer(answer, answerHeaders);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
129 return new HttpCommand::SuccessMessage(command, answerHeaders, answer);
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
133 static IMessage* Execute(const Orthanc::WebServiceParameters& orthanc,
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
134 const OrthancRestApiCommand& command)
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 Orthanc::HttpClient client(orthanc, command.GetUri());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 client.SetMethod(command.GetMethod());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 client.SetTimeout(command.GetTimeout());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 CopyHttpHeaders(client, command.GetHttpHeaders());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 if (command.GetMethod() == Orthanc::HttpMethod_Post ||
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 command.GetMethod() == Orthanc::HttpMethod_Put)
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 client.SetBody(command.GetBody());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 std::string answer;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 Orthanc::HttpClient::HttpHeaders answerHeaders;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 client.ApplyAndThrowException(answer, answerHeaders);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 DecodeAnswer(answer, answerHeaders);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
154 return new OrthancRestApiCommand::SuccessMessage(command, answerHeaders, answer);
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
158 static IMessage* Execute(const Orthanc::WebServiceParameters& orthanc,
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
159 const GetOrthancImageCommand& command)
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 Orthanc::HttpClient client(orthanc, command.GetUri());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 client.SetTimeout(command.GetTimeout());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 CopyHttpHeaders(client, command.GetHttpHeaders());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 std::string answer;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 Orthanc::HttpClient::HttpHeaders answerHeaders;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 client.ApplyAndThrowException(answer, answerHeaders);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 DecodeAnswer(answer, answerHeaders);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
172 return command.ProcessHttpAnswer(answer, answerHeaders);
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
176 static IMessage* Execute(const Orthanc::WebServiceParameters& orthanc,
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
177 const GetOrthancWebViewerJpegCommand& command)
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 Orthanc::HttpClient client(orthanc, command.GetUri());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 client.SetTimeout(command.GetTimeout());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 CopyHttpHeaders(client, command.GetHttpHeaders());
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 std::string answer;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 Orthanc::HttpClient::HttpHeaders answerHeaders;
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 client.ApplyAndThrowException(answer, answerHeaders);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 DecodeAnswer(answer, answerHeaders);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
190 return command.ProcessHttpAnswer(answer);
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
194 static std::string GetPath(const std::string& root,
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
195 const std::string& file)
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
196 {
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
197 boost::filesystem::path a(root);
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
198 boost::filesystem::path b(file);
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
199
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
200 boost::filesystem::path c;
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
201 if (b.is_absolute())
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
202 {
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
203 c = b;
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
204 }
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
205 else
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
206 {
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
207 c = a / b;
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
208 }
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
209
1111
3730956f41a5 ParseDicomFileCommand::GetDicomDirPath()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1110
diff changeset
210 LOG(TRACE) << "Oracle reading file: " << c.string();
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
211 return c.string();
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
212 }
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
213
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
214
1104
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
215 static IMessage* Execute(const std::string& root,
1128
8e3763d1736a removing CustomOracleCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
216 ReadFileCommand& command)
1104
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
217 {
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
218 std::string path = GetPath(root, command.GetPath());
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
219
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
220 std::string content;
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
221 Orthanc::SystemToolbox::ReadFile(content, path, true /* log */);
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
222
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
223 return new ReadFileCommand::SuccessMessage(command, content);
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
224 }
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
225
1104
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
226
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
227 #if ORTHANC_ENABLE_DCMTK == 1
1124
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
228 static ParseDicomFileCommand::SuccessMessage* Execute(const std::string& root,
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
229 const ParseDicomFileCommand& command)
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
230 {
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
231 std::string path = GetPath(root, command.GetPath());
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
232
1116
a08699daf78b ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1111
diff changeset
233 if (!Orthanc::SystemToolbox::IsRegularFile(path))
a08699daf78b ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1111
diff changeset
234 {
a08699daf78b ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1111
diff changeset
235 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentFile);
a08699daf78b ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1111
diff changeset
236 }
a08699daf78b ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1111
diff changeset
237
a08699daf78b ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1111
diff changeset
238 uint64_t fileSize = Orthanc::SystemToolbox::GetFileSize(path);
a08699daf78b ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1111
diff changeset
239
a08699daf78b ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1111
diff changeset
240 // Check for 32bit systems
a08699daf78b ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1111
diff changeset
241 if (fileSize != static_cast<uint64_t>(static_cast<size_t>(fileSize)))
a08699daf78b ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1111
diff changeset
242 {
a08699daf78b ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1111
diff changeset
243 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory);
a08699daf78b ParsedDicomFileCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1111
diff changeset
244 }
1124
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
245
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
246 DcmFileFormat dicom;
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
247 bool ok;
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
248
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
249 if (command.IsPixelDataIncluded())
1104
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
250 {
1124
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
251 ok = dicom.loadFile(path.c_str()).good();
1104
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
252 }
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
253 else
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
254 {
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
255 #if DCMTK_VERSION_NUMBER >= 362
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
256 // NB : We could stop at (0x3007, 0x0000) instead of
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
257 // DCM_PixelData, cf. the Orthanc::DICOM_TAG_* constants
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
258
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
259 static const DcmTagKey STOP = DCM_PixelData;
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
260 //static const DcmTagKey STOP(0x3007, 0x0000);
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
261
1124
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
262 ok = dicom.loadFileUntilTag(path.c_str(), EXS_Unknown, EGL_noChange,
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
263 DCM_MaxReadLength, ERM_autoDetect, STOP).good();
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
264 #else
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
265 // The primitive "loadFileUntilTag" was introduced in DCMTK 3.6.2
1124
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
266 ok = dicom.loadFile(path.c_str()).good();
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
267 #endif
1104
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
268 }
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
269
1124
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
270 printf("Reading %s\n", path.c_str());
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
271
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
272 if (ok)
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
273 {
1124
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
274 return new ParseDicomFileCommand::SuccessMessage
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
275 (command, dicom, static_cast<size_t>(fileSize), command.IsPixelDataIncluded());
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
276 }
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
277 else
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
278 {
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
279 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
280 "Cannot parse file: " + path);
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
281 }
1104
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
282 }
1124
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
283
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
284
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
285 static ParseDicomFileCommand::SuccessMessage* Execute(boost::shared_ptr<ParsedDicomFileCache> cache,
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
286 const std::string& root,
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
287 const ParseDicomFileCommand& command)
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
288 {
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
289 #if 0
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
290 // The code to use the cache is buggy in multithreaded environments => TODO FIX
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
291 if (cache.get())
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
292 {
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
293 {
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
294 ParsedDicomFileCache::Reader reader(*cache, command.GetPath());
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
295 if (reader.IsValid() &&
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
296 (!command.IsPixelDataIncluded() ||
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
297 reader.HasPixelData()))
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
298 {
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
299 // Reuse the DICOM file from the cache
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
300 return new ParseDicomFileCommand::SuccessMessage(
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
301 command, reader.GetDicom(), reader.GetFileSize(), reader.HasPixelData());
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
302 }
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
303 }
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
304
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
305 // Not in the cache, first read and parse the DICOM file
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
306 std::auto_ptr<ParseDicomFileCommand::SuccessMessage> message(Execute(root, command));
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
307
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
308 // Secondly, store it into the cache for future use
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
309 assert(&message->GetOrigin() == &command);
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
310 cache->Acquire(message->GetOrigin().GetPath(), message->GetDicom(),
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
311 message->GetFileSize(), message->HasPixelData());
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
312
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
313 return message.release();
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
314 }
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
315 else
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
316 {
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
317 // No cache available
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
318 return Execute(root, command);
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
319 }
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
320 #else
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
321 return Execute(root, command);
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
322 #endif
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
323 }
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
324
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
325 #endif
1104
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
326
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
327
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
328 IMessage* GenericOracleRunner::Run(IOracleCommand& command)
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 try
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 switch (command.GetType())
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 case IOracleCommand::Type_Sleep:
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadParameterType,
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 "Sleep command cannot be executed by the runner");
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 case IOracleCommand::Type_Http:
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
339 return Execute(dynamic_cast<const HttpCommand&>(command));
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 case IOracleCommand::Type_OrthancRestApi:
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
342 return Execute(orthanc_, dynamic_cast<const OrthancRestApiCommand&>(command));
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 case IOracleCommand::Type_GetOrthancImage:
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
345 return Execute(orthanc_, dynamic_cast<const GetOrthancImageCommand&>(command));
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 case IOracleCommand::Type_GetOrthancWebViewerJpeg:
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
348 return Execute(orthanc_, dynamic_cast<const GetOrthancWebViewerJpegCommand&>(command));
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349
1104
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
350 case IOracleCommand::Type_ReadFile:
1128
8e3763d1736a removing CustomOracleCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
351 return Execute(rootDirectory_, dynamic_cast<ReadFileCommand&>(command));
1104
98cdfe5768a4 ReadFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1098
diff changeset
352
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
353 case IOracleCommand::Type_ParseDicomFile:
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
354 #if ORTHANC_ENABLE_DCMTK == 1
1124
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
355 return Execute(dicomCache_, rootDirectory_,
a8bf81756839 unsuccessful attempt to cache ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1116
diff changeset
356 dynamic_cast<const ParseDicomFileCommand&>(command));
1110
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
357 #else
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
358 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented,
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
359 "DCMTK must be enabled to parse DICOM files");
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
360 #endif
b82b74d13830 ParseDicomFileCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1104
diff changeset
361
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 default:
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 catch (Orthanc::OrthancException& e)
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 LOG(ERROR) << "Exception within the oracle: " << e.What();
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
369 return new OracleCommandExceptionMessage(command, e);
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 catch (...)
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 {
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 LOG(ERROR) << "Threaded exception within the oracle";
1098
17660df24c36 simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1079
diff changeset
374 return new OracleCommandExceptionMessage(command, Orthanc::ErrorCode_InternalError);
1077
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 }
d7a18a3cd6f9 IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 }