Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 1198:1169528a9a5f db-changes
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 23 Oct 2014 13:52:01 +0200 |
parents | 669bb978d52e |
children | efece308018e |
comparison
equal
deleted
inserted
replaced
1197:61b71ccac362 | 1198:1169528a9a5f |
---|---|
35 | 35 |
36 #ifndef NOMINMAX | 36 #ifndef NOMINMAX |
37 #define NOMINMAX | 37 #define NOMINMAX |
38 #endif | 38 #endif |
39 | 39 |
40 #include "ServerIndexChange.h" | |
40 #include "EmbeddedResources.h" | 41 #include "EmbeddedResources.h" |
41 #include "OrthancInitialization.h" | 42 #include "OrthancInitialization.h" |
42 #include "../Core/Toolbox.h" | 43 #include "../Core/Toolbox.h" |
43 #include "../Core/Uuid.h" | 44 #include "../Core/Uuid.h" |
44 #include "../Core/DicomFormat/DicomArray.h" | 45 #include "../Core/DicomFormat/DicomArray.h" |
80 { | 81 { |
81 return type_; | 82 return type_; |
82 } | 83 } |
83 }; | 84 }; |
84 | 85 |
85 struct ServerIndexChange | |
86 { | |
87 private: | |
88 ChangeType changeType_; | |
89 ResourceType resourceType_; | |
90 std::string publicId_; | |
91 | |
92 public: | |
93 ServerIndexChange(ChangeType changeType, | |
94 ResourceType resourceType, | |
95 const std::string& publicId) : | |
96 changeType_(changeType), | |
97 resourceType_(resourceType), | |
98 publicId_(publicId) | |
99 { | |
100 } | |
101 | |
102 ChangeType GetChangeType() const | |
103 { | |
104 return changeType_; | |
105 } | |
106 | |
107 ResourceType GetResourceType() const | |
108 { | |
109 return resourceType_; | |
110 } | |
111 | |
112 const std::string& GetPublicId() const | |
113 { | |
114 return publicId_; | |
115 } | |
116 }; | |
117 | |
118 ServerContext& context_; | 86 ServerContext& context_; |
119 bool hasRemainingLevel_; | 87 bool hasRemainingLevel_; |
120 ResourceType remainingType_; | 88 ResourceType remainingType_; |
121 std::string remainingPublicId_; | 89 std::string remainingPublicId_; |
122 std::list<FileToRemove> pendingFilesToRemove_; | 90 std::list<FileToRemove> pendingFilesToRemove_; |
172 { | 140 { |
173 for (std::list<ServerIndexChange>::const_iterator | 141 for (std::list<ServerIndexChange>::const_iterator |
174 it = pendingChanges_.begin(); | 142 it = pendingChanges_.begin(); |
175 it != pendingChanges_.end(); it++) | 143 it != pendingChanges_.end(); it++) |
176 { | 144 { |
177 context_.SignalChange(it->GetChangeType(), it->GetResourceType(), it->GetPublicId()); | 145 context_.SignalChange(*it); |
178 } | 146 } |
179 } | 147 } |
180 | 148 |
181 virtual void SignalRemainingAncestor(ResourceType parentType, | 149 virtual void SignalRemainingAncestor(ResourceType parentType, |
182 const std::string& publicId) | 150 const std::string& publicId) |
204 assert(Toolbox::IsUuid(info.GetUuid())); | 172 assert(Toolbox::IsUuid(info.GetUuid())); |
205 pendingFilesToRemove_.push_back(FileToRemove(info)); | 173 pendingFilesToRemove_.push_back(FileToRemove(info)); |
206 sizeOfFilesToRemove_ += info.GetCompressedSize(); | 174 sizeOfFilesToRemove_ += info.GetCompressedSize(); |
207 } | 175 } |
208 | 176 |
209 virtual void SignalChange(ChangeType changeType, | 177 virtual void SignalChange(const ServerIndexChange& change) |
210 ResourceType resourceType, | 178 { |
211 const std::string& publicId) | 179 LOG(INFO) << "Change related to resource " << change.GetPublicId() << " of type " |
212 { | 180 << EnumerationToString(change.GetResourceType()) << ": " |
213 LOG(INFO) << "Change related to resource " << publicId << " of type " | 181 << EnumerationToString(change.GetChangeType()); |
214 << EnumerationToString(resourceType) << ": " << EnumerationToString(changeType); | |
215 | 182 |
216 if (insideTransaction_) | 183 if (insideTransaction_) |
217 { | 184 { |
218 pendingChanges_.push_back(ServerIndexChange(changeType, resourceType, publicId)); | 185 pendingChanges_.push_back(change); |
219 } | 186 } |
220 else | 187 else |
221 { | 188 { |
222 context_.SignalChange(changeType, resourceType, publicId); | 189 context_.SignalChange(change); |
223 } | 190 } |
224 } | 191 } |
225 | 192 |
226 bool HasRemainingLevel() const | 193 bool HasRemainingLevel() const |
227 { | 194 { |
704 } | 671 } |
705 | 672 |
706 SeriesStatus seriesStatus = GetSeriesStatus(series); | 673 SeriesStatus seriesStatus = GetSeriesStatus(series); |
707 if (seriesStatus == SeriesStatus_Complete) | 674 if (seriesStatus == SeriesStatus_Complete) |
708 { | 675 { |
709 db_->LogChange(ChangeType_CompletedSeries, series, ResourceType_Series, hasher.HashSeries()); | 676 db_->LogChange(series, ChangeType_CompletedSeries, ResourceType_Series, hasher.HashSeries()); |
710 } | 677 } |
711 | 678 |
712 // Mark the parent resources of this instance as unstable | 679 // Mark the parent resources of this instance as unstable |
713 MarkAsUnstable(series, ResourceType_Series, hasher.HashSeries()); | 680 MarkAsUnstable(series, ResourceType_Series, hasher.HashSeries()); |
714 MarkAsUnstable(study, ResourceType_Study, hasher.HashStudy()); | 681 MarkAsUnstable(study, ResourceType_Study, hasher.HashStudy()); |
1493 if (!db_->LookupResource(publicId, id, type)) | 1460 if (!db_->LookupResource(publicId, id, type)) |
1494 { | 1461 { |
1495 throw OrthancException(ErrorCode_UnknownResource); | 1462 throw OrthancException(ErrorCode_UnknownResource); |
1496 } | 1463 } |
1497 | 1464 |
1498 db_->LogChange(changeType, id, type, publicId); | 1465 db_->LogChange(id, changeType, type, publicId); |
1499 | 1466 |
1500 transaction->Commit(); | 1467 transaction->Commit(); |
1501 } | 1468 } |
1502 | 1469 |
1503 | 1470 |
1693 if (that->db_->IsExistingResource(id)) | 1660 if (that->db_->IsExistingResource(id)) |
1694 { | 1661 { |
1695 switch (payload.GetResourceType()) | 1662 switch (payload.GetResourceType()) |
1696 { | 1663 { |
1697 case ResourceType_Patient: | 1664 case ResourceType_Patient: |
1698 that->db_->LogChange(ChangeType_StablePatient, id, ResourceType_Patient, payload.GetPublicId()); | 1665 that->db_->LogChange(id, ChangeType_StablePatient, ResourceType_Patient, payload.GetPublicId()); |
1699 break; | 1666 break; |
1700 | 1667 |
1701 case ResourceType_Study: | 1668 case ResourceType_Study: |
1702 that->db_->LogChange(ChangeType_StableStudy, id, ResourceType_Study, payload.GetPublicId()); | 1669 that->db_->LogChange(id, ChangeType_StableStudy, ResourceType_Study, payload.GetPublicId()); |
1703 break; | 1670 break; |
1704 | 1671 |
1705 case ResourceType_Series: | 1672 case ResourceType_Series: |
1706 that->db_->LogChange(ChangeType_StableSeries, id, ResourceType_Series, payload.GetPublicId()); | 1673 that->db_->LogChange(id, ChangeType_StableSeries, ResourceType_Series, payload.GetPublicId()); |
1707 break; | 1674 break; |
1708 | 1675 |
1709 default: | 1676 default: |
1710 throw OrthancException(ErrorCode_InternalError); | 1677 throw OrthancException(ErrorCode_InternalError); |
1711 } | 1678 } |
1731 | 1698 |
1732 UnstableResourcePayload payload(type, publicId); | 1699 UnstableResourcePayload payload(type, publicId); |
1733 unstableResources_.AddOrMakeMostRecent(id, payload); | 1700 unstableResources_.AddOrMakeMostRecent(id, payload); |
1734 //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id; | 1701 //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id; |
1735 | 1702 |
1736 db_->LogChange(ChangeType_NewChildInstance, id, type, publicId); | 1703 db_->LogChange(id, ChangeType_NewChildInstance, type, publicId); |
1737 } | 1704 } |
1738 | 1705 |
1739 | 1706 |
1740 | 1707 |
1741 void ServerIndex::LookupIdentifier(std::list<std::string>& result, | 1708 void ServerIndex::LookupIdentifier(std::list<std::string>& result, |