annotate OrthancServer/Plugins/Samples/DelayedDeletion/LargeDeleteJob.cpp @ 5264:99751c5a7cfe

added missing copyrights
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Apr 2023 17:43:05 +0200
parents c2ebc47f4f18
children 49477780e25a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5264
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
1 /**
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
4 * Department, University Hospital of Liege, Belgium
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
7 *
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
8 * This program is free software: you can redistribute it and/or
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
9 * modify it under the terms of the GNU General Public License as
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
11 * License, or (at your option) any later version.
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
12 *
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
13 * This program is distributed in the hope that it will be useful, but
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
16 * General Public License for more details.
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
17 *
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
18 * You should have received a copy of the GNU General Public License
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
20 **/
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
21
99751c5a7cfe added missing copyrights
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5024
diff changeset
22
5024
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
23 #include "LargeDeleteJob.h"
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
24
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
25 #include "../../../../OrthancFramework/Sources/Logging.h"
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
26 #include "../../../../OrthancFramework/Sources/OrthancException.h"
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
27
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
28 #include <json/reader.h>
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
29
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
30 void LargeDeleteJob::UpdateDeleteProgress()
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
31 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
32 size_t total = 2 * resources_.size() + instances_.size() + series_.size();
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
33
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
34 float progress;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
35 if (total == 0)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
36 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
37 progress = 1;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
38 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
39 else
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
40 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
41 progress = (static_cast<float>(posResources_ + posInstances_ + posSeries_ + posDelete_) /
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
42 static_cast<float>(total));
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
43 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
44
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
45 UpdateProgress(progress);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
46 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
47
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
48
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
49 void LargeDeleteJob::ScheduleChildrenResources(std::vector<std::string>& target,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
50 const std::string& uri)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
51 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
52 Json::Value items;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
53 if (OrthancPlugins::RestApiGet(items, uri, false))
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
54 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
55 if (items.type() != Json::arrayValue)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
56 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
57 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
58 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
59
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
60 for (Json::Value::ArrayIndex i = 0; i < items.size(); i++)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
61 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
62 if (items[i].type() != Json::objectValue ||
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
63 !items[i].isMember("ID") ||
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
64 items[i]["ID"].type() != Json::stringValue)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
65 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
67 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
68 else
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
69 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
70 target.push_back(items[i]["ID"].asString());
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
71 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
72 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
73 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
74 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
75
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
76
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
77 void LargeDeleteJob::ScheduleResource(Orthanc::ResourceType level,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
78 const std::string& id)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
79 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
80 #if 0
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
81 // Instance-level granularity => very slow!
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
82 switch (level)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
83 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
84 case Orthanc::ResourceType_Patient:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
85 ScheduleChildrenResources(instances_, "/patients/" + id + "/instances");
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
86 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
87
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
88 case Orthanc::ResourceType_Study:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
89 ScheduleChildrenResources(instances_, "/studies/" + id + "/instances");
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
90 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
91
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
92 case Orthanc::ResourceType_Series:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
93 ScheduleChildrenResources(instances_, "/series/" + id + "/instances");
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
94 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
95
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
96 case Orthanc::ResourceType_Instance:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
97 instances_.push_back(id);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
98 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
99
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
100 default:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
101 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
102 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
103 #else
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
104 /**
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
105 * Series-level granularity => looks like a good compromise between
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
106 * having the Orthanc mutex locked during all the study, and very
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
107 * slow instance-level granularity.
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
108 **/
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
109 switch (level)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
110 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
111 case Orthanc::ResourceType_Patient:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
112 ScheduleChildrenResources(series_, "/patients/" + id + "/series");
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
113 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
114
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
115 case Orthanc::ResourceType_Study:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
116 ScheduleChildrenResources(series_, "/studies/" + id + "/series");
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
117 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
118
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
119 case Orthanc::ResourceType_Series:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
120 series_.push_back(id);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
121 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
122
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
123 case Orthanc::ResourceType_Instance:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
124 instances_.push_back(id);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
125 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
126
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
127 default:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
128 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
129 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
130 #endif
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
131 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
132
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
133
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
134 void LargeDeleteJob::DeleteResource(Orthanc::ResourceType level,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
135 const std::string& id)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
136 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
137 std::string uri;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
138 switch (level)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
139 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
140 case Orthanc::ResourceType_Patient:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
141 uri = "/patients/" + id;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
142 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
143
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
144 case Orthanc::ResourceType_Study:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
145 uri = "/studies/" + id;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
146 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
147
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
148 case Orthanc::ResourceType_Series:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
149 uri = "/series/" + id;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
150 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
151
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
152 case Orthanc::ResourceType_Instance:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
153 uri = "/instances/" + id;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
154 break;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
155
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
156 default:
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
157 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
158 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
159
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
160 OrthancPlugins::RestApiDelete(uri, false);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
161 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
162
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
163
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
164 LargeDeleteJob::LargeDeleteJob(const std::vector<std::string>& resources,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
165 const std::vector<Orthanc::ResourceType>& levels) :
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
166 OrthancJob("LargeDelete"),
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
167 resources_(resources),
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
168 levels_(levels),
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
169 posResources_(0),
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
170 posInstances_(0),
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
171 posDelete_(0)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
172 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
173 if (resources.size() != levels.size())
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
174 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
175 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
176 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
177 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
178
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
179
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
180 OrthancPluginJobStepStatus LargeDeleteJob::Step()
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
181 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
182 if (posResources_ == 0)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
183 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
184 if (resources_.size() == 1)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
185 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
186 // LOG(WARNING) << "LargeDeleteJob has started on resource: " << resources_[0];
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
187 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
188 else
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
189 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
190 // LOG(WARNING) << "LargeDeleteJob has started";
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
191 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
192 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
193
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
194 if (posResources_ < resources_.size())
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
195 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
196 // First step: Discovering all the instances of the resources
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
197
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
198 ScheduleResource(levels_[posResources_], resources_[posResources_]);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
199
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
200 posResources_ += 1;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
201 UpdateDeleteProgress();
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
202 return OrthancPluginJobStepStatus_Continue;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
203 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
204 else if (posInstances_ < instances_.size())
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
205 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
206 // Second step: Deleting the instances one by one
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
207
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
208 DeleteResource(Orthanc::ResourceType_Instance, instances_[posInstances_]);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
209
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
210 posInstances_ += 1;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
211 UpdateDeleteProgress();
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
212 return OrthancPluginJobStepStatus_Continue;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
213 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
214 else if (posSeries_ < series_.size())
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
215 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
216 // Third step: Deleting the series one by one
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
217
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
218 DeleteResource(Orthanc::ResourceType_Series, series_[posSeries_]);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
219
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
220 posSeries_ += 1;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
221 UpdateDeleteProgress();
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
222 return OrthancPluginJobStepStatus_Continue;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
223 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
224 else if (posDelete_ < resources_.size())
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
225 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
226 // Fourth step: Make sure the resources where fully deleted
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
227 // (instances might have been received since the beginning of
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
228 // the job)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
229
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
230 DeleteResource(levels_[posDelete_], resources_[posDelete_]);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
231
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
232 posDelete_ += 1;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
233 UpdateDeleteProgress();
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
234 return OrthancPluginJobStepStatus_Continue;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
235 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
236 else
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
237 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
238 if (resources_.size() == 1)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
239 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
240 // LOG(WARNING) << "LargeDeleteJob has completed on resource: " << resources_[0];
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
241 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
242 else
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
243 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
244 // LOG(WARNING) << "LargeDeleteJob has completed";
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
245 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
246
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
247 UpdateProgress(1);
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
248 return OrthancPluginJobStepStatus_Success;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
249 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
250 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
251
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
252
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
253 void LargeDeleteJob::Reset()
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
254 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
255 posResources_ = 0;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
256 posInstances_ = 0;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
257 posDelete_ = 0;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
258 instances_.clear();
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
259 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
260
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
261
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
262 void LargeDeleteJob::RestHandler(OrthancPluginRestOutput* output,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
263 const char* url,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
264 const OrthancPluginHttpRequest* request)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
265 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
266 static const char* KEY_RESOURCES = "Resources";
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
267
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
268 if (request->method != OrthancPluginHttpMethod_Post)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
269 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
270 OrthancPluginSendMethodNotAllowed(OrthancPlugins::GetGlobalContext(), output, "POST");
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
271 return;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
272 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
273
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
274 Json::Value body;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
275 Json::Reader reader;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
276 if (!reader.parse(reinterpret_cast<const char*>(request->body),
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
277 reinterpret_cast<const char*>(request->body) + request->bodySize, body))
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
278 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
279 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "JSON body is expected");
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
280 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
281
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
282 if (body.type() != Json::objectValue)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
283 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
284 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
285 "Expected a JSON object in the body");
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
286 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
287
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
288 if (!body.isMember(KEY_RESOURCES) ||
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
289 body[KEY_RESOURCES].type() != Json::arrayValue)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
290 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
291 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
292 "The JSON object must contain an array in \"" +
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
293 std::string(KEY_RESOURCES) + "\"");
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
294 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
295
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
296 std::vector<std::string> resources;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
297 std::vector<Orthanc::ResourceType> levels;
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
298
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
299 resources.reserve(body.size());
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
300 levels.reserve(body.size());
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
301
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
302 const Json::Value& arr = body[KEY_RESOURCES];
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
303 for (Json::Value::ArrayIndex i = 0; i < arr.size(); i++)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
304 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
305 if (arr[i].type() != Json::arrayValue ||
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
306 arr[i].size() != 2u ||
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
307 arr[i][0].type() != Json::stringValue ||
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
308 arr[i][1].type() != Json::stringValue)
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
309 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
310 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
311 "Each entry must be an array containing 2 strings, "
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
312 "the resource level and its ID");
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
313 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
314 else
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
315 {
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
316 levels.push_back(Orthanc::StringToResourceType(arr[i][0].asCString()));
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
317 resources.push_back(arr[i][1].asString());
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
318 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
319 }
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
320
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
321 OrthancPlugins::OrthancJob::SubmitFromRestApiPost(
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
322 output, body, new LargeDeleteJob(resources, levels));
c2ebc47f4f18 wip: adding DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
323 }