comparison OrthancServer/ServerJobs/StorageCommitmentScpJob.cpp @ 3638:ae866fc06df5 storage-commitment

serialization of StorageCommitmentScpJob
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 31 Jan 2020 16:53:23 +0100
parents bce6ee64f2a4
children 0c9a8f6d2349
comparison
equal deleted inserted replaced
3637:06eb59faf4da 3638:ae866fc06df5
35 #include "StorageCommitmentScpJob.h" 35 #include "StorageCommitmentScpJob.h"
36 36
37 #include "../../Core/DicomNetworking/DicomUserConnection.h" 37 #include "../../Core/DicomNetworking/DicomUserConnection.h"
38 #include "../../Core/Logging.h" 38 #include "../../Core/Logging.h"
39 #include "../../Core/OrthancException.h" 39 #include "../../Core/OrthancException.h"
40 #include "../../Core/SerializationToolbox.h"
40 #include "../OrthancConfiguration.h" 41 #include "../OrthancConfiguration.h"
41 #include "../ServerContext.h" 42 #include "../ServerContext.h"
43
44
45 static const char* ANSWER = "Answer";
46 static const char* CALLED_AET = "CalledAet";
47 static const char* FAILED_SOP_CLASS_UIDS = "FailedSopClassUids";
48 static const char* FAILED_SOP_INSTANCE_UIDS = "FailedSopInstanceUids";
49 static const char* LOOKUP = "Lookup";
50 static const char* REMOTE_MODALITY = "RemoteModality";
51 static const char* SOP_CLASS_UID = "SopClassUid";
52 static const char* SOP_INSTANCE_UID = "SopInstanceUid";
53 static const char* SUCCESS_SOP_CLASS_UIDS = "SuccessSopClassUids";
54 static const char* SUCCESS_SOP_INSTANCE_UIDS = "SuccessSopInstanceUids";
55 static const char* TRANSACTION_UID = "TransactionUid";
56 static const char* TYPE = "Type";
57
42 58
43 59
44 namespace Orthanc 60 namespace Orthanc
45 { 61 {
46 class StorageCommitmentScpJob::LookupCommand : public SetOfCommandsJob::ICommand 62 class StorageCommitmentScpJob::LookupCommand : public SetOfCommandsJob::ICommand
67 } 83 }
68 84
69 virtual void Serialize(Json::Value& target) const 85 virtual void Serialize(Json::Value& target) const
70 { 86 {
71 target = Json::objectValue; 87 target = Json::objectValue;
72 target["Type"] = "Lookup"; 88 target[TYPE] = LOOKUP;
73 target["SopClassUid"] = sopClassUid_; 89 target[SOP_CLASS_UID] = sopClassUid_;
74 target["SopInstanceUid"] = sopInstanceUid_; 90 target[SOP_INSTANCE_UID] = sopInstanceUid_;
75 } 91 }
76 }; 92 };
77 93
78 94
79 class StorageCommitmentScpJob::AnswerCommand : public SetOfCommandsJob::ICommand 95 class StorageCommitmentScpJob::AnswerCommand : public SetOfCommandsJob::ICommand
94 } 110 }
95 111
96 virtual void Serialize(Json::Value& target) const 112 virtual void Serialize(Json::Value& target) const
97 { 113 {
98 target = Json::objectValue; 114 target = Json::objectValue;
99 target["Type"] = "Answer"; 115 target[TYPE] = ANSWER;
100 } 116 }
101 }; 117 };
102 118
103 119
104 class StorageCommitmentScpJob::Unserializer : public SetOfCommandsJob::ICommandUnserializer 120 class StorageCommitmentScpJob::Unserializer : public SetOfCommandsJob::ICommandUnserializer
112 { 128 {
113 } 129 }
114 130
115 virtual ICommand* Unserialize(const Json::Value& source) const 131 virtual ICommand* Unserialize(const Json::Value& source) const
116 { 132 {
117 std::cout << "===================================\n"; 133 const std::string type = SerializationToolbox::ReadString(source, TYPE);
118 std::cout << source.toStyledString(); 134
119 135 if (type == LOOKUP)
120 /*DicomMap findAnswer; 136 {
121 findAnswer.Unserialize(source); 137 return new LookupCommand(that_,
122 return new Command(that_, findAnswer);*/ 138 SerializationToolbox::ReadString(source, SOP_CLASS_UID),
123 139 SerializationToolbox::ReadString(source, SOP_INSTANCE_UID));
124 throw OrthancException(ErrorCode_NotImplemented); 140 }
141 else if (type == ANSWER)
142 {
143 return new AnswerCommand(that_);
144 }
145 else
146 {
147 throw OrthancException(ErrorCode_BadFileFormat);
148 }
125 } 149 }
126 }; 150 };
127 151
128 152
129 void StorageCommitmentScpJob::LookupInstance(const std::string& sopClassUid, 153 void StorageCommitmentScpJob::LookupInstance(const std::string& sopClassUid,
233 257
234 void StorageCommitmentScpJob::GetPublicContent(Json::Value& value) 258 void StorageCommitmentScpJob::GetPublicContent(Json::Value& value)
235 { 259 {
236 SetOfCommandsJob::GetPublicContent(value); 260 SetOfCommandsJob::GetPublicContent(value);
237 261
238 value["LocalAet"] = calledAet_; 262 value["CalledAet"] = calledAet_;
239 value["RemoteAet"] = remoteModality_.GetApplicationEntityTitle(); 263 value["RemoteAet"] = remoteModality_.GetApplicationEntityTitle();
240 value["TransactionUid"] = transactionUid_; 264 value["TransactionUid"] = transactionUid_;
241 } 265 }
266
267
268
269 StorageCommitmentScpJob::StorageCommitmentScpJob(ServerContext& context,
270 const Json::Value& serialized) :
271 SetOfCommandsJob(new Unserializer(*this), serialized),
272 context_(context),
273 ready_(false)
274 {
275 transactionUid_ = SerializationToolbox::ReadString(serialized, TRANSACTION_UID);
276 remoteModality_ = RemoteModalityParameters(serialized[REMOTE_MODALITY]);
277 calledAet_ = SerializationToolbox::ReadString(serialized, CALLED_AET);
278 SerializationToolbox::ReadListOfStrings(successSopClassUids_, serialized, SUCCESS_SOP_CLASS_UIDS);
279 SerializationToolbox::ReadListOfStrings(successSopInstanceUids_, serialized, SUCCESS_SOP_INSTANCE_UIDS);
280 SerializationToolbox::ReadListOfStrings(failedSopClassUids_, serialized, FAILED_SOP_CLASS_UIDS);
281 SerializationToolbox::ReadListOfStrings(failedSopInstanceUids_, serialized, FAILED_SOP_INSTANCE_UIDS);
282
283 MarkAsReady();
284 }
285
286
287 bool StorageCommitmentScpJob::Serialize(Json::Value& target)
288 {
289 if (!SetOfCommandsJob::Serialize(target))
290 {
291 return false;
292 }
293 else
294 {
295 target[TRANSACTION_UID] = transactionUid_;
296 remoteModality_.Serialize(target[REMOTE_MODALITY], true /* force advanced format */);
297 target[CALLED_AET] = calledAet_;
298 SerializationToolbox::WriteListOfStrings(target, successSopClassUids_, SUCCESS_SOP_CLASS_UIDS);
299 SerializationToolbox::WriteListOfStrings(target, successSopInstanceUids_, SUCCESS_SOP_INSTANCE_UIDS);
300 SerializationToolbox::WriteListOfStrings(target, failedSopClassUids_, FAILED_SOP_CLASS_UIDS);
301 SerializationToolbox::WriteListOfStrings(target, failedSopInstanceUids_, FAILED_SOP_INSTANCE_UIDS);
302 return true;
303 }
304 }
242 } 305 }