annotate Core/JobsEngine/SetOfInstancesJob.cpp @ 2657:5eea2f11e8df jobs

JobsSerialization.GenericJobs
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 06 Jun 2018 16:52:42 +0200
parents a6d3e45eeff5
children 228e2783ce83
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
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
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
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace Orthanc
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 SetOfInstancesJob::SetOfInstancesJob() :
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 started_(false),
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 permissive_(false),
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 position_(0)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 void SetOfInstancesJob::Reserve(size_t size)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 if (started_)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 throw OrthancException(ErrorCode_BadSequenceOfCalls);
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 else
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 instances_.reserve(size);
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 void SetOfInstancesJob::AddInstance(const std::string& instance)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 if (started_)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 throw OrthancException(ErrorCode_BadSequenceOfCalls);
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 else
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 instances_.push_back(instance);
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 void SetOfInstancesJob::SetPermissive(bool permissive)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 if (IsStarted())
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 throw OrthancException(ErrorCode_BadSequenceOfCalls);
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 else
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 permissive_ = permissive;
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 void SetOfInstancesJob::SignalResubmit()
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 if (started_)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 position_ = 0;
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 failedInstances_.clear();
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 else
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 throw OrthancException(ErrorCode_BadSequenceOfCalls);
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 float SetOfInstancesJob::GetProgress()
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 if (instances_.size() == 0)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 return 0;
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 else
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 return (static_cast<float>(position_) /
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 static_cast<float>(instances_.size()));
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
117 const std::string& SetOfInstancesJob::GetInstance(size_t index) const
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
118 {
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
119 if (index > instances_.size())
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
120 {
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
121 throw OrthancException(ErrorCode_ParameterOutOfRange);
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
122 }
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
123 else
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
124 {
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
125 return instances_[index];
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
126 }
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
127 }
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
128
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
129
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2586
diff changeset
130 JobStepResult SetOfInstancesJob::ExecuteStep()
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
2586
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
132 if (!started_)
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
133 {
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
134 throw OrthancException(ErrorCode_InternalError);
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
135 }
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
136
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
137 if (instances_.empty() &&
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
138 position_ == 0)
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
2586
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
140 // No instance to handle, we're done
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
141 position_ = 1;
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2586
diff changeset
142 return JobStepResult::Success();
2586
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
143 }
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
144
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
145 if (position_ >= instances_.size())
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
146 {
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
147 // Already done
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2586
diff changeset
148 throw OrthancException(ErrorCode_BadSequenceOfCalls);
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
2586
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
151 const std::string currentInstance = instances_[position_];
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
152
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 bool ok;
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 try
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
2586
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
157 ok = HandleInstance(currentInstance);
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 if (!ok && !permissive_)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2586
diff changeset
161 return JobStepResult::Failure(ErrorCode_InternalError);
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 catch (OrthancException& e)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 if (permissive_)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 ok = false;
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 else
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 throw;
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 if (!ok)
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
2586
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
178 failedInstances_.insert(currentInstance);
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
2586
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
181 position_ += 1;
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
2586
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
183 if (position_ == instances_.size())
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
2586
ec09641d6f41 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2585
diff changeset
185 // We're done
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2586
diff changeset
186 return JobStepResult::Success();
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 else
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2586
diff changeset
190 return JobStepResult::Continue();
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
195 void SetOfInstancesJob::GetPublicContent(Json::Value& value)
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
196 {
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
197 value["Description"] = GetDescription();
2657
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
198 value["InstancesCount"] = static_cast<uint32_t>(instances_.size());
5eea2f11e8df JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2656
diff changeset
199 value["FailedInstancesCount"] = static_cast<uint32_t>(failedInstances_.size());
2640
c691fcf66071 ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
200 }
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
2648
e1893d31652a serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2640
diff changeset
203 void SetOfInstancesJob::Serialize(Json::Value& value)
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 {
2655
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2652
diff changeset
205 value = Json::objectValue;
c196d76cb8fa serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2652
diff changeset
206
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
207 std::string type;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
208 GetJobType(type);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
209 value["Type"] = type;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
210
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
211 value["Permissive"] = permissive_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
212 value["Position"] = static_cast<unsigned int>(position_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
213 value["Description"] = description_;
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
215 SerializationToolbox::WriteArrayOfStrings(value, instances_, "Instances");
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
216 SerializationToolbox::WriteSetOfStrings(value, failedInstances_, "FailedInstances");
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 }
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
218
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
219
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
220 SetOfInstancesJob::SetOfInstancesJob(const Json::Value& value) :
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
221 started_(false),
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
222 permissive_(SerializationToolbox::ReadBoolean(value, "Permissive")),
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
223 position_(SerializationToolbox::ReadUnsignedInteger(value, "Position")),
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
224 description_(SerializationToolbox::ReadString(value, "Description"))
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
225 {
2656
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
226 SerializationToolbox::ReadArrayOfStrings(instances_, value, "Instances");
a6d3e45eeff5 SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2655
diff changeset
227 SerializationToolbox::ReadSetOfStrings(failedInstances_, value, "FailedInstances");
2652
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
228
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
229 if (position_ > instances_.size())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
230 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
231 throw OrthancException(ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
232 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2648
diff changeset
233 }
2585
4c809711149e reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }