Mercurial > hg > orthanc
annotate OrthancServer/Sources/Database/Compatibility/SetOfResources.cpp @ 5464:38f1d06875ad pg-transactions
delete attachment in case of same instance being uploaded multiple times at the same time
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 12 Dec 2023 17:20:10 +0100 |
parents | 0ea402b4d901 |
children | 48b8dae6dc77 |
rev | line source |
---|---|
1746 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1746 | 4 * Department, University Hospital of Liege, Belgium |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1746 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
3052
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3050
diff
changeset
|
23 #include "../../PrecompiledHeadersServer.h" |
1746 | 24 #include "SetOfResources.h" |
25 | |
4045 | 26 #include "../../../../OrthancFramework/Sources/OrthancException.h" |
1746 | 27 |
28 | |
29 namespace Orthanc | |
30 { | |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
31 namespace Compatibility |
1746 | 32 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
33 void SetOfResources::Intersect(const std::list<int64_t>& resources) |
1746 | 34 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
35 if (resources_.get() == NULL) |
1746 | 36 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
37 resources_.reset(new Resources); |
1746 | 38 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
39 for (std::list<int64_t>::const_iterator |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
40 it = resources.begin(); it != resources.end(); ++it) |
1746 | 41 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
42 resources_->insert(*it); |
1746 | 43 } |
44 } | |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
45 else |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
46 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
47 std::unique_ptr<Resources> filtered(new Resources); |
1746 | 48 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
49 for (std::list<int64_t>::const_iterator |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
50 it = resources.begin(); it != resources.end(); ++it) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
51 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
52 if (resources_->find(*it) != resources_->end()) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
53 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
54 filtered->insert(*it); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
55 } |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
56 } |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
57 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
58 #if __cplusplus < 201103L |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
59 resources_.reset(filtered.release()); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
60 #else |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
61 resources_ = std::move(filtered); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
62 #endif |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
63 } |
1746 | 64 } |
65 | |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
66 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
67 void SetOfResources::GoDown() |
1753 | 68 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
69 if (level_ == ResourceType_Instance) |
1753 | 70 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
71 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
1746 | 72 } |
1753 | 73 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
74 if (resources_.get() != NULL) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
75 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
76 std::unique_ptr<Resources> children(new Resources); |
1746 | 77 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
78 for (Resources::const_iterator it = resources_->begin(); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
79 it != resources_->end(); ++it) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
80 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
81 std::list<int64_t> tmp; |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
82 transaction_.GetChildrenInternalId(tmp, *it); |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
83 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
84 for (std::list<int64_t>::const_iterator |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
85 child = tmp.begin(); child != tmp.end(); ++child) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
86 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
87 children->insert(*child); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
88 } |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
89 } |
1747 | 90 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
91 #if __cplusplus < 201103L |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
92 resources_.reset(children.release()); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
93 #else |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
94 resources_ = std::move(children); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
95 #endif |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
96 } |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
97 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
98 switch (level_) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
99 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
100 case ResourceType_Patient: |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
101 level_ = ResourceType_Study; |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
102 break; |
1747 | 103 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
104 case ResourceType_Study: |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
105 level_ = ResourceType_Series; |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
106 break; |
1747 | 107 |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
108 case ResourceType_Series: |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
109 level_ = ResourceType_Instance; |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
110 break; |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
111 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
112 default: |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
113 throw OrthancException(ErrorCode_InternalError); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
114 } |
1747 | 115 } |
1746 | 116 |
117 | |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
118 void SetOfResources::Flatten(std::list<std::string>& result) |
1746 | 119 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
120 result.clear(); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
121 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
122 if (resources_.get() == NULL) |
1746 | 123 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
124 // All the resources of this level are part of the filter |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
125 transaction_.GetAllPublicIds(result, level_); |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
126 } |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
127 else |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
128 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
129 for (Resources::const_iterator it = resources_->begin(); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
130 it != resources_->end(); ++it) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
131 { |
4591
ff8170d17d90
moving all accesses to databases from IDatabaseWrapper to ITransaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
132 result.push_back(transaction_.GetPublicId(*it)); |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
133 } |
1746 | 134 } |
135 } | |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
136 |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
137 |
3085 | 138 void SetOfResources::Flatten(ILookupResources& compatibility, |
3084 | 139 std::list<int64_t>& result) |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
140 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
141 result.clear(); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
142 |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
143 if (resources_.get() == NULL) |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
144 { |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
145 // All the resources of this level are part of the filter |
3084 | 146 compatibility.GetAllInternalIds(result, level_); |
3056
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
147 } |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
148 else |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
149 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
150 for (Resources::const_iterator it = resources_->begin(); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
151 it != resources_->end(); ++it) |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
152 { |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
153 result.push_back(*it); |
6c5d4281da4a
removal of SQLiteDatabaseWrapper::GetAllInternalIds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
154 } |
1750
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
155 } |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
156 } |
55d52567bebb
LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1747
diff
changeset
|
157 } |
1746 | 158 } |