annotate Core/JobsEngine/SetOfInstancesJob.cpp @ 3218:9a83d94b2a1e

kanji encoding
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 14 Feb 2019 11:32:14 +0100
parents 4e43e67f8ecf
children d0d6bd633e4c
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
3060
4e43e67f8ecf preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2860
diff changeset
5 * Copyright (C) 2017-2019 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
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../PrecompiledHeaders.h"
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "SetOfInstancesJob.h"
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../OrthancException.h"
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
38 #include "../SerializationToolbox.h"
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
40 #include <cassert>
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
41
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 namespace Orthanc
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
44 class SetOfInstancesJob::InstanceCommand : public SetOfInstancesJob::ICommand
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 private:
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
47 SetOfInstancesJob& that_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
48 std::string instance_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
49
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
50 public:
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
51 InstanceCommand(SetOfInstancesJob& that,
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
52 const std::string& instance) :
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
53 that_(that),
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
54 instance_(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 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
57
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
58 const std::string& GetInstance() const
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
59 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
60 return instance_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
61 }
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 virtual bool Execute()
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
64 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
65 if (!that_.HandleInstance(instance_))
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 that_.failedInstances_.insert(instance_);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
68 return false;
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 else
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 return true;
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 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
75
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
76 virtual void Serialize(Json::Value& target) const
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
77 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
78 target = instance_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
79 }
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
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
83 class SetOfInstancesJob::TrailingStepCommand : public SetOfInstancesJob::ICommand
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 private:
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
86 SetOfInstancesJob& that_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
87
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
88 public:
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
89 TrailingStepCommand(SetOfInstancesJob& that) :
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
90 that_(that)
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 virtual bool Execute()
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
95 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
96 return that_.HandleTrailingStep();
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
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
99 virtual void Serialize(Json::Value& target) const
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 target = Json::nullValue;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
102 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
103 };
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 class SetOfInstancesJob::InstanceUnserializer :
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
107 public SetOfInstancesJob::ICommandUnserializer
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 private:
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
110 SetOfInstancesJob& that_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
111
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
112 public:
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
113 InstanceUnserializer(SetOfInstancesJob& that) :
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
114 that_(that)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
115 {
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
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
118 virtual ICommand* Unserialize(const Json::Value& source) const
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
119 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
120 if (source.type() == Json::nullValue)
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 return new TrailingStepCommand(that_);
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 else if (source.type() == Json::stringValue)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
125 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
126 return new InstanceCommand(that_, source.asString());
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
127 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
128 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
129 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
130 throw OrthancException(ErrorCode_BadFileFormat);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
131 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
132 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
133 };
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
134
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
135
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
136 SetOfInstancesJob::SetOfInstancesJob() :
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
137 hasTrailingStep_(false)
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 void SetOfInstancesJob::AddInstance(const std::string& instance)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
144 AddCommand(new InstanceCommand(*this, instance));
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
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 void SetOfInstancesJob::AddTrailingStep()
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
150 AddCommand(new TrailingStepCommand(*this));
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
151 hasTrailingStep_ = true;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
152 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
153
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
154
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
155 size_t SetOfInstancesJob::GetInstancesCount() const
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
156 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
157 if (hasTrailingStep_)
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
159 assert(GetCommandsCount() > 0);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
160 return GetCommandsCount() - 1;
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 else
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
164 return GetCommandsCount();
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
168
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
169 const std::string& SetOfInstancesJob::GetInstance(size_t index) const
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
170 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
171 if (index >= GetInstancesCount())
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
172 {
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
173 throw OrthancException(ErrorCode_ParameterOutOfRange);
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
174 }
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
175 else
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
176 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
177 return dynamic_cast<const InstanceCommand&>(GetCommand(index)).GetInstance();
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
181
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
182 void SetOfInstancesJob::Start()
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 SetOfCommandsJob::Start();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
185 }
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
186
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
187
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
188 void SetOfInstancesJob::Reset()
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
189 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
190 SetOfCommandsJob::Reset();
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
191
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
192 failedInstances_.clear();
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
193 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
194
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
195
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
196 void SetOfInstancesJob::GetPublicContent(Json::Value& target)
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
197 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
198 SetOfCommandsJob::GetPublicContent(target);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
199 target["InstancesCount"] = static_cast<uint32_t>(GetInstancesCount());
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
200 target["FailedInstancesCount"] = static_cast<uint32_t>(failedInstances_.size());
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
201 }
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
202
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
203
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2652
diff changeset
204
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
205 static const char* KEY_TRAILING_STEP = "TrailingStep";
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
206 static const char* KEY_FAILED_INSTANCES = "FailedInstances";
2663
228e2783ce83 some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2657
diff changeset
207
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
208 bool SetOfInstancesJob::Serialize(Json::Value& target)
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
209 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
210 if (SetOfCommandsJob::Serialize(target))
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
211 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
212 target[KEY_TRAILING_STEP] = hasTrailingStep_;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
213 SerializationToolbox::WriteSetOfStrings(target, failedInstances_, KEY_FAILED_INSTANCES);
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
214 return true;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
215 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
216 else
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
217 {
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
218 return false;
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
219 }
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 }
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
221
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
222
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
223 SetOfInstancesJob::SetOfInstancesJob(const Json::Value& source) :
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
224 SetOfCommandsJob(new InstanceUnserializer(*this), source)
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
225 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
226 SerializationToolbox::ReadSetOfStrings(failedInstances_, source, KEY_FAILED_INSTANCES);
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
227
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
228 if (source.isMember(KEY_TRAILING_STEP))
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
229 {
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
230 hasTrailingStep_ = SerializationToolbox::ReadBoolean(source, KEY_TRAILING_STEP);
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
231 }
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
232 else
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
233 {
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
234 // Backward compatibility with Orthanc <= 1.4.2
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
235 hasTrailingStep_ = false;
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
236 }
2860
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
237 }
8b00e4cb4a6b SetOfCommandsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2842
diff changeset
238
2842
ff0ed5ea9e4e trailing step in SetOfInstancesJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
239
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }