annotate OrthancServer/Plugins/Engine/PluginsJob.cpp @ 5021:559b35d18ef7

Improved HttpClient error logging (add method + url)
author Alain Mazy <am@osimis.io>
date Wed, 15 Jun 2022 15:40:07 +0200
parents 6eff25f70121
children d00db9fb48fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * General Public License for more details.
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
23 #include "../../Sources/PrecompiledHeadersServer.h"
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "PluginsJob.h"
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #if ORTHANC_ENABLE_PLUGINS != 1
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #error The plugin support is disabled
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #endif
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
31 #include "../../../OrthancFramework/Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
32 #include "../../../OrthancFramework/Sources/OrthancException.h"
4392
3af1d763763a confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
33 #include "../../../OrthancFramework/Sources/Toolbox.h"
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include <cassert>
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 namespace Orthanc
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
39 PluginsJob::PluginsJob(const _OrthancPluginCreateJob& parameters) :
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
40 parameters_(parameters)
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
42 if (parameters_.job == NULL)
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 throw OrthancException(ErrorCode_NullPointer);
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
46
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
47 if (parameters_.target == NULL ||
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
48 parameters_.finalize == NULL ||
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
49 parameters_.type == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
50 parameters_.getProgress == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
51 parameters_.getContent == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
52 parameters_.getSerialized == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
53 parameters_.step == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
54 parameters_.stop == NULL ||
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
55 parameters_.reset == NULL)
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
56 {
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
57 parameters_.finalize(parameters.job);
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
58 throw OrthancException(ErrorCode_NullPointer);
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
59 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
61 type_.assign(parameters.type);
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 PluginsJob::~PluginsJob()
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
66 assert(parameters_.job != NULL);
2815
925d8dc03a23 unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2814
diff changeset
67 parameters_.finalize(parameters_.job);
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
70 JobStepResult PluginsJob::Step(const std::string& jobId)
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
72 OrthancPluginJobStepStatus status = parameters_.step(parameters_.job);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
73
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
74 switch (status)
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
75 {
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
76 case OrthancPluginJobStepStatus_Success:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
77 return JobStepResult::Success();
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
78
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
79 case OrthancPluginJobStepStatus_Failure:
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
80 return JobStepResult::Failure(ErrorCode_Plugin, NULL);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
81
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
82 case OrthancPluginJobStepStatus_Continue:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
83 return JobStepResult::Continue();
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
84
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
85 default:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
86 throw OrthancException(ErrorCode_ParameterOutOfRange);
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
87 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
90 void PluginsJob::Reset()
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
92 parameters_.reset(parameters_.job);
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
95 void PluginsJob::Stop(JobStopReason reason)
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
97 switch (reason)
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
98 {
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
99 case JobStopReason_Success:
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
100 parameters_.stop(parameters_.job, OrthancPluginJobStopReason_Success);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
101 break;
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
102
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
103 case JobStopReason_Failure:
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
104 parameters_.stop(parameters_.job, OrthancPluginJobStopReason_Failure);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
105 break;
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
106
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
107 case JobStopReason_Canceled:
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
108 parameters_.stop(parameters_.job, OrthancPluginJobStopReason_Canceled);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
109 break;
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
110
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
111 case JobStopReason_Paused:
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
112 parameters_.stop(parameters_.job, OrthancPluginJobStopReason_Paused);
2811
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
113 break;
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
114
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
115 default:
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
116 throw OrthancException(ErrorCode_ParameterOutOfRange);
7cfc8d266f41 reason for releasing resources in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2810
diff changeset
117 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 float PluginsJob::GetProgress()
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
122 return parameters_.getProgress(parameters_.job);
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
123 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
124
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
125 void PluginsJob::GetPublicContent(Json::Value& value)
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
126 {
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
127 const char* content = parameters_.getContent(parameters_.job);
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
128
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
129 if (content == NULL)
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
130 {
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
131 value = Json::objectValue;
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
132 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
133 else
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
134 {
4392
3af1d763763a confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
135 if (!Toolbox::ReadJson(value, content) ||
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
136 value.type() != Json::objectValue)
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
137 {
2956
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
138 throw OrthancException(ErrorCode_Plugin,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
139 "A job plugin must provide a JSON object as its public content");
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
140 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
141 }
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 bool PluginsJob::Serialize(Json::Value& value)
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
146 const char* serialized = parameters_.getSerialized(parameters_.job);
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
147
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
148 if (serialized == NULL)
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
150 return false;
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 else
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
4392
3af1d763763a confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
154 if (!Toolbox::ReadJson(value, serialized) ||
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
155 value.type() != Json::objectValue)
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
156 {
2956
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
157 throw OrthancException(ErrorCode_Plugin,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
158 "A job plugin must provide a JSON object as its serialized content");
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
159 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
160
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
161
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
162 static const char* KEY_TYPE = "Type";
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
163
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
164 if (value.isMember(KEY_TYPE))
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
165 {
2956
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
166 throw OrthancException(ErrorCode_Plugin,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2815
diff changeset
167 "The \"Type\" field is for reserved use for serialized job");
2814
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
168 }
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
169
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
170 value[KEY_TYPE] = type_;
7d1d3136f6cf more generic handling of content and serialization in plugin jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
171 return true;
2810
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
1e8c4ecd02f4 missing files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }