annotate Common/MoveStorageJob.cpp @ 210:408c90c9027f default tip

todo: google soft delete
author Alain Mazy <am@orthanc.team>
date Wed, 09 Oct 2024 11:48:14 +0200
parents d62f52be1943
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
83
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
1 /**
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
2 * Cloud storage plugins for Orthanc
145
3c7e0374f28e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 111
diff changeset
3 * Copyright (C) 2020-2023 Osimis S.A., Belgium
3c7e0374f28e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 111
diff changeset
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
3c7e0374f28e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 111
diff changeset
5 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
83
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
6 *
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
10 * the License, or (at your option) any later version.
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
11 *
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
15 * Affero General Public License for more details.
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
16 *
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
19 **/
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
20
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
21 #include "MoveStorageJob.h"
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
22 #include "Logging.h"
84
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
23 #include "StoragePlugin.h"
83
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
24
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
25
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
26 MoveStorageJob::MoveStorageJob(const std::string& targetStorage,
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
27 const std::vector<std::string>& instances,
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
28 const Json::Value& resourceForJobContent,
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
29 bool cryptoEnabled)
84
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
30 : OrthancPlugins::OrthancJob(JOB_TYPE_MOVE_STORAGE),
83
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
31 targetStorage_(targetStorage),
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
32 instances_(instances),
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
33 processedInstancesCount_(0),
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
34 resourceForJobContent_(resourceForJobContent),
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
35 fileSystemStorage_(NULL),
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
36 objectStorage_(NULL),
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
37 cryptoEnabled_(cryptoEnabled)
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
38 {
84
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
39 UpdateContent(resourceForJobContent);
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
40
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
41 Json::Value serialized;
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
42 Serialize(serialized);
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
43 UpdateSerialized(serialized);
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
44 }
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
45
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
46 void MoveStorageJob::Serialize(Json::Value& target) const
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
47 {
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
48 target[KEY_CONTENT] = resourceForJobContent_;
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
49 target[KEY_TARGET_STORAGE] = targetStorage_;
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
50 target[KEY_INSTANCES] = Json::arrayValue;
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
51
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
52 for (size_t i = 0; i < instances_.size(); ++i)
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
53 {
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
54 target[KEY_INSTANCES].append(instances_[i]);
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
55 }
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
56
83
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
57 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
58
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
59 void MoveStorageJob::SetStorages(IStorage* fileSystemStorage, IStorage* objectStorage)
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
60 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
61 fileSystemStorage_ = fileSystemStorage;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
62 objectStorage_ = objectStorage;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
63 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
64
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
65 static bool MoveAttachment(const std::string& uuid, int type, IStorage* sourceStorage, IStorage* targetStorage, bool cryptoEnabled)
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
66 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
67 std::vector<char> buffer;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
68
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
69 // read from source storage
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
70 try
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
71 {
111
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
72 if (sourceStorage->HasFileExists() && !sourceStorage->FileExists(uuid, static_cast<OrthancPluginContentType>(type), cryptoEnabled))
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
73 {
152
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
74 LOG(INFO) << "Move attachment: " << sourceStorage->GetNameForLogs() << " " << uuid
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
75 << " of type " << boost::lexical_cast<std::string>(type) << ", skipping, file is not on the source anymore";
111
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
76 return true;
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
77 }
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
78 else if (targetStorage->HasFileExists() && targetStorage->FileExists(uuid, static_cast<OrthancPluginContentType>(type), cryptoEnabled))
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
79 {
152
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
80 LOG(INFO) << "Move attachment: " << targetStorage->GetNameForLogs() << " " << uuid
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
81 << " of type " << boost::lexical_cast<std::string>(type) << ", skipping, file already on the target";
111
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
82 return true;
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
83 }
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
84 else
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
85 {
152
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
86 LOG(INFO) << "Move attachment: " << sourceStorage->GetNameForLogs() << ": reading attachment "
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
87 << uuid << " of type " << boost::lexical_cast<std::string>(type);
111
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
88 }
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
89
83
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
90 std::unique_ptr<IStorage::IReader> reader(sourceStorage->GetReaderForObject(uuid.c_str(), static_cast<OrthancPluginContentType>(type), cryptoEnabled));
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
91
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
92 size_t fileSize = reader->GetSize();
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
93 buffer.resize(fileSize);
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
94
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
95 reader->ReadWhole(buffer.data(), fileSize);
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
96 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
97 catch (StoragePluginException& ex)
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
98 {
152
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
99 LOG(INFO) << "Move attachment: " << sourceStorage->GetNameForLogs() << ": error while reading attachment " << uuid
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
100 << " of type " << boost::lexical_cast<std::string>(type) << ", this likely means that the file is already on the right storage";
83
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
101 return true;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
102 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
103
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
104 // write to target storage
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
105 if (buffer.size() > 0)
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
106 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
107 try
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
108 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
109 std::unique_ptr<IStorage::IWriter> writer(targetStorage->GetWriterForObject(uuid.c_str(), static_cast<OrthancPluginContentType>(type), cryptoEnabled));
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
110
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
111 writer->Write(buffer.data(), buffer.size());
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
112 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
113 catch (StoragePluginException& ex)
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
114 {
152
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
115 LOG(ERROR) << "Move attachment: " << targetStorage->GetNameForLogs() << ": error while writing attachment "
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
116 << uuid << " of type " << boost::lexical_cast<std::string>(type) << ": " << ex.what();
83
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
117 return false;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
118 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
119 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
120
111
407bd022b0cf in /move-storage: now detecting if file should be moved or not
Alain Mazy <am@osimis.io>
parents: 84
diff changeset
121 // everything went well so far, we can delete from source storage
83
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
122 if (buffer.size() > 0)
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
123 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
124 try
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
125 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
126 sourceStorage->DeleteObject(uuid.c_str(), static_cast<OrthancPluginContentType>(type), cryptoEnabled);
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
127 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
128 catch (StoragePluginException& ex)
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
129 {
152
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
130 LOG(ERROR) << "Move attachment: " << sourceStorage->GetNameForLogs() << ": error while deleting attachment "
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
131 << uuid << " of type " << boost::lexical_cast<std::string>(type) << ": " << ex.what();
83
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
132 return false;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
133 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
134 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
135 return true;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
136 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
137
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
138 static bool MoveInstance(const std::string& instanceId, IStorage* sourceStorage, IStorage* targetStorage, bool cryptoEnabled)
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
139 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
140 LOG(INFO) << "Moving instance from " << sourceStorage->GetNameForLogs() << " to " << targetStorage->GetNameForLogs();
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
141
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
142 Json::Value attachmentsList;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
143 OrthancPlugins::RestApiGet(attachmentsList, std::string("/instances/") + instanceId + "/attachments?full", false);
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
144
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
145 Json::Value::Members attachmentsMembers = attachmentsList.getMemberNames();
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
146 bool success = true;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
147
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
148 for (size_t i = 0; i < attachmentsMembers.size(); i++)
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
149 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
150 int attachmentId = attachmentsList[attachmentsMembers[i]].asInt();
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
151
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
152 Json::Value attachmentInfo;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
153 OrthancPlugins::RestApiGet(attachmentInfo, std::string("/instances/") + instanceId + "/attachments/" + boost::lexical_cast<std::string>(attachmentId) + "/info", false);
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
154
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
155 std::string attachmentUuid = attachmentInfo["Uuid"].asString();
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
156
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
157 // now we have the uuid and type. We actually don't know where the file is but we'll try to move it anyway to the requested target
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
158 success &= MoveAttachment(attachmentUuid, attachmentId, sourceStorage, targetStorage, cryptoEnabled);
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
159 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
160
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
161 return success;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
162 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
163
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
164 OrthancPluginJobStepStatus MoveStorageJob::Step()
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
165 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
166 if (processedInstancesCount_ < instances_.size())
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
167 {
84
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
168 IStorage* sourceStorage = (targetStorage_ == STORAGE_TYPE_FILE_SYSTEM ? objectStorage_ : fileSystemStorage_);
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
169 IStorage* targetStorage = (targetStorage_ == STORAGE_TYPE_FILE_SYSTEM ? fileSystemStorage_ : objectStorage_);
83
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
170
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
171 if (MoveInstance(instances_[processedInstancesCount_], sourceStorage, targetStorage, cryptoEnabled_))
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
172 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
173 processedInstancesCount_++;
84
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
174 UpdateProgress((float)processedInstancesCount_/(float)instances_.size());
8a9207933297 MoveStorageJob serialization
Alain Mazy <am@osimis.io>
parents: 83
diff changeset
175
83
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
176 return OrthancPluginJobStepStatus_Continue;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
177 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
178 else
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
179 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
180 return OrthancPluginJobStepStatus_Failure;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
181 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
182 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
183
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
184 return OrthancPluginJobStepStatus_Success;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
185 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
186
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
187 void MoveStorageJob::Stop(OrthancPluginJobStopReason reason)
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
188 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
189 }
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
190
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
191 void MoveStorageJob::Reset()
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
192 {
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
193 processedInstancesCount_ = 0;
431ab61b5760 /move-storage when HybridMode is enabled
Alain Mazy <am@osimis.io>
parents:
diff changeset
194 }