Mercurial > hg > orthanc
annotate OrthancServer/Search/Compatibility/DatabaseLookup.cpp @ 3054:3638de45a08c db-changes
backward compatibility with filtering identifiers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 21 Dec 2018 12:45:24 +0100 |
parents | 3f986ce336c8 |
children | 71ac4f28176f |
rev | line source |
---|---|
3052
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 **/ |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include "../../PrecompiledHeadersServer.h" |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include "DatabaseLookup.h" |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
3054
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
37 #include "../../../Core/OrthancException.h" |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
38 #include "../../ServerToolbox.h" |
3052
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 #include "SetOfResources.h" |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 namespace Orthanc |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 { |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 namespace Compatibility |
3053
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
44 { |
3054
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
45 static void ApplyIdentifierConstraint(SetOfResources& candidates, |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
46 CompatibilityDatabaseWrapper& database, |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
47 const DatabaseConstraint& constraint, |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
48 ResourceType level) |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
49 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
50 std::list<int64_t> matches; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
51 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
52 switch (constraint.GetConstraintType()) |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
53 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
54 case ConstraintType_Equal: |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
55 database.LookupIdentifier(matches, level, constraint.GetTag(), |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
56 IdentifierConstraintType_Equal, constraint.GetSingleValue()); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
57 break; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
58 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
59 case ConstraintType_SmallerOrEqual: |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
60 database.LookupIdentifier(matches, level, constraint.GetTag(), |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
61 IdentifierConstraintType_SmallerOrEqual, constraint.GetSingleValue()); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
62 break; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
63 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
64 case ConstraintType_GreaterOrEqual: |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
65 database.LookupIdentifier(matches, level, constraint.GetTag(), |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
66 IdentifierConstraintType_GreaterOrEqual, constraint.GetSingleValue()); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
67 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
68 break; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
69 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
70 case ConstraintType_Wildcard: |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
71 database.LookupIdentifier(matches, level, constraint.GetTag(), |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
72 IdentifierConstraintType_Wildcard, constraint.GetSingleValue()); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
73 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
74 break; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
75 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
76 case ConstraintType_List: |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
77 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
78 for (size_t i = 0; i < constraint.GetValuesCount(); i++) |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
79 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
80 std::list<int64_t> tmp; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
81 database.LookupIdentifier(tmp, level, constraint.GetTag(), |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
82 IdentifierConstraintType_Wildcard, constraint.GetValue(i)); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
83 matches.splice(matches.end(), tmp); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
84 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
85 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
86 break; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
87 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
88 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
89 default: |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
90 throw OrthancException(ErrorCode_InternalError); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
91 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
92 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
93 candidates.Intersect(matches); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
94 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
95 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
96 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
97 static void ApplyIdentifierRange(SetOfResources& candidates, |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
98 CompatibilityDatabaseWrapper& database, |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
99 const DatabaseConstraint& smaller, |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
100 const DatabaseConstraint& greater, |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
101 ResourceType level) |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
102 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
103 assert(smaller.GetConstraintType() == ConstraintType_SmallerOrEqual && |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
104 greater.GetConstraintType() == ConstraintType_GreaterOrEqual && |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
105 smaller.GetTag() == greater.GetTag() && |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
106 ServerToolbox::IsIdentifier(smaller.GetTag(), level)); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
107 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
108 std::list<int64_t> matches; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
109 database.LookupIdentifierRange(matches, level, smaller.GetTag(), |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
110 greater.GetSingleValue(), smaller.GetSingleValue()); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
111 candidates.Intersect(matches); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
112 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
113 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
114 |
3053
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
115 static void ApplyLevel(SetOfResources& candidates, |
3054
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
116 CompatibilityDatabaseWrapper& database, |
3053
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
117 const std::vector<DatabaseConstraint>& lookup, |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
118 ResourceType level) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
119 { |
3054
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
120 typedef std::set<const DatabaseConstraint*> SetOfConstraints; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
121 typedef std::map<DicomTag, SetOfConstraints> Identifiers; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
122 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
123 Identifiers identifiers; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
124 SetOfConstraints mainTags; |
3053
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
125 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
126 for (size_t i = 0; i < lookup.size(); i++) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
127 { |
3054
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
128 if (lookup[i].GetLevel() == level) |
3053
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
129 { |
3054
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
130 if (lookup[i].IsIdentifier()) |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
131 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
132 identifiers[lookup[i].GetTag()].insert(&lookup[i]); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
133 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
134 else |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
135 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
136 mainTags.insert(&lookup[i]); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
137 } |
3053
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
138 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
139 } |
3054
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
140 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
141 for (Identifiers::const_iterator it = identifiers.begin(); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
142 it != identifiers.end(); ++it) |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
143 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
144 const DatabaseConstraint* smaller = NULL; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
145 const DatabaseConstraint* greater = NULL; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
146 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
147 for (SetOfConstraints::const_iterator it2 = it->second.begin(); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
148 it2 != it->second.end(); ++it2) |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
149 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
150 if ((*it2)->GetConstraintType() == ConstraintType_SmallerOrEqual) |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
151 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
152 smaller = *it2; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
153 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
154 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
155 if ((*it2)->GetConstraintType() == ConstraintType_GreaterOrEqual) |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
156 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
157 greater = *it2; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
158 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
159 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
160 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
161 if (smaller != NULL && |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
162 greater != NULL) |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
163 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
164 ApplyIdentifierRange(candidates, database, *smaller, *greater, level); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
165 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
166 else |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
167 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
168 smaller = NULL; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
169 greater = NULL; |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
170 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
171 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
172 for (SetOfConstraints::const_iterator it2 = it->second.begin(); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
173 it2 != it->second.end(); ++it2) |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
174 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
175 if (*it2 != smaller && |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
176 *it2 != greater) |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
177 { |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
178 ApplyIdentifierConstraint(candidates, database, **it2, level); |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
179 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
180 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
181 } |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
182 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
183 |
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
184 // TODO - Fiter main DICOM tags |
3053
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
185 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
186 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
187 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
188 static std::string GetOneInstance(IDatabaseWrapper& database, |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
189 int64_t resource, |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
190 ResourceType level) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
191 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
192 for (int i = level; i < ResourceType_Instance; i++) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
193 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
194 assert(database.GetResourceType(resource) == static_cast<ResourceType>(i)); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
195 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
196 std::list<int64_t> children; |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
197 database.GetChildrenInternalId(children, resource); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
198 |
3054
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
199 if (children.empty()) |
3053
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
200 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
201 throw OrthancException(ErrorCode_Database); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
202 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
203 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
204 resource = children.front(); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
205 } |
3054
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
206 |
3053
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
207 return database.GetPublicId(resource); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
208 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
209 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
210 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
211 void DatabaseLookup::ApplyLookupResources(std::vector<std::string>& resourcesId, |
3052
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 std::vector<std::string>* instancesId, |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 const std::vector<DatabaseConstraint>& lookup, |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 ResourceType queryLevel, |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 size_t limit) |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 { |
3053
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
217 // This is a re-implementation of |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
218 // "../../../Resources/Graveyard/DatabaseOptimizations/LookupResource.cpp" |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
219 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
220 assert(ResourceType_Patient < ResourceType_Study && |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
221 ResourceType_Study < ResourceType_Series && |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
222 ResourceType_Series < ResourceType_Instance); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
223 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
224 ResourceType upperLevel = queryLevel; |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
225 ResourceType lowerLevel = queryLevel; |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
226 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
227 for (size_t i = 0; i < lookup.size(); i++) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
228 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
229 ResourceType level = lookup[i].GetLevel(); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
230 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
231 if (level < upperLevel) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
232 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
233 upperLevel = level; |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
234 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
235 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
236 if (level > lowerLevel) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
237 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
238 lowerLevel = level; |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
239 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
240 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
241 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
242 assert(upperLevel <= queryLevel && |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
243 queryLevel <= lowerLevel); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
244 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
245 SetOfResources candidates(database_, upperLevel); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
246 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
247 for (int level = upperLevel; level <= lowerLevel; level++) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
248 { |
3054
3638de45a08c
backward compatibility with filtering identifiers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3053
diff
changeset
|
249 ApplyLevel(candidates, database_, lookup, static_cast<ResourceType>(level)); |
3053
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
250 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
251 if (level != lowerLevel) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
252 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
253 candidates.GoDown(); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
254 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
255 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
256 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
257 std::list<int64_t> resources; |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
258 candidates.Flatten(resources); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
259 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
260 // Climb up, up to queryLevel |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
261 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
262 for (int level = lowerLevel; level > queryLevel; level--) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
263 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
264 std::list<int64_t> parents; |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
265 for (std::list<int64_t>::const_iterator |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
266 it = resources.begin(); it != resources.end(); ++it) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
267 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
268 int64_t parent; |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
269 if (database_.LookupParent(parent, *it)) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
270 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
271 parents.push_back(parent); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
272 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
273 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
274 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
275 resources.swap(parents); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
276 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
277 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
278 // Apply the limit, if given |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
279 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
280 if (limit != 0 && |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
281 resources.size() > limit) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
282 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
283 resources.resize(limit); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
284 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
285 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
286 // Get the public ID of all the selected resources |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
287 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
288 resourcesId.resize(resources.size()); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
289 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
290 if (instancesId != NULL) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
291 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
292 instancesId->resize(resources.size()); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
293 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
294 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
295 size_t pos = 0; |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
296 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
297 for (std::list<int64_t>::const_iterator |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
298 it = resources.begin(); it != resources.end(); ++it, pos++) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
299 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
300 assert(database_.GetResourceType(*it) == queryLevel); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
301 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
302 resourcesId[pos] = database_.GetPublicId(*it); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
303 |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
304 if (instancesId != NULL) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
305 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
306 // Collect one child instance for each of the selected resources |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
307 if (queryLevel == ResourceType_Instance) |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
308 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
309 (*instancesId) [pos] = resourcesId[pos]; |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
310 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
311 else |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
312 { |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
313 (*instancesId) [pos] = GetOneInstance(database_, *it, queryLevel); |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
314 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
315 } |
3f986ce336c8
working on Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3052
diff
changeset
|
316 } |
3052
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 } |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
318 } |
c7db469bbe8e
new class: Compatibility::DatabaseLookup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 } |