Mercurial > hg > orthanc
comparison OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.cpp @ 4600:c02a04e6161d db-changes
processing of database events in OrthancPluginDatabaseV3
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 18 Mar 2021 12:09:29 +0100 |
parents | da2e0a457eae |
children | 27c07dbf6b4f |
comparison
equal
deleted
inserted
replaced
4599:3875dcb65987 | 4600:c02a04e6161d |
---|---|
60 { | 60 { |
61 that_.CheckSuccess(code); | 61 that_.CheckSuccess(code); |
62 } | 62 } |
63 | 63 |
64 | 64 |
65 static FileInfo Convert(const OrthancPluginAttachment& attachment) | |
66 { | |
67 return FileInfo(attachment.uuid, | |
68 static_cast<FileContentType>(attachment.contentType), | |
69 attachment.uncompressedSize, | |
70 attachment.uncompressedHash, | |
71 static_cast<CompressionType>(attachment.compressionType), | |
72 attachment.compressedSize, | |
73 attachment.compressedHash); | |
74 } | |
75 | |
76 | |
65 void ReadStringAnswers(std::list<std::string>& target) | 77 void ReadStringAnswers(std::list<std::string>& target) |
66 { | 78 { |
67 uint32_t count; | 79 uint32_t count; |
68 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); | 80 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); |
69 | 81 |
184 change.date); | 196 change.date); |
185 } | 197 } |
186 } | 198 } |
187 | 199 |
188 | 200 |
201 void CheckNoEvent() | |
202 { | |
203 uint32_t count; | |
204 CheckSuccess(that_.backend_.readEventsCount(transaction_, &count)); | |
205 if (count != 0) | |
206 { | |
207 throw OrthancException(ErrorCode_DatabasePlugin); | |
208 } | |
209 } | |
210 | |
211 | |
212 void ProcessEvents(bool isDeletingAttachment) | |
213 { | |
214 uint32_t count; | |
215 CheckSuccess(that_.backend_.readEventsCount(transaction_, &count)); | |
216 | |
217 for (uint32_t i = 0; i < count; i++) | |
218 { | |
219 OrthancPluginDatabaseEvent event; | |
220 CheckSuccess(that_.backend_.readEvent(transaction_, &event, i)); | |
221 | |
222 switch (event.type) | |
223 { | |
224 case OrthancPluginDatabaseEventType_DeletedAttachment: | |
225 listener_.SignalAttachmentDeleted(Convert(event.content.attachment)); | |
226 break; | |
227 | |
228 case OrthancPluginDatabaseEventType_DeletedResource: | |
229 if (isDeletingAttachment) | |
230 { | |
231 // This event should only be triggered by "DeleteResource()" | |
232 throw OrthancException(ErrorCode_DatabasePlugin); | |
233 } | |
234 else | |
235 { | |
236 listener_.SignalResourceDeleted(Plugins::Convert(event.content.resource.level), event.content.resource.publicId); | |
237 } | |
238 break; | |
239 | |
240 case OrthancPluginDatabaseEventType_RemainingAncestor: | |
241 if (isDeletingAttachment) | |
242 { | |
243 // This event should only triggered by "DeleteResource()" | |
244 throw OrthancException(ErrorCode_DatabasePlugin); | |
245 } | |
246 else | |
247 { | |
248 listener_.SignalRemainingAncestor(Plugins::Convert(event.content.resource.level), event.content.resource.publicId); | |
249 } | |
250 break; | |
251 | |
252 default: | |
253 break; // Unhandled event | |
254 } | |
255 } | |
256 } | |
257 | |
258 | |
189 public: | 259 public: |
190 Transaction(OrthancPluginDatabaseV3& that, | 260 Transaction(OrthancPluginDatabaseV3& that, |
191 IDatabaseListener& listener, | 261 IDatabaseListener& listener, |
192 _OrthancPluginDatabaseTransactionType type) : | 262 OrthancPluginDatabaseTransactionType type) : |
193 that_(that), | 263 that_(that), |
194 listener_(listener) | 264 listener_(listener) |
195 { | 265 { |
196 CheckSuccess(that.backend_.startTransaction(that.database_, &transaction_, type)); | 266 CheckSuccess(that.backend_.startTransaction(that.database_, &transaction_, type)); |
197 if (transaction_ == NULL) | 267 if (transaction_ == NULL) |
213 | 283 |
214 | 284 |
215 virtual void Rollback() ORTHANC_OVERRIDE | 285 virtual void Rollback() ORTHANC_OVERRIDE |
216 { | 286 { |
217 CheckSuccess(that_.backend_.rollback(transaction_)); | 287 CheckSuccess(that_.backend_.rollback(transaction_)); |
288 CheckNoEvent(); | |
218 } | 289 } |
219 | 290 |
220 | 291 |
221 virtual void Commit(int64_t fileSizeDelta) ORTHANC_OVERRIDE | 292 virtual void Commit(int64_t fileSizeDelta) ORTHANC_OVERRIDE |
222 { | 293 { |
223 CheckSuccess(that_.backend_.commit(transaction_, fileSizeDelta)); | 294 CheckSuccess(that_.backend_.commit(transaction_, fileSizeDelta)); |
295 CheckNoEvent(); | |
224 } | 296 } |
225 | 297 |
226 | 298 |
227 virtual void AddAttachment(int64_t id, | 299 virtual void AddAttachment(int64_t id, |
228 const FileInfo& attachment) ORTHANC_OVERRIDE | 300 const FileInfo& attachment) ORTHANC_OVERRIDE |
235 tmp.compressionType = static_cast<int32_t>(attachment.GetCompressionType()); | 307 tmp.compressionType = static_cast<int32_t>(attachment.GetCompressionType()); |
236 tmp.compressedSize = attachment.GetCompressedSize(); | 308 tmp.compressedSize = attachment.GetCompressedSize(); |
237 tmp.compressedHash = attachment.GetCompressedMD5().c_str(); | 309 tmp.compressedHash = attachment.GetCompressedMD5().c_str(); |
238 | 310 |
239 CheckSuccess(that_.backend_.addAttachment(transaction_, id, &tmp)); | 311 CheckSuccess(that_.backend_.addAttachment(transaction_, id, &tmp)); |
312 CheckNoEvent(); | |
240 } | 313 } |
241 | 314 |
242 | 315 |
243 virtual void ClearChanges() ORTHANC_OVERRIDE | 316 virtual void ClearChanges() ORTHANC_OVERRIDE |
244 { | 317 { |
245 CheckSuccess(that_.backend_.clearChanges(transaction_)); | 318 CheckSuccess(that_.backend_.clearChanges(transaction_)); |
319 CheckNoEvent(); | |
246 } | 320 } |
247 | 321 |
248 | 322 |
249 virtual void ClearExportedResources() ORTHANC_OVERRIDE | 323 virtual void ClearExportedResources() ORTHANC_OVERRIDE |
250 { | 324 { |
251 CheckSuccess(that_.backend_.clearExportedResources(transaction_)); | 325 CheckSuccess(that_.backend_.clearExportedResources(transaction_)); |
326 CheckNoEvent(); | |
252 } | 327 } |
253 | 328 |
254 | 329 |
255 virtual void DeleteAttachment(int64_t id, | 330 virtual void DeleteAttachment(int64_t id, |
256 FileContentType attachment) ORTHANC_OVERRIDE | 331 FileContentType attachment) ORTHANC_OVERRIDE |
257 { | 332 { |
258 CheckSuccess(that_.backend_.deleteAttachment(transaction_, id, static_cast<int32_t>(attachment))); | 333 CheckSuccess(that_.backend_.deleteAttachment(transaction_, id, static_cast<int32_t>(attachment))); |
334 ProcessEvents(true); | |
259 } | 335 } |
260 | 336 |
261 | 337 |
262 virtual void DeleteMetadata(int64_t id, | 338 virtual void DeleteMetadata(int64_t id, |
263 MetadataType type) ORTHANC_OVERRIDE | 339 MetadataType type) ORTHANC_OVERRIDE |
264 { | 340 { |
265 CheckSuccess(that_.backend_.deleteMetadata(transaction_, id, static_cast<int32_t>(type))); | 341 CheckSuccess(that_.backend_.deleteMetadata(transaction_, id, static_cast<int32_t>(type))); |
342 CheckNoEvent(); | |
266 } | 343 } |
267 | 344 |
268 | 345 |
269 virtual void DeleteResource(int64_t id) ORTHANC_OVERRIDE | 346 virtual void DeleteResource(int64_t id) ORTHANC_OVERRIDE |
270 { | 347 { |
271 CheckSuccess(that_.backend_.deleteResource(transaction_, id)); | 348 CheckSuccess(that_.backend_.deleteResource(transaction_, id)); |
349 ProcessEvents(false); | |
272 } | 350 } |
273 | 351 |
274 | 352 |
275 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target, | 353 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target, |
276 int64_t id) ORTHANC_OVERRIDE | 354 int64_t id) ORTHANC_OVERRIDE |
277 { | 355 { |
278 CheckSuccess(that_.backend_.getAllMetadata(transaction_, id)); | 356 CheckSuccess(that_.backend_.getAllMetadata(transaction_, id)); |
357 CheckNoEvent(); | |
279 | 358 |
280 uint32_t count; | 359 uint32_t count; |
281 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); | 360 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); |
282 | 361 |
283 target.clear(); | 362 target.clear(); |
301 | 380 |
302 virtual void GetAllPublicIds(std::list<std::string>& target, | 381 virtual void GetAllPublicIds(std::list<std::string>& target, |
303 ResourceType resourceType) ORTHANC_OVERRIDE | 382 ResourceType resourceType) ORTHANC_OVERRIDE |
304 { | 383 { |
305 CheckSuccess(that_.backend_.getAllPublicIds(transaction_, Plugins::Convert(resourceType))); | 384 CheckSuccess(that_.backend_.getAllPublicIds(transaction_, Plugins::Convert(resourceType))); |
385 CheckNoEvent(); | |
386 | |
306 ReadStringAnswers(target); | 387 ReadStringAnswers(target); |
307 } | 388 } |
308 | 389 |
309 | 390 |
310 virtual void GetAllPublicIds(std::list<std::string>& target, | 391 virtual void GetAllPublicIds(std::list<std::string>& target, |
313 size_t limit) ORTHANC_OVERRIDE | 394 size_t limit) ORTHANC_OVERRIDE |
314 { | 395 { |
315 CheckSuccess(that_.backend_.getAllPublicIdsWithLimit( | 396 CheckSuccess(that_.backend_.getAllPublicIdsWithLimit( |
316 transaction_, Plugins::Convert(resourceType), | 397 transaction_, Plugins::Convert(resourceType), |
317 static_cast<uint64_t>(since), static_cast<uint64_t>(limit))); | 398 static_cast<uint64_t>(since), static_cast<uint64_t>(limit))); |
399 CheckNoEvent(); | |
400 | |
318 ReadStringAnswers(target); | 401 ReadStringAnswers(target); |
319 } | 402 } |
320 | 403 |
321 | 404 |
322 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/, | 405 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/, |
324 int64_t since, | 407 int64_t since, |
325 uint32_t maxResults) ORTHANC_OVERRIDE | 408 uint32_t maxResults) ORTHANC_OVERRIDE |
326 { | 409 { |
327 uint8_t tmpDone = true; | 410 uint8_t tmpDone = true; |
328 CheckSuccess(that_.backend_.getChanges(transaction_, &tmpDone, since, maxResults)); | 411 CheckSuccess(that_.backend_.getChanges(transaction_, &tmpDone, since, maxResults)); |
412 CheckNoEvent(); | |
329 | 413 |
330 done = (tmpDone != 0); | 414 done = (tmpDone != 0); |
331 | 415 |
332 uint32_t count; | 416 uint32_t count; |
333 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); | 417 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); |
342 | 426 |
343 virtual void GetChildrenInternalId(std::list<int64_t>& target, | 427 virtual void GetChildrenInternalId(std::list<int64_t>& target, |
344 int64_t id) ORTHANC_OVERRIDE | 428 int64_t id) ORTHANC_OVERRIDE |
345 { | 429 { |
346 CheckSuccess(that_.backend_.getChildrenInternalId(transaction_, id)); | 430 CheckSuccess(that_.backend_.getChildrenInternalId(transaction_, id)); |
431 CheckNoEvent(); | |
347 | 432 |
348 uint32_t count; | 433 uint32_t count; |
349 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); | 434 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); |
350 | 435 |
351 target.clear(); | 436 target.clear(); |
360 | 445 |
361 virtual void GetChildrenPublicId(std::list<std::string>& target, | 446 virtual void GetChildrenPublicId(std::list<std::string>& target, |
362 int64_t id) ORTHANC_OVERRIDE | 447 int64_t id) ORTHANC_OVERRIDE |
363 { | 448 { |
364 CheckSuccess(that_.backend_.getChildrenPublicId(transaction_, id)); | 449 CheckSuccess(that_.backend_.getChildrenPublicId(transaction_, id)); |
450 CheckNoEvent(); | |
451 | |
365 ReadStringAnswers(target); | 452 ReadStringAnswers(target); |
366 } | 453 } |
367 | 454 |
368 | 455 |
369 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/, | 456 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/, |
371 int64_t since, | 458 int64_t since, |
372 uint32_t maxResults) ORTHANC_OVERRIDE | 459 uint32_t maxResults) ORTHANC_OVERRIDE |
373 { | 460 { |
374 uint8_t tmpDone = true; | 461 uint8_t tmpDone = true; |
375 CheckSuccess(that_.backend_.getExportedResources(transaction_, &tmpDone, since, maxResults)); | 462 CheckSuccess(that_.backend_.getExportedResources(transaction_, &tmpDone, since, maxResults)); |
463 CheckNoEvent(); | |
376 | 464 |
377 done = (tmpDone != 0); | 465 done = (tmpDone != 0); |
378 | 466 |
379 uint32_t count; | 467 uint32_t count; |
380 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); | 468 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); |
388 | 476 |
389 | 477 |
390 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/) ORTHANC_OVERRIDE | 478 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/) ORTHANC_OVERRIDE |
391 { | 479 { |
392 CheckSuccess(that_.backend_.getLastChange(transaction_)); | 480 CheckSuccess(that_.backend_.getLastChange(transaction_)); |
481 CheckNoEvent(); | |
393 | 482 |
394 uint32_t count; | 483 uint32_t count; |
395 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); | 484 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); |
396 | 485 |
397 target.clear(); | 486 target.clear(); |
407 | 496 |
408 | 497 |
409 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/) ORTHANC_OVERRIDE | 498 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/) ORTHANC_OVERRIDE |
410 { | 499 { |
411 CheckSuccess(that_.backend_.getLastExportedResource(transaction_)); | 500 CheckSuccess(that_.backend_.getLastExportedResource(transaction_)); |
501 CheckNoEvent(); | |
412 | 502 |
413 uint32_t count; | 503 uint32_t count; |
414 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); | 504 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); |
415 | 505 |
416 target.clear(); | 506 target.clear(); |
427 | 517 |
428 virtual void GetMainDicomTags(DicomMap& target, | 518 virtual void GetMainDicomTags(DicomMap& target, |
429 int64_t id) ORTHANC_OVERRIDE | 519 int64_t id) ORTHANC_OVERRIDE |
430 { | 520 { |
431 CheckSuccess(that_.backend_.getMainDicomTags(transaction_, id)); | 521 CheckSuccess(that_.backend_.getMainDicomTags(transaction_, id)); |
522 CheckNoEvent(); | |
432 | 523 |
433 uint32_t count; | 524 uint32_t count; |
434 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); | 525 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); |
435 | 526 |
436 target.Clear(); | 527 target.Clear(); |
453 | 544 |
454 | 545 |
455 virtual std::string GetPublicId(int64_t resourceId) ORTHANC_OVERRIDE | 546 virtual std::string GetPublicId(int64_t resourceId) ORTHANC_OVERRIDE |
456 { | 547 { |
457 CheckSuccess(that_.backend_.getPublicId(transaction_, resourceId)); | 548 CheckSuccess(that_.backend_.getPublicId(transaction_, resourceId)); |
549 CheckNoEvent(); | |
458 | 550 |
459 std::string s; | 551 std::string s; |
460 if (ReadSingleStringAnswer(s)) | 552 if (ReadSingleStringAnswer(s)) |
461 { | 553 { |
462 return s; | 554 return s; |
470 | 562 |
471 virtual uint64_t GetResourcesCount(ResourceType resourceType) ORTHANC_OVERRIDE | 563 virtual uint64_t GetResourcesCount(ResourceType resourceType) ORTHANC_OVERRIDE |
472 { | 564 { |
473 uint64_t value; | 565 uint64_t value; |
474 CheckSuccess(that_.backend_.getResourcesCount(transaction_, &value, Plugins::Convert(resourceType))); | 566 CheckSuccess(that_.backend_.getResourcesCount(transaction_, &value, Plugins::Convert(resourceType))); |
567 CheckNoEvent(); | |
475 return value; | 568 return value; |
476 } | 569 } |
477 | 570 |
478 | 571 |
479 virtual ResourceType GetResourceType(int64_t resourceId) ORTHANC_OVERRIDE | 572 virtual ResourceType GetResourceType(int64_t resourceId) ORTHANC_OVERRIDE |
480 { | 573 { |
481 OrthancPluginResourceType type; | 574 OrthancPluginResourceType type; |
482 CheckSuccess(that_.backend_.getResourceType(transaction_, &type, resourceId)); | 575 CheckSuccess(that_.backend_.getResourceType(transaction_, &type, resourceId)); |
576 CheckNoEvent(); | |
483 return Plugins::Convert(type); | 577 return Plugins::Convert(type); |
484 } | 578 } |
485 | 579 |
486 | 580 |
487 virtual uint64_t GetTotalCompressedSize() ORTHANC_OVERRIDE | 581 virtual uint64_t GetTotalCompressedSize() ORTHANC_OVERRIDE |
488 { | 582 { |
489 uint64_t s; | 583 uint64_t s; |
490 CheckSuccess(that_.backend_.getTotalCompressedSize(transaction_, &s)); | 584 CheckSuccess(that_.backend_.getTotalCompressedSize(transaction_, &s)); |
585 CheckNoEvent(); | |
491 return s; | 586 return s; |
492 } | 587 } |
493 | 588 |
494 | 589 |
495 virtual uint64_t GetTotalUncompressedSize() ORTHANC_OVERRIDE | 590 virtual uint64_t GetTotalUncompressedSize() ORTHANC_OVERRIDE |
496 { | 591 { |
497 uint64_t s; | 592 uint64_t s; |
498 CheckSuccess(that_.backend_.getTotalUncompressedSize(transaction_, &s)); | 593 CheckSuccess(that_.backend_.getTotalUncompressedSize(transaction_, &s)); |
594 CheckNoEvent(); | |
499 return s; | 595 return s; |
500 } | 596 } |
501 | 597 |
502 | 598 |
503 virtual bool IsExistingResource(int64_t internalId) ORTHANC_OVERRIDE | 599 virtual bool IsExistingResource(int64_t internalId) ORTHANC_OVERRIDE |
504 { | 600 { |
505 uint8_t b; | 601 uint8_t b; |
506 CheckSuccess(that_.backend_.isExistingResource(transaction_, &b, internalId)); | 602 CheckSuccess(that_.backend_.isExistingResource(transaction_, &b, internalId)); |
603 CheckNoEvent(); | |
507 return (b != 0); | 604 return (b != 0); |
508 } | 605 } |
509 | 606 |
510 | 607 |
511 virtual bool IsProtectedPatient(int64_t internalId) ORTHANC_OVERRIDE | 608 virtual bool IsProtectedPatient(int64_t internalId) ORTHANC_OVERRIDE |
512 { | 609 { |
513 uint8_t b; | 610 uint8_t b; |
514 CheckSuccess(that_.backend_.isProtectedPatient(transaction_, &b, internalId)); | 611 CheckSuccess(that_.backend_.isProtectedPatient(transaction_, &b, internalId)); |
612 CheckNoEvent(); | |
515 return (b != 0); | 613 return (b != 0); |
516 } | 614 } |
517 | 615 |
518 | 616 |
519 virtual void ListAvailableAttachments(std::set<FileContentType>& target, | 617 virtual void ListAvailableAttachments(std::set<FileContentType>& target, |
520 int64_t id) ORTHANC_OVERRIDE | 618 int64_t id) ORTHANC_OVERRIDE |
521 { | 619 { |
522 CheckSuccess(that_.backend_.listAvailableAttachments(transaction_, id)); | 620 CheckSuccess(that_.backend_.listAvailableAttachments(transaction_, id)); |
621 CheckNoEvent(); | |
523 | 622 |
524 uint32_t count; | 623 uint32_t count; |
525 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); | 624 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); |
526 | 625 |
527 target.clear(); | 626 target.clear(); |
538 const ServerIndexChange& change) ORTHANC_OVERRIDE | 637 const ServerIndexChange& change) ORTHANC_OVERRIDE |
539 { | 638 { |
540 CheckSuccess(that_.backend_.logChange(transaction_, static_cast<int32_t>(change.GetChangeType()), | 639 CheckSuccess(that_.backend_.logChange(transaction_, static_cast<int32_t>(change.GetChangeType()), |
541 internalId, Plugins::Convert(change.GetResourceType()), | 640 internalId, Plugins::Convert(change.GetResourceType()), |
542 change.GetDate().c_str())); | 641 change.GetDate().c_str())); |
642 CheckNoEvent(); | |
543 } | 643 } |
544 | 644 |
545 | 645 |
546 virtual void LogExportedResource(const ExportedResource& resource) ORTHANC_OVERRIDE | 646 virtual void LogExportedResource(const ExportedResource& resource) ORTHANC_OVERRIDE |
547 { | 647 { |
551 resource.GetDate().c_str(), | 651 resource.GetDate().c_str(), |
552 resource.GetPatientId().c_str(), | 652 resource.GetPatientId().c_str(), |
553 resource.GetStudyInstanceUid().c_str(), | 653 resource.GetStudyInstanceUid().c_str(), |
554 resource.GetSeriesInstanceUid().c_str(), | 654 resource.GetSeriesInstanceUid().c_str(), |
555 resource.GetSopInstanceUid().c_str())); | 655 resource.GetSopInstanceUid().c_str())); |
656 CheckNoEvent(); | |
556 } | 657 } |
557 | 658 |
558 | 659 |
559 virtual bool LookupAttachment(FileInfo& attachment, | 660 virtual bool LookupAttachment(FileInfo& attachment, |
560 int64_t id, | 661 int64_t id, |
561 FileContentType contentType) ORTHANC_OVERRIDE | 662 FileContentType contentType) ORTHANC_OVERRIDE |
562 { | 663 { |
563 CheckSuccess(that_.backend_.lookupAttachment(transaction_, id, static_cast<int32_t>(contentType))); | 664 CheckSuccess(that_.backend_.lookupAttachment(transaction_, id, static_cast<int32_t>(contentType))); |
665 CheckNoEvent(); | |
564 | 666 |
565 uint32_t count; | 667 uint32_t count; |
566 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); | 668 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); |
567 | 669 |
568 if (count == 0) | 670 if (count == 0) |
571 } | 673 } |
572 else if (count == 1) | 674 else if (count == 1) |
573 { | 675 { |
574 OrthancPluginAttachment tmp; | 676 OrthancPluginAttachment tmp; |
575 CheckSuccess(that_.backend_.readAnswerAttachment(transaction_, &tmp, 0)); | 677 CheckSuccess(that_.backend_.readAnswerAttachment(transaction_, &tmp, 0)); |
576 | 678 attachment = Convert(tmp); |
577 attachment = FileInfo(tmp.uuid, | |
578 static_cast<FileContentType>(tmp.contentType), | |
579 tmp.uncompressedSize, | |
580 tmp.uncompressedHash, | |
581 static_cast<CompressionType>(tmp.compressionType), | |
582 tmp.compressedSize, | |
583 tmp.compressedHash); | |
584 return true; | 679 return true; |
585 } | 680 } |
586 else | 681 else |
587 { | 682 { |
588 throw OrthancException(ErrorCode_DatabasePlugin); | 683 throw OrthancException(ErrorCode_DatabasePlugin); |
592 | 687 |
593 virtual bool LookupGlobalProperty(std::string& target, | 688 virtual bool LookupGlobalProperty(std::string& target, |
594 GlobalProperty property) ORTHANC_OVERRIDE | 689 GlobalProperty property) ORTHANC_OVERRIDE |
595 { | 690 { |
596 CheckSuccess(that_.backend_.lookupGlobalProperty(transaction_, static_cast<int32_t>(property))); | 691 CheckSuccess(that_.backend_.lookupGlobalProperty(transaction_, static_cast<int32_t>(property))); |
692 CheckNoEvent(); | |
597 return ReadSingleStringAnswer(target); | 693 return ReadSingleStringAnswer(target); |
598 } | 694 } |
599 | 695 |
600 | 696 |
601 virtual bool LookupMetadata(std::string& target, | 697 virtual bool LookupMetadata(std::string& target, |
602 int64_t id, | 698 int64_t id, |
603 MetadataType type) ORTHANC_OVERRIDE | 699 MetadataType type) ORTHANC_OVERRIDE |
604 { | 700 { |
605 CheckSuccess(that_.backend_.lookupMetadata(transaction_, id, static_cast<int32_t>(type))); | 701 CheckSuccess(that_.backend_.lookupMetadata(transaction_, id, static_cast<int32_t>(type))); |
702 CheckNoEvent(); | |
606 return ReadSingleStringAnswer(target); | 703 return ReadSingleStringAnswer(target); |
607 } | 704 } |
608 | 705 |
609 | 706 |
610 virtual bool LookupParent(int64_t& parentId, | 707 virtual bool LookupParent(int64_t& parentId, |
611 int64_t resourceId) ORTHANC_OVERRIDE | 708 int64_t resourceId) ORTHANC_OVERRIDE |
612 { | 709 { |
613 CheckSuccess(that_.backend_.lookupParent(transaction_, resourceId)); | 710 CheckSuccess(that_.backend_.lookupParent(transaction_, resourceId)); |
711 CheckNoEvent(); | |
614 return ReadSingleInt64Answer(parentId); | 712 return ReadSingleInt64Answer(parentId); |
615 } | 713 } |
616 | 714 |
617 | 715 |
618 virtual bool LookupResource(int64_t& id, | 716 virtual bool LookupResource(int64_t& id, |
619 ResourceType& type, | 717 ResourceType& type, |
620 const std::string& publicId) ORTHANC_OVERRIDE | 718 const std::string& publicId) ORTHANC_OVERRIDE |
621 { | 719 { |
622 CheckSuccess(that_.backend_.lookupResource(transaction_, Plugins::Convert(type), publicId.c_str())); | 720 CheckSuccess(that_.backend_.lookupResource(transaction_, Plugins::Convert(type), publicId.c_str())); |
721 CheckNoEvent(); | |
623 return ReadSingleInt64Answer(id); | 722 return ReadSingleInt64Answer(id); |
624 } | 723 } |
625 | 724 |
626 | 725 |
627 virtual bool SelectPatientToRecycle(int64_t& internalId) ORTHANC_OVERRIDE | 726 virtual bool SelectPatientToRecycle(int64_t& internalId) ORTHANC_OVERRIDE |
628 { | 727 { |
629 CheckSuccess(that_.backend_.selectPatientToRecycle(transaction_)); | 728 CheckSuccess(that_.backend_.selectPatientToRecycle(transaction_)); |
729 CheckNoEvent(); | |
630 return ReadSingleInt64Answer(internalId); | 730 return ReadSingleInt64Answer(internalId); |
631 } | 731 } |
632 | 732 |
633 | 733 |
634 virtual bool SelectPatientToRecycle(int64_t& internalId, | 734 virtual bool SelectPatientToRecycle(int64_t& internalId, |
635 int64_t patientIdToAvoid) ORTHANC_OVERRIDE | 735 int64_t patientIdToAvoid) ORTHANC_OVERRIDE |
636 { | 736 { |
637 CheckSuccess(that_.backend_.selectPatientToRecycle2(transaction_, patientIdToAvoid)); | 737 CheckSuccess(that_.backend_.selectPatientToRecycle2(transaction_, patientIdToAvoid)); |
738 CheckNoEvent(); | |
638 return ReadSingleInt64Answer(internalId); | 739 return ReadSingleInt64Answer(internalId); |
639 } | 740 } |
640 | 741 |
641 | 742 |
642 virtual void SetGlobalProperty(GlobalProperty property, | 743 virtual void SetGlobalProperty(GlobalProperty property, |
643 const std::string& value) ORTHANC_OVERRIDE | 744 const std::string& value) ORTHANC_OVERRIDE |
644 { | 745 { |
645 CheckSuccess(that_.backend_.setGlobalProperty(transaction_, static_cast<int32_t>(property), value.c_str())); | 746 CheckSuccess(that_.backend_.setGlobalProperty(transaction_, static_cast<int32_t>(property), value.c_str())); |
747 CheckNoEvent(); | |
646 } | 748 } |
647 | 749 |
648 | 750 |
649 virtual void ClearMainDicomTags(int64_t id) ORTHANC_OVERRIDE | 751 virtual void ClearMainDicomTags(int64_t id) ORTHANC_OVERRIDE |
650 { | 752 { |
651 CheckSuccess(that_.backend_.clearMainDicomTags(transaction_, id)); | 753 CheckSuccess(that_.backend_.clearMainDicomTags(transaction_, id)); |
754 CheckNoEvent(); | |
652 } | 755 } |
653 | 756 |
654 | 757 |
655 virtual void SetMetadata(int64_t id, | 758 virtual void SetMetadata(int64_t id, |
656 MetadataType type, | 759 MetadataType type, |
657 const std::string& value) ORTHANC_OVERRIDE | 760 const std::string& value) ORTHANC_OVERRIDE |
658 { | 761 { |
659 CheckSuccess(that_.backend_.setMetadata(transaction_, id, static_cast<int32_t>(type), value.c_str())); | 762 CheckSuccess(that_.backend_.setMetadata(transaction_, id, static_cast<int32_t>(type), value.c_str())); |
763 CheckNoEvent(); | |
660 } | 764 } |
661 | 765 |
662 | 766 |
663 virtual void SetProtectedPatient(int64_t internalId, | 767 virtual void SetProtectedPatient(int64_t internalId, |
664 bool isProtected) ORTHANC_OVERRIDE | 768 bool isProtected) ORTHANC_OVERRIDE |
665 { | 769 { |
666 CheckSuccess(that_.backend_.setProtectedPatient(transaction_, internalId, (isProtected ? 1 : 0))); | 770 CheckSuccess(that_.backend_.setProtectedPatient(transaction_, internalId, (isProtected ? 1 : 0))); |
771 CheckNoEvent(); | |
667 } | 772 } |
668 | 773 |
669 | 774 |
670 virtual bool IsDiskSizeAbove(uint64_t threshold) ORTHANC_OVERRIDE | 775 virtual bool IsDiskSizeAbove(uint64_t threshold) ORTHANC_OVERRIDE |
671 { | 776 { |
672 uint8_t tmp; | 777 uint8_t tmp; |
673 CheckSuccess(that_.backend_.isDiskSizeAbove(transaction_, &tmp, threshold)); | 778 CheckSuccess(that_.backend_.isDiskSizeAbove(transaction_, &tmp, threshold)); |
779 CheckNoEvent(); | |
674 return (tmp != 0); | 780 return (tmp != 0); |
675 } | 781 } |
676 | 782 |
677 | 783 |
678 virtual void ApplyLookupResources(std::list<std::string>& resourcesId, | 784 virtual void ApplyLookupResources(std::list<std::string>& resourcesId, |
694 | 800 |
695 CheckSuccess(that_.backend_.lookupResources(transaction_, lookup.size(), | 801 CheckSuccess(that_.backend_.lookupResources(transaction_, lookup.size(), |
696 (lookup.empty() ? NULL : &constraints[0]), | 802 (lookup.empty() ? NULL : &constraints[0]), |
697 Plugins::Convert(queryLevel), | 803 Plugins::Convert(queryLevel), |
698 limit, (instancesId == NULL ? 0 : 1))); | 804 limit, (instancesId == NULL ? 0 : 1))); |
805 CheckNoEvent(); | |
699 | 806 |
700 uint32_t count; | 807 uint32_t count; |
701 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); | 808 CheckSuccess(that_.backend_.readAnswersCount(transaction_, &count)); |
702 | 809 |
703 resourcesId.clear(); | 810 resourcesId.clear(); |
744 OrthancPluginCreateInstanceResult output; | 851 OrthancPluginCreateInstanceResult output; |
745 memset(&output, 0, sizeof(output)); | 852 memset(&output, 0, sizeof(output)); |
746 | 853 |
747 CheckSuccess(that_.backend_.createInstance(transaction_, &output, patient.c_str(), | 854 CheckSuccess(that_.backend_.createInstance(transaction_, &output, patient.c_str(), |
748 study.c_str(), series.c_str(), instance.c_str())); | 855 study.c_str(), series.c_str(), instance.c_str())); |
856 CheckNoEvent(); | |
749 | 857 |
750 instanceId = output.instanceId; | 858 instanceId = output.instanceId; |
751 | 859 |
752 if (output.isNewInstance) | 860 if (output.isNewInstance) |
753 { | 861 { |
814 (identifierTags.empty() ? NULL : &identifierTags[0]), | 922 (identifierTags.empty() ? NULL : &identifierTags[0]), |
815 mainDicomTags.size(), | 923 mainDicomTags.size(), |
816 (mainDicomTags.empty() ? NULL : &mainDicomTags[0]), | 924 (mainDicomTags.empty() ? NULL : &mainDicomTags[0]), |
817 metadata.size(), | 925 metadata.size(), |
818 (metadata.empty() ? NULL : &metadata[0]))); | 926 (metadata.empty() ? NULL : &metadata[0]))); |
927 CheckNoEvent(); | |
819 } | 928 } |
820 | 929 |
821 | 930 |
822 virtual void GetChildrenMetadata(std::list<std::string>& target, | 931 virtual void GetChildrenMetadata(std::list<std::string>& target, |
823 int64_t resourceId, | 932 int64_t resourceId, |
824 MetadataType metadata) ORTHANC_OVERRIDE | 933 MetadataType metadata) ORTHANC_OVERRIDE |
825 { | 934 { |
826 CheckSuccess(that_.backend_.getChildrenMetadata(transaction_, resourceId, static_cast<int32_t>(metadata))); | 935 CheckSuccess(that_.backend_.getChildrenMetadata(transaction_, resourceId, static_cast<int32_t>(metadata))); |
936 CheckNoEvent(); | |
827 ReadStringAnswers(target); | 937 ReadStringAnswers(target); |
828 } | 938 } |
829 | 939 |
830 | 940 |
831 virtual int64_t GetLastChangeIndex() ORTHANC_OVERRIDE | 941 virtual int64_t GetLastChangeIndex() ORTHANC_OVERRIDE |
832 { | 942 { |
833 int64_t tmp; | 943 int64_t tmp; |
834 CheckSuccess(that_.backend_.getLastChangeIndex(transaction_, &tmp)); | 944 CheckSuccess(that_.backend_.getLastChangeIndex(transaction_, &tmp)); |
945 CheckNoEvent(); | |
835 return tmp; | 946 return tmp; |
836 } | 947 } |
837 | 948 |
838 | 949 |
839 virtual bool LookupResourceAndParent(int64_t& id, | 950 virtual bool LookupResourceAndParent(int64_t& id, |
842 const std::string& publicId) ORTHANC_OVERRIDE | 953 const std::string& publicId) ORTHANC_OVERRIDE |
843 { | 954 { |
844 uint8_t isExisting; | 955 uint8_t isExisting; |
845 OrthancPluginResourceType tmpType; | 956 OrthancPluginResourceType tmpType; |
846 CheckSuccess(that_.backend_.lookupResourceAndParent(transaction_, &isExisting, &id, &tmpType, publicId.c_str())); | 957 CheckSuccess(that_.backend_.lookupResourceAndParent(transaction_, &isExisting, &id, &tmpType, publicId.c_str())); |
958 CheckNoEvent(); | |
847 | 959 |
848 if (isExisting) | 960 if (isExisting) |
849 { | 961 { |
850 type = Plugins::Convert(tmpType); | 962 type = Plugins::Convert(tmpType); |
851 | 963 |
965 IDatabaseListener& listener) | 1077 IDatabaseListener& listener) |
966 { | 1078 { |
967 switch (type) | 1079 switch (type) |
968 { | 1080 { |
969 case TransactionType_ReadOnly: | 1081 case TransactionType_ReadOnly: |
970 return new Transaction(*this, listener, _OrthancPluginDatabaseTransactionType_ReadOnly); | 1082 return new Transaction(*this, listener, OrthancPluginDatabaseTransactionType_ReadOnly); |
971 | 1083 |
972 case TransactionType_ReadWrite: | 1084 case TransactionType_ReadWrite: |
973 return new Transaction(*this, listener, _OrthancPluginDatabaseTransactionType_ReadWrite); | 1085 return new Transaction(*this, listener, OrthancPluginDatabaseTransactionType_ReadWrite); |
974 | 1086 |
975 default: | 1087 default: |
976 throw OrthancException(ErrorCode_InternalError); | 1088 throw OrthancException(ErrorCode_InternalError); |
977 } | 1089 } |
978 } | 1090 } |
991 { | 1103 { |
992 VoidDatabaseListener listener; | 1104 VoidDatabaseListener listener; |
993 | 1105 |
994 if (backend_.upgradeDatabase != NULL) | 1106 if (backend_.upgradeDatabase != NULL) |
995 { | 1107 { |
996 Transaction transaction(*this, listener, _OrthancPluginDatabaseTransactionType_ReadWrite); | 1108 Transaction transaction(*this, listener, OrthancPluginDatabaseTransactionType_ReadWrite); |
997 | 1109 |
998 OrthancPluginErrorCode code = backend_.upgradeDatabase( | 1110 OrthancPluginErrorCode code = backend_.upgradeDatabase( |
999 database_, reinterpret_cast<OrthancPluginStorageArea*>(&storageArea), | 1111 database_, reinterpret_cast<OrthancPluginStorageArea*>(&storageArea), |
1000 static_cast<uint32_t>(targetVersion)); | 1112 static_cast<uint32_t>(targetVersion)); |
1001 | 1113 |