annotate OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.cpp @ 4224:38d446c9ee1d

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Sep 2020 17:59:09 +0200
parents 2007ab69ac16
children 50b0c69b653a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3374
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * the License, or (at your option) any later version.
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
15 * Lesser General Public License for more details.
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * <http://www.gnu.org/licenses/>.
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "../PrecompiledHeaders.h"
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "SetOfInstancesJob.h"
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../OrthancException.h"
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
27 #include "../SerializationToolbox.h"
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
29 #include <cassert>
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
30
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace Orthanc
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
33 class SetOfInstancesJob::InstanceCommand : public SetOfInstancesJob::ICommand
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
34 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
35 private:
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
36 SetOfInstancesJob& that_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
37 std::string instance_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
38
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
39 public:
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
40 InstanceCommand(SetOfInstancesJob& that,
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
41 const std::string& instance) :
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
42 that_(that),
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
43 instance_(instance)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
44 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
45 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
46
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
47 const std::string& GetInstance() const
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
48 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
49 return instance_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
50 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
51
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
52 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
53 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
54 if (!that_.HandleInstance(instance_))
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
55 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
56 that_.failedInstances_.insert(instance_);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
57 return false;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
58 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
59 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
60 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
61 return true;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
62 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
63 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
64
3674
9201a7858cce fix warnings with recent wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3658
diff changeset
65 virtual void Serialize(Json::Value& target) const ORTHANC_OVERRIDE
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
66 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
67 target = instance_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
68 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
69 };
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
70
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
71
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
72 class SetOfInstancesJob::TrailingStepCommand : public SetOfInstancesJob::ICommand
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
73 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
74 private:
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
75 SetOfInstancesJob& that_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
76
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
77 public:
4202
2007ab69ac16 moving ORTHANC_FORCE_INLINE and ORTHANC_OVERRIDE from Enumerations.h to Compatibility.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
78 explicit TrailingStepCommand(SetOfInstancesJob& that) :
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
79 that_(that)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
80 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
81 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
82
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
83 virtual bool Execute(const std::string& jobId) ORTHANC_OVERRIDE
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
84 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
85 return that_.HandleTrailingStep();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
86 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
87
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
88 virtual void Serialize(Json::Value& target) const ORTHANC_OVERRIDE
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
89 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
90 target = Json::nullValue;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
91 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
92 };
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
93
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
94
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
95 class SetOfInstancesJob::InstanceUnserializer :
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
96 public SetOfInstancesJob::ICommandUnserializer
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
97 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
98 private:
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
99 SetOfInstancesJob& that_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
100
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
101 public:
4202
2007ab69ac16 moving ORTHANC_FORCE_INLINE and ORTHANC_OVERRIDE from Enumerations.h to Compatibility.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
102 explicit InstanceUnserializer(SetOfInstancesJob& that) :
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
103 that_(that)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
104 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
105 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
106
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
107 virtual ICommand* Unserialize(const Json::Value& source) const
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
108 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
109 if (source.type() == Json::nullValue)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
110 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
111 return new TrailingStepCommand(that_);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
112 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
113 else if (source.type() == Json::stringValue)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
114 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
115 return new InstanceCommand(that_, source.asString());
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
116 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
117 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
118 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
119 throw OrthancException(ErrorCode_BadFileFormat);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
120 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
121 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
122 };
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
123
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
124
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
125 SetOfInstancesJob::SetOfInstancesJob() :
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
126 hasTrailingStep_(false)
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 void SetOfInstancesJob::AddInstance(const std::string& instance)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
133 AddCommand(new InstanceCommand(*this, instance));
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
137 void SetOfInstancesJob::AddTrailingStep()
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
139 AddCommand(new TrailingStepCommand(*this));
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
140 hasTrailingStep_ = true;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
141 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
142
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
143
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
144 size_t SetOfInstancesJob::GetInstancesCount() const
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
145 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
146 if (hasTrailingStep_)
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
148 assert(GetCommandsCount() > 0);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
149 return GetCommandsCount() - 1;
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 else
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
153 return GetCommandsCount();
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
157
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
158 const std::string& SetOfInstancesJob::GetInstance(size_t index) const
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
159 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
160 if (index >= GetInstancesCount())
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
161 {
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
162 throw OrthancException(ErrorCode_ParameterOutOfRange);
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
163 }
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
164 else
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
165 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
166 return dynamic_cast<const InstanceCommand&>(GetCommand(index)).GetInstance();
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
170
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
171 void SetOfInstancesJob::Start()
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
172 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
173 SetOfCommandsJob::Start();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
174 }
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
175
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
176
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
177 void SetOfInstancesJob::Reset()
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
178 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
179 SetOfCommandsJob::Reset();
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
180
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
181 failedInstances_.clear();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
182 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
183
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
184
3374
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
185 static const char* KEY_TRAILING_STEP = "TrailingStep";
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
186 static const char* KEY_FAILED_INSTANCES = "FailedInstances";
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
187 static const char* KEY_PARENT_RESOURCES = "ParentResources";
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
188
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
189 void SetOfInstancesJob::GetPublicContent(Json::Value& target)
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
190 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
191 SetOfCommandsJob::GetPublicContent(target);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
192 target["InstancesCount"] = static_cast<uint32_t>(GetInstancesCount());
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
193 target["FailedInstancesCount"] = static_cast<uint32_t>(failedInstances_.size());
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
194
3374
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
195 if (!parentResources_.empty())
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
196 {
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
197 SerializationToolbox::WriteSetOfStrings(target, parentResources_, KEY_PARENT_RESOURCES);
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
198 }
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
199 }
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2652
diff changeset
200
2663
228e2783ce83 some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
201
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
202 bool SetOfInstancesJob::Serialize(Json::Value& target)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
203 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
204 if (SetOfCommandsJob::Serialize(target))
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
205 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
206 target[KEY_TRAILING_STEP] = hasTrailingStep_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
207 SerializationToolbox::WriteSetOfStrings(target, failedInstances_, KEY_FAILED_INSTANCES);
3374
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
208 SerializationToolbox::WriteSetOfStrings(target, parentResources_, KEY_PARENT_RESOURCES);
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
209 return true;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
210 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
211 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
212 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
213 return false;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
214 }
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
216
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
217
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
218 SetOfInstancesJob::SetOfInstancesJob(const Json::Value& source) :
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
219 SetOfCommandsJob(new InstanceUnserializer(*this), source)
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
220 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
221 SerializationToolbox::ReadSetOfStrings(failedInstances_, source, KEY_FAILED_INSTANCES);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
222
3374
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
223 if (source.isMember(KEY_PARENT_RESOURCES))
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
224 {
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
225 // Backward compatibility with Orthanc <= 1.5.6
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
226 SerializationToolbox::ReadSetOfStrings(parentResources_, source, KEY_PARENT_RESOURCES);
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
227 }
d0d6bd633e4c Reporting of "ParentResources" in "DicomModalityStore" and "DicomModalityStore" jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
228
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
229 if (source.isMember(KEY_TRAILING_STEP))
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
230 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
231 hasTrailingStep_ = SerializationToolbox::ReadBoolean(source, KEY_TRAILING_STEP);
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
232 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
233 else
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
234 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
235 // Backward compatibility with Orthanc <= 1.4.2
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
236 hasTrailingStep_ = false;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
237 }
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
238 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
239
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
240
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }