Mercurial > hg > orthanc
annotate OrthancServer/ServerIndex.cpp @ 369:4632a044746e
simplification of the code
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 19 Feb 2013 12:09:03 +0100 |
parents | fc856d175d18 |
children | d1ea72f1c967 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
0 | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
4 * Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "ServerIndex.h" | |
34 | |
6 | 35 #ifndef NOMINMAX |
2 | 36 #define NOMINMAX |
6 | 37 #endif |
38 | |
8 | 39 #include "EmbeddedResources.h" |
0 | 40 #include "../Core/Toolbox.h" |
41 #include "../Core/Uuid.h" | |
42 #include "../Core/DicomFormat/DicomArray.h" | |
43 #include "../Core/SQLite/Transaction.h" | |
44 #include "FromDcmtkBridge.h" | |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
45 #include "ServerContext.h" |
0 | 46 |
47 #include <boost/lexical_cast.hpp> | |
48 #include <stdio.h> | |
108 | 49 #include <glog/logging.h> |
0 | 50 |
62 | 51 namespace Orthanc |
0 | 52 { |
53 namespace Internals | |
54 { | |
202 | 55 class ServerIndexListener : public IServerIndexListener |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
56 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
57 private: |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
58 ServerContext& context_; |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
59 bool hasRemainingLevel_; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
60 ResourceType remainingType_; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
61 std::string remainingPublicId_; |
264
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
62 std::list<std::string> pendingFilesToRemove_; |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
63 uint64_t sizeOfFilesToRemove_; |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
64 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
65 public: |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
66 ServerIndexListener(ServerContext& context) : |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
67 context_(context) |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
68 { |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
69 Reset(); |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
70 assert(ResourceType_Patient < ResourceType_Study && |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
71 ResourceType_Study < ResourceType_Series && |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
72 ResourceType_Series < ResourceType_Instance); |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
73 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
74 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
75 void Reset() |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
76 { |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
77 sizeOfFilesToRemove_ = 0; |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
78 hasRemainingLevel_ = false; |
264
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
79 pendingFilesToRemove_.clear(); |
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
80 } |
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
81 |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
82 uint64_t GetSizeOfFilesToRemove() |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
83 { |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
84 return sizeOfFilesToRemove_; |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
85 } |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
86 |
264
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
87 void CommitFilesToRemove() |
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
88 { |
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
89 for (std::list<std::string>::iterator |
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
90 it = pendingFilesToRemove_.begin(); |
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
91 it != pendingFilesToRemove_.end(); it++) |
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
92 { |
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
93 context_.RemoveFile(*it); |
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
94 } |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
95 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
96 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
97 virtual void SignalRemainingAncestor(ResourceType parentType, |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
98 const std::string& publicId) |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
99 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
100 LOG(INFO) << "Remaining ancestor \"" << publicId << "\" (" << parentType << ")"; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
101 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
102 if (hasRemainingLevel_) |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
103 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
104 if (parentType < remainingType_) |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
105 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
106 remainingType_ = parentType; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
107 remainingPublicId_ = publicId; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
108 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
109 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
110 else |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
111 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
112 hasRemainingLevel_ = true; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
113 remainingType_ = parentType; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
114 remainingPublicId_ = publicId; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
115 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
116 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
117 |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
118 virtual void SignalFileDeleted(const FileInfo& info) |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
119 { |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
120 assert(Toolbox::IsUuid(info.GetUuid())); |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
272
diff
changeset
|
121 pendingFilesToRemove_.push_back(info.GetUuid()); |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
122 sizeOfFilesToRemove_ += info.GetCompressedSize(); |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
123 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
124 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
125 bool HasRemainingLevel() const |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
126 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
127 return hasRemainingLevel_; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
128 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
129 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
130 ResourceType GetRemainingType() const |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
131 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
132 assert(HasRemainingLevel()); |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
133 return remainingType_; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
134 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
135 |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
136 const std::string& GetRemainingPublicId() const |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
137 { |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
138 assert(HasRemainingLevel()); |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
139 return remainingPublicId_; |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
140 } |
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
141 }; |
0 | 142 } |
143 | |
144 | |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
145 class ServerIndex::Transaction |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
146 { |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
147 private: |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
148 ServerIndex& index_; |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
149 std::auto_ptr<SQLite::Transaction> transaction_; |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
150 bool isCommitted_; |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
151 |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
152 public: |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
153 Transaction(ServerIndex& index) : |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
154 index_(index), |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
155 isCommitted_(false) |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
156 { |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
157 assert(index_.currentStorageSize_ == index_.db_->GetTotalCompressedSize()); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
158 |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
159 index_.listener_->Reset(); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
160 transaction_.reset(index_.db_->StartTransaction()); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
161 transaction_->Begin(); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
162 } |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
163 |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
164 void Commit(uint64_t sizeOfAddedFiles) |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
165 { |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
166 if (!isCommitted_) |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
167 { |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
168 transaction_->Commit(); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
169 |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
170 // We can remove the files once the SQLite transaction has |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
171 // been successfully committed. Some files might have to be |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
172 // deleted because of recycling. |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
173 index_.listener_->CommitFilesToRemove(); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
174 |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
175 index_.currentStorageSize_ += sizeOfAddedFiles; |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
176 |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
177 assert(index_.currentStorageSize_ >= index_.listener_->GetSizeOfFilesToRemove()); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
178 index_.currentStorageSize_ -= index_.listener_->GetSizeOfFilesToRemove(); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
179 |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
180 assert(index_.currentStorageSize_ == index_.db_->GetTotalCompressedSize()); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
181 |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
182 isCommitted_ = true; |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
183 } |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
184 } |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
185 }; |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
186 |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
187 |
212 | 188 bool ServerIndex::DeleteResource(Json::Value& target, |
0 | 189 const std::string& uuid, |
202 | 190 ResourceType expectedType) |
0 | 191 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
192 boost::mutex::scoped_lock lock(mutex_); |
202 | 193 listener_->Reset(); |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
194 |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
195 Transaction t(*this); |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
196 |
202 | 197 int64_t id; |
198 ResourceType type; | |
199 if (!db_->LookupResource(uuid, id, type) || | |
200 expectedType != type) | |
0 | 201 { |
202 return false; | |
203 } | |
202 | 204 |
205 db_->DeleteResource(id); | |
0 | 206 |
202 | 207 if (listener_->HasRemainingLevel()) |
0 | 208 { |
202 | 209 ResourceType type = listener_->GetRemainingType(); |
210 const std::string& uuid = listener_->GetRemainingPublicId(); | |
0 | 211 |
212 target["RemainingAncestor"] = Json::Value(Json::objectValue); | |
204 | 213 target["RemainingAncestor"]["Path"] = GetBasePath(type, uuid); |
202 | 214 target["RemainingAncestor"]["Type"] = ToString(type); |
0 | 215 target["RemainingAncestor"]["ID"] = uuid; |
216 } | |
217 else | |
218 { | |
219 target["RemainingAncestor"] = Json::nullValue; | |
220 } | |
221 | |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
222 t.Commit(0); |
264
5b8e8b74bc8b
remove files only after the sqlite transaction has succeeded
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
240
diff
changeset
|
223 |
0 | 224 return true; |
225 } | |
226 | |
227 | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
228 static void FlushThread(DatabaseWrapper* db, |
220 | 229 boost::mutex* mutex, |
230 unsigned int sleep) | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
231 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
232 LOG(INFO) << "Starting the database flushing thread (sleep = " << sleep << ")"; |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
233 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
234 while (1) |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
235 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
236 boost::this_thread::sleep(boost::posix_time::seconds(sleep)); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
237 boost::mutex::scoped_lock lock(*mutex); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
238 db->FlushToDisk(); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
239 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
240 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
241 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
242 |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
243 ServerIndex::ServerIndex(ServerContext& context, |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
244 const std::string& dbPath) : |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
245 maximumStorageSize_(0), |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
246 maximumPatients_(0) |
186
f68c039b0571
preparing refactoring of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
247 { |
226
8a26a8e85edf
refactoring to read files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
248 listener_.reset(new Internals::ServerIndexListener(context)); |
186
f68c039b0571
preparing refactoring of ServerIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
249 |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
250 if (dbPath == ":memory:") |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
251 { |
202 | 252 db_.reset(new DatabaseWrapper(*listener_)); |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
253 } |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
254 else |
0 | 255 { |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
256 boost::filesystem::path p = dbPath; |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
257 |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
258 try |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
259 { |
201
bee20e978835
refactoring of delete
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
260 boost::filesystem::create_directories(p); |
180
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
261 } |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
262 catch (boost::filesystem::filesystem_error) |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
263 { |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
264 } |
626777d01dc4
use of hashes to index dicom objects
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
265 |
202 | 266 db_.reset(new DatabaseWrapper(p.string() + "/index", *listener_)); |
0 | 267 } |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
268 |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
269 currentStorageSize_ = db_->GetTotalCompressedSize(); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
270 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
271 // Initial recycling if the parameters have changed since the last |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
272 // execution of Orthanc |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
273 StandaloneRecycling(); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
274 |
220 | 275 unsigned int sleep; |
276 try | |
277 { | |
278 std::string sleepString = db_->GetGlobalProperty(GlobalProperty_FlushSleep); | |
279 sleep = boost::lexical_cast<unsigned int>(sleepString); | |
280 } | |
281 catch (boost::bad_lexical_cast&) | |
282 { | |
283 // By default, wait for 10 seconds before flushing | |
284 sleep = 10; | |
285 } | |
286 | |
287 flushThread_ = boost::thread(FlushThread, db_.get(), &mutex_, sleep); | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
288 } |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
289 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
290 |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
291 ServerIndex::~ServerIndex() |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
292 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
293 LOG(INFO) << "Stopping the database flushing thread"; |
220 | 294 /*flushThread_.terminate(); |
295 flushThread_.join();*/ | |
0 | 296 } |
297 | |
298 | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
299 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary, |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
300 const Attachments& attachments, |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
301 const std::string& remoteAet) |
0 | 302 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
303 boost::mutex::scoped_lock lock(mutex_); |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
304 listener_->Reset(); |
0 | 305 |
178 | 306 DicomInstanceHasher hasher(dicomSummary); |
0 | 307 |
308 try | |
309 { | |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
310 Transaction t(*this); |
0 | 311 |
202 | 312 int64_t patient, study, series, instance; |
313 ResourceType type; | |
314 bool isNewSeries = false; | |
315 | |
316 // Do nothing if the instance already exists | |
317 if (db_->LookupResource(hasher.HashInstance(), patient, type)) | |
0 | 318 { |
202 | 319 assert(type == ResourceType_Instance); |
0 | 320 return StoreStatus_AlreadyStored; |
321 } | |
322 | |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
323 // Ensure there is enough room in the storage for the new instance |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
324 uint64_t instanceSize = 0; |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
325 for (Attachments::const_iterator it = attachments.begin(); |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
326 it != attachments.end(); it++) |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
327 { |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
328 instanceSize += it->GetCompressedSize(); |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
329 } |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
330 |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
331 Recycle(instanceSize, hasher.HashPatient()); |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
332 |
202 | 333 // Create the instance |
334 instance = db_->CreateResource(hasher.HashInstance(), ResourceType_Instance); | |
335 | |
336 DicomMap dicom; | |
337 dicomSummary.ExtractInstanceInformation(dicom); | |
338 db_->SetMainDicomTags(instance, dicom); | |
339 | |
340 // Create the patient/study/series/instance hierarchy | |
341 if (!db_->LookupResource(hasher.HashSeries(), series, type)) | |
0 | 342 { |
202 | 343 // This is a new series |
344 isNewSeries = true; | |
345 series = db_->CreateResource(hasher.HashSeries(), ResourceType_Series); | |
346 dicomSummary.ExtractSeriesInformation(dicom); | |
347 db_->SetMainDicomTags(series, dicom); | |
348 db_->AttachChild(series, instance); | |
349 | |
350 if (!db_->LookupResource(hasher.HashStudy(), study, type)) | |
351 { | |
352 // This is a new study | |
353 study = db_->CreateResource(hasher.HashStudy(), ResourceType_Study); | |
354 dicomSummary.ExtractStudyInformation(dicom); | |
355 db_->SetMainDicomTags(study, dicom); | |
356 db_->AttachChild(study, series); | |
357 | |
358 if (!db_->LookupResource(hasher.HashPatient(), patient, type)) | |
359 { | |
360 // This is a new patient | |
361 patient = db_->CreateResource(hasher.HashPatient(), ResourceType_Patient); | |
362 dicomSummary.ExtractPatientInformation(dicom); | |
363 db_->SetMainDicomTags(patient, dicom); | |
364 db_->AttachChild(patient, study); | |
365 } | |
366 else | |
367 { | |
368 assert(type == ResourceType_Patient); | |
369 db_->AttachChild(patient, study); | |
370 } | |
371 } | |
372 else | |
373 { | |
374 assert(type == ResourceType_Study); | |
375 db_->AttachChild(study, series); | |
376 } | |
0 | 377 } |
378 else | |
379 { | |
202 | 380 assert(type == ResourceType_Series); |
381 db_->AttachChild(series, instance); | |
0 | 382 } |
383 | |
202 | 384 // Attach the files to the newly created instance |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
385 for (Attachments::const_iterator it = attachments.begin(); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
386 it != attachments.end(); it++) |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
387 { |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
388 db_->AddAttachment(instance, *it); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
389 } |
202 | 390 |
391 // Attach the metadata | |
392 db_->SetMetadata(instance, MetadataType_Instance_ReceptionDate, Toolbox::GetNowIsoString()); | |
393 db_->SetMetadata(instance, MetadataType_Instance_RemoteAet, remoteAet); | |
394 | |
395 const DicomValue* value; | |
396 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_INSTANCE_NUMBER)) != NULL || | |
397 (value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGE_INDEX)) != NULL) | |
0 | 398 { |
202 | 399 db_->SetMetadata(instance, MetadataType_Instance_IndexInSeries, value->AsString()); |
0 | 400 } |
401 | |
202 | 402 if (isNewSeries) |
403 { | |
404 if ((value = dicomSummary.TestAndGetValue(DICOM_TAG_NUMBER_OF_SLICES)) != NULL || | |
405 (value = dicomSummary.TestAndGetValue(DICOM_TAG_IMAGES_IN_ACQUISITION)) != NULL || | |
406 (value = dicomSummary.TestAndGetValue(DICOM_TAG_CARDIAC_NUMBER_OF_IMAGES)) != NULL) | |
407 { | |
408 db_->SetMetadata(series, MetadataType_Series_ExpectedNumberOfInstances, value->AsString()); | |
409 } | |
410 } | |
411 | |
205
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
412 // Check whether the series of this new instance is now completed |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
413 SeriesStatus seriesStatus = GetSeriesStatus(series); |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
414 if (seriesStatus == SeriesStatus_Complete) |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
415 { |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
416 db_->LogChange(ChangeType_CompletedSeries, series, ResourceType_Series); |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
417 } |
6ab754744446
logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
418 |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
419 t.Commit(instanceSize); |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
420 |
0 | 421 return StoreStatus_Success; |
422 } | |
62 | 423 catch (OrthancException& e) |
0 | 424 { |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
425 LOG(ERROR) << "EXCEPTION [" << e.What() << "]" |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
426 << " (SQLite status: " << db_->GetErrorMessage() << ")"; |
0 | 427 } |
428 | |
429 return StoreStatus_Failure; | |
430 } | |
431 | |
432 | |
238 | 433 void ServerIndex::ComputeStatistics(Json::Value& target) |
0 | 434 { |
240 | 435 static const uint64_t MB = 1024 * 1024; |
436 | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
437 boost::mutex::scoped_lock lock(mutex_); |
238 | 438 target = Json::objectValue; |
0 | 439 |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
440 uint64_t cs = currentStorageSize_; |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
441 assert(cs == db_->GetTotalCompressedSize()); |
238 | 442 uint64_t us = db_->GetTotalUncompressedSize(); |
239 | 443 target["TotalDiskSpace"] = boost::lexical_cast<std::string>(cs); |
238 | 444 target["TotalUncompressedSize"] = boost::lexical_cast<std::string>(us); |
240 | 445 target["TotalDiskSpaceMB"] = boost::lexical_cast<unsigned int>(cs / MB); |
446 target["TotalUncompressedSizeMB"] = boost::lexical_cast<unsigned int>(us / MB); | |
238 | 447 |
448 target["CountPatients"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Patient)); | |
449 target["CountStudies"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Study)); | |
450 target["CountSeries"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Series)); | |
451 target["CountInstances"] = static_cast<unsigned int>(db_->GetResourceCount(ResourceType_Instance)); | |
452 } | |
453 | |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
454 |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
186
diff
changeset
|
455 |
199 | 456 SeriesStatus ServerIndex::GetSeriesStatus(int id) |
457 { | |
458 // Get the expected number of instances in this series (from the metadata) | |
202 | 459 std::string s = db_->GetMetadata(id, MetadataType_Series_ExpectedNumberOfInstances); |
199 | 460 |
461 size_t expected; | |
462 try | |
463 { | |
464 expected = boost::lexical_cast<size_t>(s); | |
465 if (expected < 0) | |
466 { | |
467 return SeriesStatus_Unknown; | |
468 } | |
469 } | |
470 catch (boost::bad_lexical_cast&) | |
471 { | |
472 return SeriesStatus_Unknown; | |
473 } | |
474 | |
475 // Loop over the instances of this series | |
476 std::list<int64_t> children; | |
202 | 477 db_->GetChildrenInternalId(children, id); |
199 | 478 |
479 std::set<size_t> instances; | |
480 for (std::list<int64_t>::const_iterator | |
481 it = children.begin(); it != children.end(); it++) | |
482 { | |
483 // Get the index of this instance in the series | |
202 | 484 s = db_->GetMetadata(*it, MetadataType_Instance_IndexInSeries); |
199 | 485 size_t index; |
486 try | |
487 { | |
488 index = boost::lexical_cast<size_t>(s); | |
489 } | |
490 catch (boost::bad_lexical_cast&) | |
491 { | |
492 return SeriesStatus_Unknown; | |
493 } | |
494 | |
495 if (index <= 0 || index > expected) | |
496 { | |
497 // Out-of-range instance index | |
498 return SeriesStatus_Inconsistent; | |
499 } | |
500 | |
501 if (instances.find(index) != instances.end()) | |
502 { | |
503 // Twice the same instance index | |
504 return SeriesStatus_Inconsistent; | |
505 } | |
506 | |
507 instances.insert(index); | |
508 } | |
509 | |
510 if (instances.size() == expected) | |
511 { | |
512 return SeriesStatus_Complete; | |
513 } | |
514 else | |
515 { | |
516 return SeriesStatus_Missing; | |
517 } | |
518 } | |
519 | |
520 | |
521 | |
202 | 522 void ServerIndex::MainDicomTagsToJson(Json::Value& target, |
523 int64_t resourceId) | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
524 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
525 DicomMap tags; |
202 | 526 db_->GetMainDicomTags(tags, resourceId); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
527 target["MainDicomTags"] = Json::objectValue; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
528 FromDcmtkBridge::ToJson(target["MainDicomTags"], tags); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
529 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
530 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
531 bool ServerIndex::LookupResource(Json::Value& result, |
199 | 532 const std::string& publicId, |
533 ResourceType expectedType) | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
534 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
535 result = Json::objectValue; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
536 |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
537 boost::mutex::scoped_lock lock(mutex_); |
199 | 538 |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
539 // Lookup for the requested resource |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
540 int64_t id; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
541 ResourceType type; |
202 | 542 if (!db_->LookupResource(publicId, id, type) || |
199 | 543 type != expectedType) |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
544 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
545 return false; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
546 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
547 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
548 // Find the parent resource (if it exists) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
549 if (type != ResourceType_Patient) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
550 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
551 int64_t parentId; |
202 | 552 if (!db_->LookupParent(parentId, id)) |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
553 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
554 throw OrthancException(ErrorCode_InternalError); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
555 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
556 |
202 | 557 std::string parent = db_->GetPublicId(parentId); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
558 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
559 switch (type) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
560 { |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
561 case ResourceType_Study: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
562 result["ParentPatient"] = parent; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
563 break; |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
564 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
565 case ResourceType_Series: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
566 result["ParentStudy"] = parent; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
567 break; |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
568 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
569 case ResourceType_Instance: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
570 result["ParentSeries"] = parent; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
571 break; |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
572 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
573 default: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
574 throw OrthancException(ErrorCode_InternalError); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
575 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
576 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
577 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
578 // List the children resources |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
579 std::list<std::string> children; |
202 | 580 db_->GetChildrenPublicId(children, id); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
581 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
582 if (type != ResourceType_Instance) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
583 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
584 Json::Value c = Json::arrayValue; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
585 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
586 for (std::list<std::string>::const_iterator |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
587 it = children.begin(); it != children.end(); it++) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
588 { |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
589 c.append(*it); |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
590 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
591 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
592 switch (type) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
593 { |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
594 case ResourceType_Patient: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
595 result["Studies"] = c; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
596 break; |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
597 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
598 case ResourceType_Study: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
599 result["Series"] = c; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
600 break; |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
601 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
602 case ResourceType_Series: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
603 result["Instances"] = c; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
604 break; |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
605 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
606 default: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
607 throw OrthancException(ErrorCode_InternalError); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
608 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
609 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
610 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
611 // Set the resource type |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
612 switch (type) |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
613 { |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
614 case ResourceType_Patient: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
615 result["Type"] = "Patient"; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
616 break; |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
617 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
618 case ResourceType_Study: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
619 result["Type"] = "Study"; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
620 break; |
199 | 621 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
622 case ResourceType_Series: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
623 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
624 result["Type"] = "Series"; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
625 result["Status"] = ToString(GetSeriesStatus(id)); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
626 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
627 int i; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
628 if (db_->GetMetadataAsInteger(i, id, MetadataType_Series_ExpectedNumberOfInstances)) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
629 result["ExpectedNumberOfInstances"] = i; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
630 else |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
631 result["ExpectedNumberOfInstances"] = Json::nullValue; |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
632 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
633 break; |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
634 } |
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
635 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
636 case ResourceType_Instance: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
637 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
638 result["Type"] = "Instance"; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
639 |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
640 FileInfo attachment; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
641 if (!db_->LookupAttachment(attachment, id, FileContentType_Dicom)) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
642 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
643 throw OrthancException(ErrorCode_InternalError); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
644 } |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
645 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
646 result["FileSize"] = static_cast<unsigned int>(attachment.GetUncompressedSize()); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
647 result["FileUuid"] = attachment.GetUuid(); |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
648 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
649 int i; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
650 if (db_->GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries)) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
651 result["IndexInSeries"] = i; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
652 else |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
653 result["IndexInSeries"] = Json::nullValue; |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
654 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
655 break; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
656 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
657 |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
658 default: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
659 throw OrthancException(ErrorCode_InternalError); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
660 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
661 |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
662 // Record the remaining information |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
663 result["ID"] = publicId; |
202 | 664 MainDicomTagsToJson(result, id); |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
665 |
315 | 666 std::string tmp; |
667 | |
668 tmp = db_->GetMetadata(id, MetadataType_AnonymizedFrom); | |
669 if (tmp.size() != 0) | |
670 result["AnonymizedFrom"] = tmp; | |
671 | |
672 tmp = db_->GetMetadata(id, MetadataType_ModifiedFrom); | |
673 if (tmp.size() != 0) | |
674 result["ModifiedFrom"] = tmp; | |
675 | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
676 return true; |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
677 } |
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
678 |
0 | 679 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
680 bool ServerIndex::LookupAttachment(FileInfo& attachment, |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
681 const std::string& instanceUuid, |
233 | 682 FileContentType contentType) |
0 | 683 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
684 boost::mutex::scoped_lock lock(mutex_); |
0 | 685 |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
686 int64_t id; |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
687 ResourceType type; |
202 | 688 if (!db_->LookupResource(instanceUuid, id, type) || |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
689 type != ResourceType_Instance) |
192
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
690 { |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
691 throw OrthancException(ErrorCode_InternalError); |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
692 } |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
693 |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
694 if (db_->LookupAttachment(attachment, id, contentType)) |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
695 { |
233 | 696 assert(attachment.GetContentType() == contentType); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
697 return true; |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
698 } |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
699 else |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
700 { |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
701 return false; |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
702 } |
192
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
703 } |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
704 |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
705 |
c56dc32266e0
refactoring getfile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
191
diff
changeset
|
706 |
0 | 707 void ServerIndex::GetAllUuids(Json::Value& target, |
190 | 708 ResourceType resourceType) |
0 | 709 { |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
710 boost::mutex::scoped_lock lock(mutex_); |
202 | 711 db_->GetAllPublicIds(target, resourceType); |
0 | 712 } |
713 | |
714 | |
715 bool ServerIndex::GetChanges(Json::Value& target, | |
204 | 716 int64_t since, |
0 | 717 unsigned int maxResults) |
718 { | |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
205
diff
changeset
|
719 boost::mutex::scoped_lock lock(mutex_); |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
720 db_->GetChanges(target, since, maxResults); |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
721 return true; |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
722 } |
0 | 723 |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
724 bool ServerIndex::GetLastChange(Json::Value& target) |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
725 { |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
726 boost::mutex::scoped_lock lock(mutex_); |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
727 db_->GetLastChange(target); |
204 | 728 return true; |
0 | 729 } |
231 | 730 |
731 void ServerIndex::LogExportedResource(const std::string& publicId, | |
732 const std::string& remoteModality) | |
733 { | |
734 boost::mutex::scoped_lock lock(mutex_); | |
735 | |
736 int64_t id; | |
737 ResourceType type; | |
738 if (!db_->LookupResource(publicId, id, type)) | |
739 { | |
740 throw OrthancException(ErrorCode_InternalError); | |
741 } | |
742 | |
743 std::string patientId; | |
744 std::string studyInstanceUid; | |
745 std::string seriesInstanceUid; | |
746 std::string sopInstanceUid; | |
747 | |
748 int64_t currentId = id; | |
749 ResourceType currentType = type; | |
750 | |
751 // Iteratively go up inside the patient/study/series/instance hierarchy | |
752 bool done = false; | |
753 while (!done) | |
754 { | |
755 DicomMap map; | |
756 db_->GetMainDicomTags(map, currentId); | |
757 | |
758 switch (currentType) | |
759 { | |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
760 case ResourceType_Patient: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
761 patientId = map.GetValue(DICOM_TAG_PATIENT_ID).AsString(); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
762 done = true; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
763 break; |
231 | 764 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
765 case ResourceType_Study: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
766 studyInstanceUid = map.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).AsString(); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
767 currentType = ResourceType_Patient; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
768 break; |
231 | 769 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
770 case ResourceType_Series: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
771 seriesInstanceUid = map.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).AsString(); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
772 currentType = ResourceType_Study; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
773 break; |
231 | 774 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
775 case ResourceType_Instance: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
776 sopInstanceUid = map.GetValue(DICOM_TAG_SOP_INSTANCE_UID).AsString(); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
777 currentType = ResourceType_Series; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
778 break; |
231 | 779 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
780 default: |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
781 throw OrthancException(ErrorCode_InternalError); |
231 | 782 } |
783 | |
784 // If we have not reached the Patient level, find the parent of | |
785 // the current resource | |
786 if (!done) | |
787 { | |
788 assert(db_->LookupParent(currentId, currentId)); | |
789 } | |
790 } | |
791 | |
792 // No need for a SQLite::Transaction here, as we only insert 1 record | |
793 db_->LogExportedResource(type, | |
794 publicId, | |
795 remoteModality, | |
796 patientId, | |
797 studyInstanceUid, | |
798 seriesInstanceUid, | |
799 sopInstanceUid); | |
800 } | |
801 | |
802 | |
803 bool ServerIndex::GetExportedResources(Json::Value& target, | |
804 int64_t since, | |
805 unsigned int maxResults) | |
806 { | |
807 boost::mutex::scoped_lock lock(mutex_); | |
808 db_->GetExportedResources(target, since, maxResults); | |
809 return true; | |
810 } | |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
811 |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
812 bool ServerIndex::GetLastExportedResource(Json::Value& target) |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
813 { |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
814 boost::mutex::scoped_lock lock(mutex_); |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
815 db_->GetLastExportedResource(target); |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
816 return true; |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
817 } |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
818 |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
819 |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
820 bool ServerIndex::IsRecyclingNeeded(uint64_t instanceSize) |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
821 { |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
822 if (maximumStorageSize_ != 0) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
823 { |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
824 uint64_t currentSize = currentStorageSize_ - listener_->GetSizeOfFilesToRemove(); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
825 assert(db_->GetTotalCompressedSize() == currentSize); |
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
826 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
827 if (currentSize + instanceSize > maximumStorageSize_) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
828 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
829 return true; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
830 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
831 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
832 |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
833 if (maximumPatients_ != 0) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
834 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
835 uint64_t patientCount = db_->GetResourceCount(ResourceType_Patient); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
836 if (patientCount > maximumPatients_) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
837 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
838 return true; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
839 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
840 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
841 |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
842 return false; |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
843 } |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
844 |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
845 |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
846 void ServerIndex::Recycle(uint64_t instanceSize, |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
847 const std::string& newPatientId) |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
848 { |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
849 if (!IsRecyclingNeeded(instanceSize)) |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
850 { |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
851 return; |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
852 } |
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
853 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
854 // Check whether other DICOM instances from this patient are |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
855 // already stored |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
856 int64_t patientToAvoid; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
857 ResourceType type; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
858 bool hasPatientToAvoid = db_->LookupResource(newPatientId, patientToAvoid, type); |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
859 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
860 if (hasPatientToAvoid && type != ResourceType_Patient) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
861 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
862 throw OrthancException(ErrorCode_InternalError); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
863 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
864 |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
865 // Iteratively select patient to remove until there is enough |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
866 // space in the DICOM store |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
867 int64_t patientToRecycle; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
868 while (true) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
869 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
870 // If other instances of this patient are already in the store, |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
871 // we must avoid to recycle them |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
872 bool ok = hasPatientToAvoid ? |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
873 db_->SelectPatientToRecycle(patientToRecycle, patientToAvoid) : |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
874 db_->SelectPatientToRecycle(patientToRecycle); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
875 |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
876 if (!ok) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
877 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
878 throw OrthancException(ErrorCode_FullStorage); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
879 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
880 |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
881 LOG(INFO) << "Recycling one patient"; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
882 db_->DeleteResource(patientToRecycle); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
883 |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
884 if (!IsRecyclingNeeded(instanceSize)) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
885 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
886 // OK, we're done |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
887 break; |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
888 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
889 } |
268
4bc02e2254ec
preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
264
diff
changeset
|
890 } |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
891 |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
892 void ServerIndex::SetMaximumPatientCount(unsigned int count) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
893 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
894 boost::mutex::scoped_lock lock(mutex_); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
895 maximumPatients_ = count; |
270
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
896 |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
897 if (count == 0) |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
898 { |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
899 LOG(WARNING) << "No limit on the number of stored patients"; |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
900 } |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
901 else |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
902 { |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
903 LOG(WARNING) << "At most " << count << " patients will be stored"; |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
904 } |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
905 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
906 StandaloneRecycling(); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
907 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
908 |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
909 void ServerIndex::SetMaximumStorageSize(uint64_t size) |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
910 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
911 boost::mutex::scoped_lock lock(mutex_); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
912 maximumStorageSize_ = size; |
270
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
913 |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
914 if (size == 0) |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
915 { |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
916 LOG(WARNING) << "No limit on the size of the storage area"; |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
917 } |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
918 else |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
919 { |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
920 LOG(WARNING) << "At most " << (size / (1024 * 1024)) << "MB will be used for the storage area"; |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
921 } |
e6a4c4329481
parameters for storage capacity
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
269
diff
changeset
|
922 |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
923 StandaloneRecycling(); |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
924 } |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
925 |
272
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
926 void ServerIndex::StandaloneRecycling() |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
927 { |
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
928 // WARNING: No mutex here, do not include this as a public method |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
929 Transaction t(*this); |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
930 Recycle(0, ""); |
278
771f12042be9
more efficient determination of storage size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
273
diff
changeset
|
931 t.Commit(0); |
269
f6fdf5abe751
recycling up and running
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
932 } |
272
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
933 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
934 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
935 bool ServerIndex::IsProtectedPatient(const std::string& publicId) |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
936 { |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
937 boost::mutex::scoped_lock lock(mutex_); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
938 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
939 // Lookup for the requested resource |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
940 int64_t id; |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
941 ResourceType type; |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
942 if (!db_->LookupResource(publicId, id, type) || |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
943 type != ResourceType_Patient) |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
944 { |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
945 throw OrthancException(ErrorCode_ParameterOutOfRange); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
946 } |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
947 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
948 return db_->IsProtectedPatient(id); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
949 } |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
950 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
951 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
952 void ServerIndex::SetProtectedPatient(const std::string& publicId, |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
953 bool isProtected) |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
954 { |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
955 boost::mutex::scoped_lock lock(mutex_); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
956 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
957 // Lookup for the requested resource |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
958 int64_t id; |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
959 ResourceType type; |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
960 if (!db_->LookupResource(publicId, id, type) || |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
961 type != ResourceType_Patient) |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
962 { |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
963 throw OrthancException(ErrorCode_ParameterOutOfRange); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
964 } |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
965 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
966 // No need for a SQLite::Transaction here, as we only make 1 write to the DB |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
967 db_->SetProtectedPatient(id, isProtected); |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
968 |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
969 if (isProtected) |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
970 LOG(INFO) << "Patient " << publicId << " has been protected"; |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
971 else |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
972 LOG(INFO) << "Patient " << publicId << " has been unprotected"; |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
973 } |
337c506461d2
protection from rest api
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
270
diff
changeset
|
974 |
304 | 975 |
976 void ServerIndex::GetChildInstances(std::list<std::string>& result, | |
977 const std::string& publicId) | |
978 { | |
979 result.clear(); | |
980 | |
981 boost::mutex::scoped_lock lock(mutex_); | |
982 | |
983 ResourceType type; | |
984 int64_t top; | |
985 if (!db_->LookupResource(publicId, top, type)) | |
986 { | |
987 throw OrthancException(ErrorCode_UnknownResource); | |
988 } | |
989 | |
990 if (type == ResourceType_Instance) | |
991 { | |
992 // The resource is already an instance: Do not go down the hierarchy | |
993 result.push_back(publicId); | |
994 return; | |
995 } | |
996 | |
997 std::stack<int64_t> toExplore; | |
998 toExplore.push(top); | |
999 | |
1000 std::list<int64_t> tmp; | |
1001 | |
1002 while (!toExplore.empty()) | |
1003 { | |
1004 // Get the internal ID of the current resource | |
1005 int64_t resource = toExplore.top(); | |
1006 toExplore.pop(); | |
1007 | |
1008 if (db_->GetResourceType(resource) == ResourceType_Instance) | |
1009 { | |
1010 result.push_back(db_->GetPublicId(resource)); | |
1011 } | |
1012 else | |
1013 { | |
1014 // Tag all the children of this resource as to be explored | |
1015 db_->GetChildrenInternalId(tmp, resource); | |
1016 for (std::list<int64_t>::const_iterator | |
1017 it = tmp.begin(); it != tmp.end(); it++) | |
1018 { | |
1019 toExplore.push(*it); | |
1020 } | |
1021 } | |
1022 } | |
1023 } | |
1024 | |
306
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1025 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1026 void ServerIndex::SetMetadata(const std::string& publicId, |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1027 MetadataType type, |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1028 const std::string& value) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1029 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1030 boost::mutex::scoped_lock lock(mutex_); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1031 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1032 ResourceType rtype; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1033 int64_t id; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1034 if (!db_->LookupResource(publicId, id, rtype)) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1035 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1036 throw OrthancException(ErrorCode_UnknownResource); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1037 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1038 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1039 db_->SetMetadata(id, type, value); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1040 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1041 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1042 bool ServerIndex::LookupMetadata(std::string& target, |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1043 const std::string& publicId, |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1044 MetadataType type) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1045 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1046 boost::mutex::scoped_lock lock(mutex_); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1047 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1048 ResourceType rtype; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1049 int64_t id; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1050 if (!db_->LookupResource(publicId, id, rtype)) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1051 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1052 throw OrthancException(ErrorCode_UnknownResource); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1053 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1054 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1055 return db_->LookupMetadata(target, id, type); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1056 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1057 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1058 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1059 bool ServerIndex::LookupParent(std::string& target, |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1060 const std::string& publicId) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1061 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1062 boost::mutex::scoped_lock lock(mutex_); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1063 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1064 ResourceType type; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1065 int64_t id; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1066 if (!db_->LookupResource(publicId, id, type)) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1067 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1068 throw OrthancException(ErrorCode_UnknownResource); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1069 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1070 |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1071 int64_t parentId; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1072 if (db_->LookupParent(parentId, id)) |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1073 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1074 target = db_->GetPublicId(parentId); |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1075 return true; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1076 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1077 else |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1078 { |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1079 return false; |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1080 } |
326d5a4a5af3
modification of instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1081 } |
310 | 1082 |
1083 | |
1084 uint64_t ServerIndex::IncrementGlobalSequence(GlobalProperty sequence) | |
1085 { | |
1086 boost::mutex::scoped_lock lock(mutex_); | |
311 | 1087 |
1088 std::auto_ptr<SQLite::Transaction> transaction(db_->StartTransaction()); | |
1089 | |
1090 transaction->Begin(); | |
1091 uint64_t seq = db_->IncrementGlobalSequence(sequence); | |
1092 transaction->Commit(); | |
1093 | |
1094 return seq; | |
310 | 1095 } |
315 | 1096 |
1097 | |
1098 | |
1099 void ServerIndex::LogChange(ChangeType changeType, | |
1100 const std::string& publicId) | |
1101 { | |
1102 boost::mutex::scoped_lock lock(mutex_); | |
1103 std::auto_ptr<SQLite::Transaction> transaction(db_->StartTransaction()); | |
1104 transaction->Begin(); | |
1105 | |
1106 int64_t id; | |
1107 ResourceType type; | |
1108 if (!db_->LookupResource(publicId, id, type)) | |
1109 { | |
1110 throw OrthancException(ErrorCode_UnknownResource); | |
1111 } | |
1112 | |
1113 db_->LogChange(changeType, id, type); | |
1114 | |
1115 transaction->Commit(); | |
1116 } | |
0 | 1117 } |