Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 204:7f4acf490179
changes api
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Nov 2012 11:27:57 +0100 |
parents | 1650557bd81a |
children | 6ab754744446 |
comparison
equal
deleted
inserted
replaced
203:9283552c25df | 204:7f4acf490179 |
---|---|
118 { | 118 { |
119 assert(HasRemainingLevel()); | 119 assert(HasRemainingLevel()); |
120 return remainingPublicId_; | 120 return remainingPublicId_; |
121 } | 121 } |
122 }; | 122 }; |
123 | |
124 | |
125 class DeleteFromFileStorageFunction : public SQLite::IScalarFunction | |
126 { | |
127 private: | |
128 FileStorage& fileStorage_; | |
129 | |
130 public: | |
131 DeleteFromFileStorageFunction(FileStorage& fileStorage) : | |
132 fileStorage_(fileStorage) | |
133 { | |
134 } | |
135 | |
136 virtual const char* GetName() const | |
137 { | |
138 return "DeleteFromFileStorage"; | |
139 } | |
140 | |
141 virtual unsigned int GetCardinality() const | |
142 { | |
143 return 1; | |
144 } | |
145 | |
146 virtual void Compute(SQLite::FunctionContext& context) | |
147 { | |
148 std::string fileUuid = context.GetStringValue(0); | |
149 LOG(INFO) << "Removing file [" << fileUuid << "]"; | |
150 | |
151 if (Toolbox::IsUuid(fileUuid)) | |
152 { | |
153 fileStorage_.Remove(fileUuid); | |
154 } | |
155 } | |
156 }; | |
157 | |
158 | |
159 class SignalDeletedLevelFunction : public SQLite::IScalarFunction | |
160 { | |
161 private: | |
162 int remainingLevel_; | |
163 std::string remainingLevelUuid_; | |
164 | |
165 public: | |
166 void Clear() | |
167 { | |
168 remainingLevel_ = std::numeric_limits<int>::max(); | |
169 } | |
170 | |
171 bool HasRemainingLevel() const | |
172 { | |
173 return (remainingLevel_ != 0 && | |
174 remainingLevel_ != std::numeric_limits<int>::max()); | |
175 } | |
176 | |
177 const std::string& GetRemainingLevelUuid() const | |
178 { | |
179 assert(HasRemainingLevel()); | |
180 return remainingLevelUuid_; | |
181 } | |
182 | |
183 const char* GetRemainingLevelType() const | |
184 { | |
185 assert(HasRemainingLevel()); | |
186 switch (remainingLevel_) | |
187 { | |
188 case 1: | |
189 return "patient"; | |
190 case 2: | |
191 return "study"; | |
192 case 3: | |
193 return "series"; | |
194 default: | |
195 throw OrthancException(ErrorCode_InternalError); | |
196 } | |
197 } | |
198 | |
199 virtual const char* GetName() const | |
200 { | |
201 return "SignalDeletedLevel"; | |
202 } | |
203 | |
204 virtual unsigned int GetCardinality() const | |
205 { | |
206 return 2; | |
207 } | |
208 | |
209 virtual void Compute(SQLite::FunctionContext& context) | |
210 { | |
211 int level = context.GetIntValue(0); | |
212 if (level < remainingLevel_) | |
213 { | |
214 remainingLevel_ = level; | |
215 remainingLevelUuid_ = context.GetStringValue(1); | |
216 } | |
217 | |
218 //printf("deleted level [%d] [%s]\n", level, context.GetStringValue(1).c_str()); | |
219 } | |
220 }; | |
221 } | 123 } |
222 | 124 |
223 | 125 |
224 bool ServerIndex::DeleteInternal(Json::Value& target, | 126 bool ServerIndex::DeleteInternal(Json::Value& target, |
225 const std::string& uuid, | 127 const std::string& uuid, |
246 { | 148 { |
247 ResourceType type = listener_->GetRemainingType(); | 149 ResourceType type = listener_->GetRemainingType(); |
248 const std::string& uuid = listener_->GetRemainingPublicId(); | 150 const std::string& uuid = listener_->GetRemainingPublicId(); |
249 | 151 |
250 target["RemainingAncestor"] = Json::Value(Json::objectValue); | 152 target["RemainingAncestor"] = Json::Value(Json::objectValue); |
251 target["RemainingAncestor"]["Path"] = std::string(GetBasePath(type)) + "/" + uuid; | 153 target["RemainingAncestor"]["Path"] = GetBasePath(type, uuid); |
252 target["RemainingAncestor"]["Type"] = ToString(type); | 154 target["RemainingAncestor"]["Type"] = ToString(type); |
253 target["RemainingAncestor"]["ID"] = uuid; | 155 target["RemainingAncestor"]["ID"] = uuid; |
254 } | 156 } |
255 else | 157 else |
256 { | 158 { |
696 db_->GetAllPublicIds(target, resourceType); | 598 db_->GetAllPublicIds(target, resourceType); |
697 } | 599 } |
698 | 600 |
699 | 601 |
700 bool ServerIndex::GetChanges(Json::Value& target, | 602 bool ServerIndex::GetChanges(Json::Value& target, |
701 int64_t since, | 603 int64_t since, |
702 const std::string& filter, | |
703 unsigned int maxResults) | 604 unsigned int maxResults) |
704 { | 605 { |
705 boost::mutex::scoped_lock scoped_lock(mutex_); | 606 boost::mutex::scoped_lock scoped_lock(mutex_); |
706 return false; | 607 |
707 // TODO !!!! | 608 db_->GetChanges(target, since, maxResults); |
708 | 609 |
709 /*assert(target.type() == Json::objectValue); | 610 return true; |
710 boost::mutex::scoped_lock scoped_lock(mutex_); | |
711 | |
712 if (filter.size() != 0 && | |
713 filter != "instances" && | |
714 filter != "series" && | |
715 filter != "studies" && | |
716 filter != "patients") | |
717 { | |
718 return false; | |
719 } | |
720 | |
721 std::auto_ptr<SQLite::Statement> s; | |
722 if (filter.size() == 0) | |
723 { | |
724 s.reset(new SQLite::Statement(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes WHERE seq>? " | |
725 "ORDER BY seq LIMIT ?")); | |
726 s->BindInt64(0, since); | |
727 s->BindInt(1, maxResults); | |
728 } | |
729 else | |
730 { | |
731 s.reset(new SQLite::Statement(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes WHERE seq>? " | |
732 "AND basePath=? ORDER BY seq LIMIT ?")); | |
733 s->BindInt64(0, since); | |
734 s->BindString(1, filter); | |
735 s->BindInt(2, maxResults); | |
736 } | |
737 | |
738 int64_t lastSeq = 0; | |
739 Json::Value results(Json::arrayValue); | |
740 while (s->Step()) | |
741 { | |
742 int64_t seq = s->ColumnInt64(0); | |
743 std::string basePath = s->ColumnString(1); | |
744 std::string uuid = s->ColumnString(2); | |
745 | |
746 if (filter.size() == 0 || | |
747 filter == basePath) | |
748 { | |
749 Json::Value change(Json::objectValue); | |
750 change["Seq"] = static_cast<int>(seq); // TODO JsonCpp in 64bit | |
751 change["BasePath"] = basePath; | |
752 change["ID"] = uuid; | |
753 results.append(change); | |
754 } | |
755 | |
756 if (seq > lastSeq) | |
757 { | |
758 lastSeq = seq; | |
759 } | |
760 } | |
761 | |
762 target["Results"] = results; | |
763 target["LastSeq"] = static_cast<int>(lastSeq); // TODO JsonCpp in 64bit | |
764 | |
765 return true;*/ | |
766 } | 611 } |
767 } | 612 } |