Mercurial > hg > orthanc
annotate OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp @ 3658:2d90dd30858c storage-commitment
providing job ID to the IJob::Step() methods
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 10 Feb 2020 16:44:26 +0100 |
parents | 115f82775c46 |
children | 08eb0f93c491 |
rev | line source |
---|---|
3636 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
3642
fddf3fc82362
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3639
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
3636 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeadersServer.h" | |
35 #include "StorageCommitmentScpJob.h" | |
36 | |
37 #include "../../Core/DicomNetworking/DicomUserConnection.h" | |
38 #include "../../Core/Logging.h" | |
39 #include "../../Core/OrthancException.h" | |
3638
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
40 #include "../../Core/SerializationToolbox.h" |
3636 | 41 #include "../OrthancConfiguration.h" |
42 #include "../ServerContext.h" | |
43 | |
44 | |
3638
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
45 static const char* ANSWER = "Answer"; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
46 static const char* CALLED_AET = "CalledAet"; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
47 static const char* LOOKUP = "Lookup"; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
48 static const char* REMOTE_MODALITY = "RemoteModality"; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
49 static const char* SOP_CLASS_UID = "SopClassUid"; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
50 static const char* SOP_INSTANCE_UID = "SopInstanceUid"; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
51 static const char* TRANSACTION_UID = "TransactionUid"; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
52 static const char* TYPE = "Type"; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
53 |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
54 |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
55 |
3636 | 56 namespace Orthanc |
57 { | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
58 class StorageCommitmentScpJob::StorageCommitmentCommand : public SetOfCommandsJob::ICommand |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
59 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
60 public: |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
61 virtual bool IsAnswer() const = 0; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
62 }; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
63 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
64 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
65 class StorageCommitmentScpJob::LookupCommand : public StorageCommitmentCommand |
3636 | 66 { |
67 private: | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
68 ServerContext& context_; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
69 bool hasFailureReason_; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
70 std::string sopClassUid_; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
71 std::string sopInstanceUid_; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
72 StorageCommitmentFailureReason failureReason_; |
3636 | 73 |
74 public: | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
75 LookupCommand(ServerContext& context, |
3636 | 76 const std::string& sopClassUid, |
77 const std::string& sopInstanceUid) : | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
78 context_(context), |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
79 hasFailureReason_(false), |
3636 | 80 sopClassUid_(sopClassUid), |
81 sopInstanceUid_(sopInstanceUid) | |
82 { | |
83 } | |
84 | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
85 virtual bool IsAnswer() const |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
86 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
87 return false; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
88 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
89 |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3657
diff
changeset
|
90 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE |
3636 | 91 { |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
92 if (hasFailureReason_) |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
93 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
94 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
95 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
96 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
97 bool success = false; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
98 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
99 try |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
100 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
101 std::vector<std::string> orthancId; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
102 context_.GetIndex().LookupIdentifierExact(orthancId, ResourceType_Instance, DICOM_TAG_SOP_INSTANCE_UID, sopInstanceUid_); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
103 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
104 if (orthancId.size() == 1) |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
105 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
106 std::string a, b; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
107 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
108 // Make sure that the DICOM file can be re-read by DCMTK |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
109 // from the file storage, and that the actual SOP |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
110 // class/instance UIDs do match |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
111 ServerContext::DicomCacheLocker locker(context_, orthancId[0]); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
112 if (locker.GetDicom().GetTagValue(a, DICOM_TAG_SOP_CLASS_UID) && |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
113 locker.GetDicom().GetTagValue(b, DICOM_TAG_SOP_INSTANCE_UID) && |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
114 a == sopClassUid_ && |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
115 b == sopInstanceUid_) |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
116 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
117 success = true; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
118 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
119 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
120 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
121 catch (OrthancException&) |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
122 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
123 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
124 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
125 LOG(INFO) << " Storage commitment SCP job: " << (success ? "Success" : "Failure") |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
126 << " while looking for " << sopClassUid_ << " / " << sopInstanceUid_; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
127 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
128 failureReason_ = (success ? |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
129 StorageCommitmentFailureReason_Success : |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
130 StorageCommitmentFailureReason_NoSuchObjectInstance /* 0x0112 == 274 */); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
131 hasFailureReason_ = true; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
132 |
3636 | 133 return true; |
134 } | |
135 | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
136 const std::string& GetSopClassUid() const |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
137 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
138 return sopClassUid_; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
139 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
140 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
141 const std::string& GetSopInstanceUid() const |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
142 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
143 return sopInstanceUid_; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
144 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
145 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
146 StorageCommitmentFailureReason GetFailureReason() const |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
147 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
148 if (hasFailureReason_) |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
149 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
150 return failureReason_; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
151 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
152 else |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
153 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
154 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
155 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
156 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
157 |
3636 | 158 virtual void Serialize(Json::Value& target) const |
159 { | |
160 target = Json::objectValue; | |
3638
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
161 target[TYPE] = LOOKUP; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
162 target[SOP_CLASS_UID] = sopClassUid_; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
163 target[SOP_INSTANCE_UID] = sopInstanceUid_; |
3636 | 164 } |
165 }; | |
166 | |
167 | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
168 class StorageCommitmentScpJob::AnswerCommand : public StorageCommitmentCommand |
3636 | 169 { |
170 private: | |
171 StorageCommitmentScpJob& that_; | |
172 | |
173 public: | |
174 AnswerCommand(StorageCommitmentScpJob& that) : | |
175 that_(that) | |
176 { | |
3639
0c9a8f6d2349
better unserialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3638
diff
changeset
|
177 if (that_.ready_) |
0c9a8f6d2349
better unserialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3638
diff
changeset
|
178 { |
0c9a8f6d2349
better unserialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3638
diff
changeset
|
179 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
0c9a8f6d2349
better unserialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3638
diff
changeset
|
180 } |
0c9a8f6d2349
better unserialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3638
diff
changeset
|
181 else |
0c9a8f6d2349
better unserialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3638
diff
changeset
|
182 { |
0c9a8f6d2349
better unserialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3638
diff
changeset
|
183 that_.ready_ = true; |
0c9a8f6d2349
better unserialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3638
diff
changeset
|
184 } |
3636 | 185 } |
186 | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
187 virtual bool IsAnswer() const |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
188 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
189 return true; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
190 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
191 |
3658
2d90dd30858c
providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3657
diff
changeset
|
192 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE |
3636 | 193 { |
194 that_.Answer(); | |
195 return true; | |
196 } | |
197 | |
198 virtual void Serialize(Json::Value& target) const | |
199 { | |
200 target = Json::objectValue; | |
3638
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
201 target[TYPE] = ANSWER; |
3636 | 202 } |
203 }; | |
204 | |
205 | |
206 class StorageCommitmentScpJob::Unserializer : public SetOfCommandsJob::ICommandUnserializer | |
207 { | |
208 private: | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
209 StorageCommitmentScpJob& that_; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
210 ServerContext& context_; |
3636 | 211 |
212 public: | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
213 Unserializer(StorageCommitmentScpJob& that, |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
214 ServerContext& context) : |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
215 that_(that), |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
216 context_(context) |
3636 | 217 { |
3639
0c9a8f6d2349
better unserialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3638
diff
changeset
|
218 that_.ready_ = false; |
3636 | 219 } |
220 | |
221 virtual ICommand* Unserialize(const Json::Value& source) const | |
222 { | |
3638
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
223 const std::string type = SerializationToolbox::ReadString(source, TYPE); |
3636 | 224 |
3638
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
225 if (type == LOOKUP) |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
226 { |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
227 return new LookupCommand(context_, |
3638
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
228 SerializationToolbox::ReadString(source, SOP_CLASS_UID), |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
229 SerializationToolbox::ReadString(source, SOP_INSTANCE_UID)); |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
230 } |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
231 else if (type == ANSWER) |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
232 { |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
233 return new AnswerCommand(that_); |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
234 } |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
235 else |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
236 { |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
237 throw OrthancException(ErrorCode_BadFileFormat); |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
238 } |
3636 | 239 } |
240 }; | |
241 | |
242 | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
243 void StorageCommitmentScpJob::Answer() |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
244 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
245 LOG(INFO) << " Storage commitment SCP job: Sending answer"; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
246 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
247 const size_t n = GetCommandsCount(); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
248 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
249 if (n == 0) |
3636 | 250 { |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
251 throw OrthancException(ErrorCode_InternalError); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
252 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
253 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
254 std::vector<std::string> sopClassUids, sopInstanceUids; |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
255 std::vector<StorageCommitmentFailureReason> failureReasons; |
3636 | 256 |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
257 sopClassUids.reserve(n); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
258 sopInstanceUids.reserve(n); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
259 failureReasons.reserve(n); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
260 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
261 for (size_t i = 0; i < n; i++) |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
262 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
263 const StorageCommitmentCommand& command = dynamic_cast<const StorageCommitmentCommand&>(GetCommand(i)); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
264 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
265 if (i == n - 1) |
3636 | 266 { |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
267 if (!command.IsAnswer()) |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
268 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
269 throw OrthancException(ErrorCode_InternalError); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
270 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
271 } |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
272 else |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
273 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
274 if (command.IsAnswer()) |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
275 { |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
276 throw OrthancException(ErrorCode_InternalError); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
277 } |
3636 | 278 |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
279 const LookupCommand& lookup = dynamic_cast<const LookupCommand&>(command); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
280 |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
281 sopClassUids.push_back(lookup.GetSopClassUid()); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
282 sopInstanceUids.push_back(lookup.GetSopInstanceUid()); |
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
283 failureReasons.push_back(lookup.GetFailureReason()); |
3636 | 284 } |
285 } | |
286 | |
287 DicomUserConnection scu(calledAet_, remoteModality_); | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
288 scu.ReportStorageCommitment(transactionUid_, sopClassUids, sopInstanceUids, failureReasons); |
3636 | 289 } |
290 | |
291 | |
292 StorageCommitmentScpJob::StorageCommitmentScpJob(ServerContext& context, | |
293 const std::string& transactionUid, | |
294 const std::string& remoteAet, | |
295 const std::string& calledAet) : | |
296 context_(context), | |
297 ready_(false), | |
298 transactionUid_(transactionUid), | |
299 calledAet_(calledAet) | |
300 { | |
301 { | |
302 OrthancConfiguration::ReaderLock lock; | |
303 if (!lock.GetConfiguration().LookupDicomModalityUsingAETitle(remoteModality_, remoteAet)) | |
304 { | |
305 throw OrthancException(ErrorCode_InexistentItem, | |
306 "Unknown remote modality for storage commitment SCP: " + remoteAet); | |
307 } | |
308 } | |
309 } | |
310 | |
311 | |
312 void StorageCommitmentScpJob::AddInstance(const std::string& sopClassUid, | |
313 const std::string& sopInstanceUid) | |
314 { | |
315 if (ready_) | |
316 { | |
317 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
318 } | |
319 else | |
320 { | |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
321 AddCommand(new LookupCommand(context_, sopClassUid, sopInstanceUid)); |
3636 | 322 } |
323 } | |
324 | |
325 | |
326 void StorageCommitmentScpJob::MarkAsReady() | |
327 { | |
3639
0c9a8f6d2349
better unserialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3638
diff
changeset
|
328 AddCommand(new AnswerCommand(*this)); |
3636 | 329 } |
330 | |
331 | |
332 void StorageCommitmentScpJob::GetPublicContent(Json::Value& value) | |
333 { | |
334 SetOfCommandsJob::GetPublicContent(value); | |
335 | |
3638
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
336 value["CalledAet"] = calledAet_; |
3636 | 337 value["RemoteAet"] = remoteModality_.GetApplicationEntityTitle(); |
338 value["TransactionUid"] = transactionUid_; | |
339 } | |
3638
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
340 |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
341 |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
342 StorageCommitmentScpJob::StorageCommitmentScpJob(ServerContext& context, |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
343 const Json::Value& serialized) : |
3657
115f82775c46
handling of storage commitment failure reasons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3642
diff
changeset
|
344 SetOfCommandsJob(new Unserializer(*this, context), serialized), |
3639
0c9a8f6d2349
better unserialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3638
diff
changeset
|
345 context_(context) |
3638
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
346 { |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
347 transactionUid_ = SerializationToolbox::ReadString(serialized, TRANSACTION_UID); |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
348 remoteModality_ = RemoteModalityParameters(serialized[REMOTE_MODALITY]); |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
349 calledAet_ = SerializationToolbox::ReadString(serialized, CALLED_AET); |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
350 } |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
351 |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
352 |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
353 bool StorageCommitmentScpJob::Serialize(Json::Value& target) |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
354 { |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
355 if (!SetOfCommandsJob::Serialize(target)) |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
356 { |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
357 return false; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
358 } |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
359 else |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
360 { |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
361 target[TRANSACTION_UID] = transactionUid_; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
362 remoteModality_.Serialize(target[REMOTE_MODALITY], true /* force advanced format */); |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
363 target[CALLED_AET] = calledAet_; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
364 return true; |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
365 } |
ae866fc06df5
serialization of StorageCommitmentScpJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3636
diff
changeset
|
366 } |
3636 | 367 } |