Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPluginDatabase.cpp @ 1629:bad4772b605c
OrthancPluginErrorCode in database plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Sep 2015 17:45:59 +0200 |
parents | c17b1142caab |
children | ffd23c0104af |
comparison
equal
deleted
inserted
replaced
1628:77c4cc4def0f | 1629:bad4772b605c |
---|---|
33 #include "../../OrthancServer/PrecompiledHeadersServer.h" | 33 #include "../../OrthancServer/PrecompiledHeadersServer.h" |
34 #include "OrthancPluginDatabase.h" | 34 #include "OrthancPluginDatabase.h" |
35 | 35 |
36 #include "../../Core/OrthancException.h" | 36 #include "../../Core/OrthancException.h" |
37 #include "../../Core/Logging.h" | 37 #include "../../Core/Logging.h" |
38 #include "PluginsEnumerations.h" | |
38 | 39 |
39 #include <cassert> | 40 #include <cassert> |
40 | 41 |
41 namespace Orthanc | 42 namespace Orthanc |
42 { | 43 { |
222 tmp.uncompressedHash = attachment.GetUncompressedMD5().c_str(); | 223 tmp.uncompressedHash = attachment.GetUncompressedMD5().c_str(); |
223 tmp.compressionType = static_cast<int32_t>(attachment.GetCompressionType()); | 224 tmp.compressionType = static_cast<int32_t>(attachment.GetCompressionType()); |
224 tmp.compressedSize = attachment.GetCompressedSize(); | 225 tmp.compressedSize = attachment.GetCompressedSize(); |
225 tmp.compressedHash = attachment.GetCompressedMD5().c_str(); | 226 tmp.compressedHash = attachment.GetCompressedMD5().c_str(); |
226 | 227 |
227 if (backend_.addAttachment(payload_, id, &tmp) != 0) | 228 OrthancPluginErrorCode error = backend_.addAttachment(payload_, id, &tmp); |
228 { | 229 |
229 throw OrthancException(ErrorCode_Plugin); | 230 if (error != OrthancPluginErrorCode_Success) |
231 { | |
232 throw OrthancException(Plugins::Convert(error)); | |
230 } | 233 } |
231 } | 234 } |
232 | 235 |
233 | 236 |
234 void OrthancPluginDatabase::AttachChild(int64_t parent, | 237 void OrthancPluginDatabase::AttachChild(int64_t parent, |
235 int64_t child) | 238 int64_t child) |
236 { | 239 { |
237 if (backend_.attachChild(payload_, parent, child) != 0) | 240 OrthancPluginErrorCode error = backend_.attachChild(payload_, parent, child); |
238 { | 241 |
239 throw OrthancException(ErrorCode_Plugin); | 242 if (error != OrthancPluginErrorCode_Success) |
243 { | |
244 throw OrthancException(Plugins::Convert(error)); | |
240 } | 245 } |
241 } | 246 } |
242 | 247 |
243 | 248 |
244 void OrthancPluginDatabase::ClearChanges() | 249 void OrthancPluginDatabase::ClearChanges() |
245 { | 250 { |
246 if (backend_.clearChanges(payload_) != 0) | 251 OrthancPluginErrorCode error = backend_.clearChanges(payload_); |
247 { | 252 |
248 throw OrthancException(ErrorCode_Plugin); | 253 if (error != OrthancPluginErrorCode_Success) |
254 { | |
255 throw OrthancException(Plugins::Convert(error)); | |
249 } | 256 } |
250 } | 257 } |
251 | 258 |
252 | 259 |
253 void OrthancPluginDatabase::ClearExportedResources() | 260 void OrthancPluginDatabase::ClearExportedResources() |
254 { | 261 { |
255 if (backend_.clearExportedResources(payload_) != 0) | 262 OrthancPluginErrorCode error = backend_.clearExportedResources(payload_); |
256 { | 263 |
257 throw OrthancException(ErrorCode_Plugin); | 264 if (error != OrthancPluginErrorCode_Success) |
265 { | |
266 throw OrthancException(Plugins::Convert(error)); | |
258 } | 267 } |
259 } | 268 } |
260 | 269 |
261 | 270 |
262 int64_t OrthancPluginDatabase::CreateResource(const std::string& publicId, | 271 int64_t OrthancPluginDatabase::CreateResource(const std::string& publicId, |
263 ResourceType type) | 272 ResourceType type) |
264 { | 273 { |
265 int64_t id; | 274 int64_t id; |
266 | 275 |
267 if (backend_.createResource(&id, payload_, publicId.c_str(), Convert(type)) != 0) | 276 OrthancPluginErrorCode error = backend_.createResource(&id, payload_, publicId.c_str(), Convert(type)); |
268 { | 277 |
269 throw OrthancException(ErrorCode_Plugin); | 278 if (error != OrthancPluginErrorCode_Success) |
279 { | |
280 throw OrthancException(Plugins::Convert(error)); | |
270 } | 281 } |
271 | 282 |
272 return id; | 283 return id; |
273 } | 284 } |
274 | 285 |
275 | 286 |
276 void OrthancPluginDatabase::DeleteAttachment(int64_t id, | 287 void OrthancPluginDatabase::DeleteAttachment(int64_t id, |
277 FileContentType attachment) | 288 FileContentType attachment) |
278 { | 289 { |
279 if (backend_.deleteAttachment(payload_, id, static_cast<int32_t>(attachment)) != 0) | 290 OrthancPluginErrorCode error = backend_.deleteAttachment(payload_, id, static_cast<int32_t>(attachment)); |
280 { | 291 |
281 throw OrthancException(ErrorCode_Plugin); | 292 if (error != OrthancPluginErrorCode_Success) |
293 { | |
294 throw OrthancException(Plugins::Convert(error)); | |
282 } | 295 } |
283 } | 296 } |
284 | 297 |
285 | 298 |
286 void OrthancPluginDatabase::DeleteMetadata(int64_t id, | 299 void OrthancPluginDatabase::DeleteMetadata(int64_t id, |
287 MetadataType type) | 300 MetadataType type) |
288 { | 301 { |
289 if (backend_.deleteMetadata(payload_, id, static_cast<int32_t>(type)) != 0) | 302 OrthancPluginErrorCode error = backend_.deleteMetadata(payload_, id, static_cast<int32_t>(type)); |
290 { | 303 |
291 throw OrthancException(ErrorCode_Plugin); | 304 if (error != OrthancPluginErrorCode_Success) |
305 { | |
306 throw OrthancException(Plugins::Convert(error)); | |
292 } | 307 } |
293 } | 308 } |
294 | 309 |
295 | 310 |
296 void OrthancPluginDatabase::DeleteResource(int64_t id) | 311 void OrthancPluginDatabase::DeleteResource(int64_t id) |
297 { | 312 { |
298 if (backend_.deleteResource(payload_, id) != 0) | 313 OrthancPluginErrorCode error = backend_.deleteResource(payload_, id); |
299 { | 314 |
300 throw OrthancException(ErrorCode_Plugin); | 315 if (error != OrthancPluginErrorCode_Success) |
316 { | |
317 throw OrthancException(Plugins::Convert(error)); | |
301 } | 318 } |
302 } | 319 } |
303 | 320 |
304 | 321 |
305 void OrthancPluginDatabase::GetAllMetadata(std::map<MetadataType, std::string>& target, | 322 void OrthancPluginDatabase::GetAllMetadata(std::map<MetadataType, std::string>& target, |
327 void OrthancPluginDatabase::GetAllPublicIds(std::list<std::string>& target, | 344 void OrthancPluginDatabase::GetAllPublicIds(std::list<std::string>& target, |
328 ResourceType resourceType) | 345 ResourceType resourceType) |
329 { | 346 { |
330 ResetAnswers(); | 347 ResetAnswers(); |
331 | 348 |
332 if (backend_.getAllPublicIds(GetContext(), payload_, Convert(resourceType)) != 0) | 349 OrthancPluginErrorCode error = backend_.getAllPublicIds(GetContext(), payload_, Convert(resourceType)); |
333 { | 350 |
334 throw OrthancException(ErrorCode_Plugin); | 351 if (error != OrthancPluginErrorCode_Success) |
352 { | |
353 throw OrthancException(Plugins::Convert(error)); | |
335 } | 354 } |
336 | 355 |
337 ForwardAnswers(target); | 356 ForwardAnswers(target); |
338 } | 357 } |
339 | 358 |
346 if (extensions_.getAllPublicIdsWithLimit != NULL) | 365 if (extensions_.getAllPublicIdsWithLimit != NULL) |
347 { | 366 { |
348 // This extension is available since Orthanc 0.9.4 | 367 // This extension is available since Orthanc 0.9.4 |
349 ResetAnswers(); | 368 ResetAnswers(); |
350 | 369 |
351 if (extensions_.getAllPublicIdsWithLimit(GetContext(), payload_, Convert(resourceType), since, limit) != 0) | 370 OrthancPluginErrorCode error = extensions_.getAllPublicIdsWithLimit |
352 { | 371 (GetContext(), payload_, Convert(resourceType), since, limit); |
353 throw OrthancException(ErrorCode_Plugin); | 372 |
373 if (error != OrthancPluginErrorCode_Success) | |
374 { | |
375 throw OrthancException(Plugins::Convert(error)); | |
354 } | 376 } |
355 | 377 |
356 ForwardAnswers(target); | 378 ForwardAnswers(target); |
357 } | 379 } |
358 else | 380 else |
397 ResetAnswers(); | 419 ResetAnswers(); |
398 answerChanges_ = ⌖ | 420 answerChanges_ = ⌖ |
399 answerDone_ = &done; | 421 answerDone_ = &done; |
400 done = false; | 422 done = false; |
401 | 423 |
402 if (backend_.getChanges(GetContext(), payload_, since, maxResults) != 0) | 424 OrthancPluginErrorCode error = backend_.getChanges(GetContext(), payload_, since, maxResults); |
403 { | 425 |
404 throw OrthancException(ErrorCode_Plugin); | 426 if (error != OrthancPluginErrorCode_Success) |
427 { | |
428 throw OrthancException(Plugins::Convert(error)); | |
405 } | 429 } |
406 } | 430 } |
407 | 431 |
408 | 432 |
409 void OrthancPluginDatabase::GetChildrenInternalId(std::list<int64_t>& target, | 433 void OrthancPluginDatabase::GetChildrenInternalId(std::list<int64_t>& target, |
410 int64_t id) | 434 int64_t id) |
411 { | 435 { |
412 ResetAnswers(); | 436 ResetAnswers(); |
413 | 437 |
414 if (backend_.getChildrenInternalId(GetContext(), payload_, id) != 0) | 438 OrthancPluginErrorCode error = backend_.getChildrenInternalId(GetContext(), payload_, id); |
415 { | 439 |
416 throw OrthancException(ErrorCode_Plugin); | 440 if (error != OrthancPluginErrorCode_Success) |
441 { | |
442 throw OrthancException(Plugins::Convert(error)); | |
417 } | 443 } |
418 | 444 |
419 ForwardAnswers(target); | 445 ForwardAnswers(target); |
420 } | 446 } |
421 | 447 |
423 void OrthancPluginDatabase::GetChildrenPublicId(std::list<std::string>& target, | 449 void OrthancPluginDatabase::GetChildrenPublicId(std::list<std::string>& target, |
424 int64_t id) | 450 int64_t id) |
425 { | 451 { |
426 ResetAnswers(); | 452 ResetAnswers(); |
427 | 453 |
428 if (backend_.getChildrenPublicId(GetContext(), payload_, id) != 0) | 454 OrthancPluginErrorCode error = backend_.getChildrenPublicId(GetContext(), payload_, id); |
429 { | 455 |
430 throw OrthancException(ErrorCode_Plugin); | 456 if (error != OrthancPluginErrorCode_Success) |
457 { | |
458 throw OrthancException(Plugins::Convert(error)); | |
431 } | 459 } |
432 | 460 |
433 ForwardAnswers(target); | 461 ForwardAnswers(target); |
434 } | 462 } |
435 | 463 |
442 ResetAnswers(); | 470 ResetAnswers(); |
443 answerExportedResources_ = ⌖ | 471 answerExportedResources_ = ⌖ |
444 answerDone_ = &done; | 472 answerDone_ = &done; |
445 done = false; | 473 done = false; |
446 | 474 |
447 if (backend_.getExportedResources(GetContext(), payload_, since, maxResults) != 0) | 475 OrthancPluginErrorCode error = backend_.getExportedResources(GetContext(), payload_, since, maxResults); |
448 { | 476 |
449 throw OrthancException(ErrorCode_Plugin); | 477 if (error != OrthancPluginErrorCode_Success) |
478 { | |
479 throw OrthancException(Plugins::Convert(error)); | |
450 } | 480 } |
451 } | 481 } |
452 | 482 |
453 | 483 |
454 void OrthancPluginDatabase::GetLastChange(std::list<ServerIndexChange>& target /*out*/) | 484 void OrthancPluginDatabase::GetLastChange(std::list<ServerIndexChange>& target /*out*/) |
457 | 487 |
458 ResetAnswers(); | 488 ResetAnswers(); |
459 answerChanges_ = ⌖ | 489 answerChanges_ = ⌖ |
460 answerDone_ = &ignored; | 490 answerDone_ = &ignored; |
461 | 491 |
462 if (backend_.getLastChange(GetContext(), payload_) != 0) | 492 OrthancPluginErrorCode error = backend_.getLastChange(GetContext(), payload_); |
463 { | 493 |
464 throw OrthancException(ErrorCode_Plugin); | 494 if (error != OrthancPluginErrorCode_Success) |
495 { | |
496 throw OrthancException(Plugins::Convert(error)); | |
465 } | 497 } |
466 } | 498 } |
467 | 499 |
468 | 500 |
469 void OrthancPluginDatabase::GetLastExportedResource(std::list<ExportedResource>& target /*out*/) | 501 void OrthancPluginDatabase::GetLastExportedResource(std::list<ExportedResource>& target /*out*/) |
472 | 504 |
473 ResetAnswers(); | 505 ResetAnswers(); |
474 answerExportedResources_ = ⌖ | 506 answerExportedResources_ = ⌖ |
475 answerDone_ = &ignored; | 507 answerDone_ = &ignored; |
476 | 508 |
477 if (backend_.getLastExportedResource(GetContext(), payload_) != 0) | 509 OrthancPluginErrorCode error = backend_.getLastExportedResource(GetContext(), payload_); |
478 { | 510 |
479 throw OrthancException(ErrorCode_Plugin); | 511 if (error != OrthancPluginErrorCode_Success) |
512 { | |
513 throw OrthancException(Plugins::Convert(error)); | |
480 } | 514 } |
481 } | 515 } |
482 | 516 |
483 | 517 |
484 void OrthancPluginDatabase::GetMainDicomTags(DicomMap& map, | 518 void OrthancPluginDatabase::GetMainDicomTags(DicomMap& map, |
485 int64_t id) | 519 int64_t id) |
486 { | 520 { |
487 ResetAnswers(); | 521 ResetAnswers(); |
488 answerDicomMap_ = ↦ | 522 answerDicomMap_ = ↦ |
489 | 523 |
490 if (backend_.getMainDicomTags(GetContext(), payload_, id) != 0) | 524 OrthancPluginErrorCode error = backend_.getMainDicomTags(GetContext(), payload_, id); |
525 | |
526 if (error != OrthancPluginErrorCode_Success) | |
527 { | |
528 throw OrthancException(Plugins::Convert(error)); | |
529 } | |
530 } | |
531 | |
532 | |
533 std::string OrthancPluginDatabase::GetPublicId(int64_t resourceId) | |
534 { | |
535 ResetAnswers(); | |
536 std::string s; | |
537 | |
538 OrthancPluginErrorCode error = backend_.getPublicId(GetContext(), payload_, resourceId); | |
539 | |
540 if (error != OrthancPluginErrorCode_Success) | |
541 { | |
542 throw OrthancException(Plugins::Convert(error)); | |
543 } | |
544 | |
545 if (!ForwardSingleAnswer(s)) | |
491 { | 546 { |
492 throw OrthancException(ErrorCode_Plugin); | 547 throw OrthancException(ErrorCode_Plugin); |
493 } | 548 } |
494 } | |
495 | |
496 | |
497 std::string OrthancPluginDatabase::GetPublicId(int64_t resourceId) | |
498 { | |
499 ResetAnswers(); | |
500 std::string s; | |
501 | |
502 if (backend_.getPublicId(GetContext(), payload_, resourceId) != 0 || | |
503 !ForwardSingleAnswer(s)) | |
504 { | |
505 throw OrthancException(ErrorCode_Plugin); | |
506 } | |
507 | 549 |
508 return s; | 550 return s; |
509 } | 551 } |
510 | 552 |
511 | 553 |
512 uint64_t OrthancPluginDatabase::GetResourceCount(ResourceType resourceType) | 554 uint64_t OrthancPluginDatabase::GetResourceCount(ResourceType resourceType) |
513 { | 555 { |
514 uint64_t count; | 556 uint64_t count; |
515 | 557 |
516 if (backend_.getResourceCount(&count, payload_, Convert(resourceType)) != 0) | 558 OrthancPluginErrorCode error = backend_.getResourceCount(&count, payload_, Convert(resourceType)); |
517 { | 559 |
518 throw OrthancException(ErrorCode_Plugin); | 560 if (error != OrthancPluginErrorCode_Success) |
561 { | |
562 throw OrthancException(Plugins::Convert(error)); | |
519 } | 563 } |
520 | 564 |
521 return count; | 565 return count; |
522 } | 566 } |
523 | 567 |
524 | 568 |
525 ResourceType OrthancPluginDatabase::GetResourceType(int64_t resourceId) | 569 ResourceType OrthancPluginDatabase::GetResourceType(int64_t resourceId) |
526 { | 570 { |
527 OrthancPluginResourceType type; | 571 OrthancPluginResourceType type; |
528 | 572 |
529 if (backend_.getResourceType(&type, payload_, resourceId) != 0) | 573 OrthancPluginErrorCode error = backend_.getResourceType(&type, payload_, resourceId); |
530 { | 574 |
531 throw OrthancException(ErrorCode_Plugin); | 575 if (error != OrthancPluginErrorCode_Success) |
576 { | |
577 throw OrthancException(Plugins::Convert(error)); | |
532 } | 578 } |
533 | 579 |
534 return Convert(type); | 580 return Convert(type); |
535 } | 581 } |
536 | 582 |
537 | 583 |
538 uint64_t OrthancPluginDatabase::GetTotalCompressedSize() | 584 uint64_t OrthancPluginDatabase::GetTotalCompressedSize() |
539 { | 585 { |
540 uint64_t size; | 586 uint64_t size; |
541 | 587 |
542 if (backend_.getTotalCompressedSize(&size, payload_) != 0) | 588 OrthancPluginErrorCode error = backend_.getTotalCompressedSize(&size, payload_); |
543 { | 589 |
544 throw OrthancException(ErrorCode_Plugin); | 590 if (error != OrthancPluginErrorCode_Success) |
591 { | |
592 throw OrthancException(Plugins::Convert(error)); | |
545 } | 593 } |
546 | 594 |
547 return size; | 595 return size; |
548 } | 596 } |
549 | 597 |
550 | 598 |
551 uint64_t OrthancPluginDatabase::GetTotalUncompressedSize() | 599 uint64_t OrthancPluginDatabase::GetTotalUncompressedSize() |
552 { | 600 { |
553 uint64_t size; | 601 uint64_t size; |
554 | 602 |
555 if (backend_.getTotalUncompressedSize(&size, payload_) != 0) | 603 OrthancPluginErrorCode error = backend_.getTotalUncompressedSize(&size, payload_); |
556 { | 604 |
557 throw OrthancException(ErrorCode_Plugin); | 605 if (error != OrthancPluginErrorCode_Success) |
606 { | |
607 throw OrthancException(Plugins::Convert(error)); | |
558 } | 608 } |
559 | 609 |
560 return size; | 610 return size; |
561 } | 611 } |
562 | 612 |
563 | 613 |
564 bool OrthancPluginDatabase::IsExistingResource(int64_t internalId) | 614 bool OrthancPluginDatabase::IsExistingResource(int64_t internalId) |
565 { | 615 { |
566 int32_t existing; | 616 int32_t existing; |
567 | 617 |
568 if (backend_.isExistingResource(&existing, payload_, internalId) != 0) | 618 OrthancPluginErrorCode error = backend_.isExistingResource(&existing, payload_, internalId); |
569 { | 619 |
570 throw OrthancException(ErrorCode_Plugin); | 620 if (error != OrthancPluginErrorCode_Success) |
621 { | |
622 throw OrthancException(Plugins::Convert(error)); | |
571 } | 623 } |
572 | 624 |
573 return (existing != 0); | 625 return (existing != 0); |
574 } | 626 } |
575 | 627 |
576 | 628 |
577 bool OrthancPluginDatabase::IsProtectedPatient(int64_t internalId) | 629 bool OrthancPluginDatabase::IsProtectedPatient(int64_t internalId) |
578 { | 630 { |
579 int32_t isProtected; | 631 int32_t isProtected; |
580 | 632 |
581 if (backend_.isProtectedPatient(&isProtected, payload_, internalId) != 0) | 633 OrthancPluginErrorCode error = backend_.isProtectedPatient(&isProtected, payload_, internalId); |
582 { | 634 |
583 throw OrthancException(ErrorCode_Plugin); | 635 if (error != OrthancPluginErrorCode_Success) |
636 { | |
637 throw OrthancException(Plugins::Convert(error)); | |
584 } | 638 } |
585 | 639 |
586 return (isProtected != 0); | 640 return (isProtected != 0); |
587 } | 641 } |
588 | 642 |
590 void OrthancPluginDatabase::ListAvailableMetadata(std::list<MetadataType>& target, | 644 void OrthancPluginDatabase::ListAvailableMetadata(std::list<MetadataType>& target, |
591 int64_t id) | 645 int64_t id) |
592 { | 646 { |
593 ResetAnswers(); | 647 ResetAnswers(); |
594 | 648 |
595 if (backend_.listAvailableMetadata(GetContext(), payload_, id) != 0) | 649 OrthancPluginErrorCode error = backend_.listAvailableMetadata(GetContext(), payload_, id); |
596 { | 650 |
597 throw OrthancException(ErrorCode_Plugin); | 651 if (error != OrthancPluginErrorCode_Success) |
652 { | |
653 throw OrthancException(Plugins::Convert(error)); | |
598 } | 654 } |
599 | 655 |
600 if (type_ != _OrthancPluginDatabaseAnswerType_None && | 656 if (type_ != _OrthancPluginDatabaseAnswerType_None && |
601 type_ != _OrthancPluginDatabaseAnswerType_Int32) | 657 type_ != _OrthancPluginDatabaseAnswerType_Int32) |
602 { | 658 { |
619 void OrthancPluginDatabase::ListAvailableAttachments(std::list<FileContentType>& target, | 675 void OrthancPluginDatabase::ListAvailableAttachments(std::list<FileContentType>& target, |
620 int64_t id) | 676 int64_t id) |
621 { | 677 { |
622 ResetAnswers(); | 678 ResetAnswers(); |
623 | 679 |
624 if (backend_.listAvailableAttachments(GetContext(), payload_, id) != 0) | 680 OrthancPluginErrorCode error = backend_.listAvailableAttachments(GetContext(), payload_, id); |
625 { | 681 |
626 throw OrthancException(ErrorCode_Plugin); | 682 if (error != OrthancPluginErrorCode_Success) |
683 { | |
684 throw OrthancException(Plugins::Convert(error)); | |
627 } | 685 } |
628 | 686 |
629 if (type_ != _OrthancPluginDatabaseAnswerType_None && | 687 if (type_ != _OrthancPluginDatabaseAnswerType_None && |
630 type_ != _OrthancPluginDatabaseAnswerType_Int32) | 688 type_ != _OrthancPluginDatabaseAnswerType_Int32) |
631 { | 689 { |
653 tmp.changeType = static_cast<int32_t>(change.GetChangeType()); | 711 tmp.changeType = static_cast<int32_t>(change.GetChangeType()); |
654 tmp.resourceType = Convert(change.GetResourceType()); | 712 tmp.resourceType = Convert(change.GetResourceType()); |
655 tmp.publicId = change.GetPublicId().c_str(); | 713 tmp.publicId = change.GetPublicId().c_str(); |
656 tmp.date = change.GetDate().c_str(); | 714 tmp.date = change.GetDate().c_str(); |
657 | 715 |
658 if (backend_.logChange(payload_, &tmp) != 0) | 716 OrthancPluginErrorCode error = backend_.logChange(payload_, &tmp); |
659 { | 717 |
660 throw OrthancException(ErrorCode_Plugin); | 718 if (error != OrthancPluginErrorCode_Success) |
719 { | |
720 throw OrthancException(Plugins::Convert(error)); | |
661 } | 721 } |
662 } | 722 } |
663 | 723 |
664 | 724 |
665 void OrthancPluginDatabase::LogExportedResource(const ExportedResource& resource) | 725 void OrthancPluginDatabase::LogExportedResource(const ExportedResource& resource) |
673 tmp.patientId = resource.GetPatientId().c_str(); | 733 tmp.patientId = resource.GetPatientId().c_str(); |
674 tmp.studyInstanceUid = resource.GetStudyInstanceUid().c_str(); | 734 tmp.studyInstanceUid = resource.GetStudyInstanceUid().c_str(); |
675 tmp.seriesInstanceUid = resource.GetSeriesInstanceUid().c_str(); | 735 tmp.seriesInstanceUid = resource.GetSeriesInstanceUid().c_str(); |
676 tmp.sopInstanceUid = resource.GetSopInstanceUid().c_str(); | 736 tmp.sopInstanceUid = resource.GetSopInstanceUid().c_str(); |
677 | 737 |
678 if (backend_.logExportedResource(payload_, &tmp) != 0) | 738 OrthancPluginErrorCode error = backend_.logExportedResource(payload_, &tmp); |
679 { | 739 |
680 throw OrthancException(ErrorCode_Plugin); | 740 if (error != OrthancPluginErrorCode_Success) |
741 { | |
742 throw OrthancException(Plugins::Convert(error)); | |
681 } | 743 } |
682 } | 744 } |
683 | 745 |
684 | 746 |
685 bool OrthancPluginDatabase::LookupAttachment(FileInfo& attachment, | 747 bool OrthancPluginDatabase::LookupAttachment(FileInfo& attachment, |
686 int64_t id, | 748 int64_t id, |
687 FileContentType contentType) | 749 FileContentType contentType) |
688 { | 750 { |
689 ResetAnswers(); | 751 ResetAnswers(); |
690 | 752 |
691 if (backend_.lookupAttachment(GetContext(), payload_, id, static_cast<int32_t>(contentType))) | 753 OrthancPluginErrorCode error = backend_.lookupAttachment |
692 { | 754 (GetContext(), payload_, id, static_cast<int32_t>(contentType)); |
693 throw OrthancException(ErrorCode_Plugin); | 755 |
756 if (error != OrthancPluginErrorCode_Success) | |
757 { | |
758 throw OrthancException(Plugins::Convert(error)); | |
694 } | 759 } |
695 | 760 |
696 if (type_ == _OrthancPluginDatabaseAnswerType_None) | 761 if (type_ == _OrthancPluginDatabaseAnswerType_None) |
697 { | 762 { |
698 return false; | 763 return false; |
713 bool OrthancPluginDatabase::LookupGlobalProperty(std::string& target, | 778 bool OrthancPluginDatabase::LookupGlobalProperty(std::string& target, |
714 GlobalProperty property) | 779 GlobalProperty property) |
715 { | 780 { |
716 ResetAnswers(); | 781 ResetAnswers(); |
717 | 782 |
718 if (backend_.lookupGlobalProperty(GetContext(), payload_, | 783 OrthancPluginErrorCode error = backend_.lookupGlobalProperty |
719 static_cast<int32_t>(property))) | 784 (GetContext(), payload_, static_cast<int32_t>(property)); |
720 { | 785 |
721 throw OrthancException(ErrorCode_Plugin); | 786 if (error != OrthancPluginErrorCode_Success) |
787 { | |
788 throw OrthancException(Plugins::Convert(error)); | |
722 } | 789 } |
723 | 790 |
724 return ForwardSingleAnswer(target); | 791 return ForwardSingleAnswer(target); |
725 } | 792 } |
726 | 793 |
734 OrthancPluginDicomTag tmp; | 801 OrthancPluginDicomTag tmp; |
735 tmp.group = tag.GetGroup(); | 802 tmp.group = tag.GetGroup(); |
736 tmp.element = tag.GetElement(); | 803 tmp.element = tag.GetElement(); |
737 tmp.value = value.c_str(); | 804 tmp.value = value.c_str(); |
738 | 805 |
739 if (backend_.lookupIdentifier(GetContext(), payload_, &tmp) != 0) | 806 OrthancPluginErrorCode error = backend_.lookupIdentifier(GetContext(), payload_, &tmp); |
740 { | 807 |
741 throw OrthancException(ErrorCode_Plugin); | 808 if (error != OrthancPluginErrorCode_Success) |
809 { | |
810 throw OrthancException(Plugins::Convert(error)); | |
742 } | 811 } |
743 | 812 |
744 ForwardAnswers(target); | 813 ForwardAnswers(target); |
745 } | 814 } |
746 | 815 |
748 void OrthancPluginDatabase::LookupIdentifier(std::list<int64_t>& target, | 817 void OrthancPluginDatabase::LookupIdentifier(std::list<int64_t>& target, |
749 const std::string& value) | 818 const std::string& value) |
750 { | 819 { |
751 ResetAnswers(); | 820 ResetAnswers(); |
752 | 821 |
753 if (backend_.lookupIdentifier2(GetContext(), payload_, value.c_str()) != 0) | 822 OrthancPluginErrorCode error = backend_.lookupIdentifier2(GetContext(), payload_, value.c_str()); |
754 { | 823 |
755 throw OrthancException(ErrorCode_Plugin); | 824 if (error != OrthancPluginErrorCode_Success) |
825 { | |
826 throw OrthancException(Plugins::Convert(error)); | |
756 } | 827 } |
757 | 828 |
758 ForwardAnswers(target); | 829 ForwardAnswers(target); |
759 } | 830 } |
760 | 831 |
763 int64_t id, | 834 int64_t id, |
764 MetadataType type) | 835 MetadataType type) |
765 { | 836 { |
766 ResetAnswers(); | 837 ResetAnswers(); |
767 | 838 |
768 if (backend_.lookupMetadata(GetContext(), payload_, id, static_cast<int32_t>(type))) | 839 OrthancPluginErrorCode error = backend_.lookupMetadata(GetContext(), payload_, id, static_cast<int32_t>(type)); |
769 { | 840 |
770 throw OrthancException(ErrorCode_Plugin); | 841 if (error != OrthancPluginErrorCode_Success) |
842 { | |
843 throw OrthancException(Plugins::Convert(error)); | |
771 } | 844 } |
772 | 845 |
773 return ForwardSingleAnswer(target); | 846 return ForwardSingleAnswer(target); |
774 } | 847 } |
775 | 848 |
777 bool OrthancPluginDatabase::LookupParent(int64_t& parentId, | 850 bool OrthancPluginDatabase::LookupParent(int64_t& parentId, |
778 int64_t resourceId) | 851 int64_t resourceId) |
779 { | 852 { |
780 ResetAnswers(); | 853 ResetAnswers(); |
781 | 854 |
782 if (backend_.lookupParent(GetContext(), payload_, resourceId)) | 855 OrthancPluginErrorCode error = backend_.lookupParent(GetContext(), payload_, resourceId); |
783 { | 856 |
784 throw OrthancException(ErrorCode_Plugin); | 857 if (error != OrthancPluginErrorCode_Success) |
858 { | |
859 throw OrthancException(Plugins::Convert(error)); | |
785 } | 860 } |
786 | 861 |
787 return ForwardSingleAnswer(parentId); | 862 return ForwardSingleAnswer(parentId); |
788 } | 863 } |
789 | 864 |
792 ResourceType& type, | 867 ResourceType& type, |
793 const std::string& publicId) | 868 const std::string& publicId) |
794 { | 869 { |
795 ResetAnswers(); | 870 ResetAnswers(); |
796 | 871 |
797 if (backend_.lookupResource(GetContext(), payload_, publicId.c_str())) | 872 OrthancPluginErrorCode error = backend_.lookupResource(GetContext(), payload_, publicId.c_str()); |
798 { | 873 |
799 throw OrthancException(ErrorCode_Plugin); | 874 if (error != OrthancPluginErrorCode_Success) |
875 { | |
876 throw OrthancException(Plugins::Convert(error)); | |
800 } | 877 } |
801 | 878 |
802 if (type_ == _OrthancPluginDatabaseAnswerType_None) | 879 if (type_ == _OrthancPluginDatabaseAnswerType_None) |
803 { | 880 { |
804 return false; | 881 return false; |
819 | 896 |
820 bool OrthancPluginDatabase::SelectPatientToRecycle(int64_t& internalId) | 897 bool OrthancPluginDatabase::SelectPatientToRecycle(int64_t& internalId) |
821 { | 898 { |
822 ResetAnswers(); | 899 ResetAnswers(); |
823 | 900 |
824 if (backend_.selectPatientToRecycle(GetContext(), payload_)) | 901 OrthancPluginErrorCode error = backend_.selectPatientToRecycle(GetContext(), payload_); |
825 { | 902 |
826 throw OrthancException(ErrorCode_Plugin); | 903 if (error != OrthancPluginErrorCode_Success) |
904 { | |
905 throw OrthancException(Plugins::Convert(error)); | |
827 } | 906 } |
828 | 907 |
829 return ForwardSingleAnswer(internalId); | 908 return ForwardSingleAnswer(internalId); |
830 } | 909 } |
831 | 910 |
833 bool OrthancPluginDatabase::SelectPatientToRecycle(int64_t& internalId, | 912 bool OrthancPluginDatabase::SelectPatientToRecycle(int64_t& internalId, |
834 int64_t patientIdToAvoid) | 913 int64_t patientIdToAvoid) |
835 { | 914 { |
836 ResetAnswers(); | 915 ResetAnswers(); |
837 | 916 |
838 if (backend_.selectPatientToRecycle2(GetContext(), payload_, patientIdToAvoid)) | 917 OrthancPluginErrorCode error = backend_.selectPatientToRecycle2(GetContext(), payload_, patientIdToAvoid); |
839 { | 918 |
840 throw OrthancException(ErrorCode_Plugin); | 919 if (error != OrthancPluginErrorCode_Success) |
920 { | |
921 throw OrthancException(Plugins::Convert(error)); | |
841 } | 922 } |
842 | 923 |
843 return ForwardSingleAnswer(internalId); | 924 return ForwardSingleAnswer(internalId); |
844 } | 925 } |
845 | 926 |
846 | 927 |
847 void OrthancPluginDatabase::SetGlobalProperty(GlobalProperty property, | 928 void OrthancPluginDatabase::SetGlobalProperty(GlobalProperty property, |
848 const std::string& value) | 929 const std::string& value) |
849 { | 930 { |
850 if (backend_.setGlobalProperty(payload_, static_cast<int32_t>(property), | 931 OrthancPluginErrorCode error = backend_.setGlobalProperty |
851 value.c_str()) != 0) | 932 (payload_, static_cast<int32_t>(property), value.c_str()); |
852 { | 933 |
853 throw OrthancException(ErrorCode_Plugin); | 934 if (error != OrthancPluginErrorCode_Success) |
935 { | |
936 throw OrthancException(Plugins::Convert(error)); | |
854 } | 937 } |
855 } | 938 } |
856 | 939 |
857 | 940 |
858 void OrthancPluginDatabase::SetMainDicomTag(int64_t id, | 941 void OrthancPluginDatabase::SetMainDicomTag(int64_t id, |
859 const DicomTag& tag, | 942 const DicomTag& tag, |
860 const std::string& value) | 943 const std::string& value) |
861 { | 944 { |
862 int32_t status; | |
863 OrthancPluginDicomTag tmp; | 945 OrthancPluginDicomTag tmp; |
864 tmp.group = tag.GetGroup(); | 946 tmp.group = tag.GetGroup(); |
865 tmp.element = tag.GetElement(); | 947 tmp.element = tag.GetElement(); |
866 tmp.value = value.c_str(); | 948 tmp.value = value.c_str(); |
867 | 949 |
950 OrthancPluginErrorCode error; | |
951 | |
868 if (tag.IsIdentifier()) | 952 if (tag.IsIdentifier()) |
869 { | 953 { |
870 status = backend_.setIdentifierTag(payload_, id, &tmp); | 954 error = backend_.setIdentifierTag(payload_, id, &tmp); |
871 } | 955 } |
872 else | 956 else |
873 { | 957 { |
874 status = backend_.setMainDicomTag(payload_, id, &tmp); | 958 error = backend_.setMainDicomTag(payload_, id, &tmp); |
875 } | 959 } |
876 | 960 |
877 if (status != 0) | 961 if (error != OrthancPluginErrorCode_Success) |
878 { | 962 { |
879 throw OrthancException(ErrorCode_Plugin); | 963 throw OrthancException(Plugins::Convert(error)); |
880 } | 964 } |
881 } | 965 } |
882 | 966 |
883 | 967 |
884 void OrthancPluginDatabase::SetMetadata(int64_t id, | 968 void OrthancPluginDatabase::SetMetadata(int64_t id, |
885 MetadataType type, | 969 MetadataType type, |
886 const std::string& value) | 970 const std::string& value) |
887 { | 971 { |
888 if (backend_.setMetadata(payload_, id, static_cast<int32_t>(type), | 972 OrthancPluginErrorCode error = backend_.setMetadata |
889 value.c_str()) != 0) | 973 (payload_, id, static_cast<int32_t>(type), value.c_str()); |
890 { | 974 |
891 throw OrthancException(ErrorCode_Plugin); | 975 if (error != OrthancPluginErrorCode_Success) |
976 { | |
977 throw OrthancException(Plugins::Convert(error)); | |
892 } | 978 } |
893 } | 979 } |
894 | 980 |
895 | 981 |
896 void OrthancPluginDatabase::SetProtectedPatient(int64_t internalId, | 982 void OrthancPluginDatabase::SetProtectedPatient(int64_t internalId, |
897 bool isProtected) | 983 bool isProtected) |
898 { | 984 { |
899 if (backend_.setProtectedPatient(payload_, internalId, isProtected) != 0) | 985 OrthancPluginErrorCode error = backend_.setProtectedPatient(payload_, internalId, isProtected); |
900 { | 986 |
901 throw OrthancException(ErrorCode_Plugin); | 987 if (error != OrthancPluginErrorCode_Success) |
988 { | |
989 throw OrthancException(Plugins::Convert(error)); | |
902 } | 990 } |
903 } | 991 } |
904 | 992 |
905 | 993 |
906 class OrthancPluginDatabase::Transaction : public SQLite::ITransaction | 994 class OrthancPluginDatabase::Transaction : public SQLite::ITransaction |
917 { | 1005 { |
918 } | 1006 } |
919 | 1007 |
920 virtual void Begin() | 1008 virtual void Begin() |
921 { | 1009 { |
922 if (backend_.startTransaction(payload_) != 0) | 1010 OrthancPluginErrorCode error = backend_.startTransaction(payload_); |
923 { | 1011 |
924 throw OrthancException(ErrorCode_Plugin); | 1012 if (error != OrthancPluginErrorCode_Success) |
1013 { | |
1014 throw OrthancException(Plugins::Convert(error)); | |
925 } | 1015 } |
926 } | 1016 } |
927 | 1017 |
928 virtual void Rollback() | 1018 virtual void Rollback() |
929 { | 1019 { |
930 if (backend_.rollbackTransaction(payload_) != 0) | 1020 OrthancPluginErrorCode error = backend_.rollbackTransaction(payload_); |
931 { | 1021 |
932 throw OrthancException(ErrorCode_Plugin); | 1022 if (error != OrthancPluginErrorCode_Success) |
1023 { | |
1024 throw OrthancException(Plugins::Convert(error)); | |
933 } | 1025 } |
934 } | 1026 } |
935 | 1027 |
936 virtual void Commit() | 1028 virtual void Commit() |
937 { | 1029 { |
938 if (backend_.commitTransaction(payload_) != 0) | 1030 OrthancPluginErrorCode error = backend_.commitTransaction(payload_); |
939 { | 1031 |
940 throw OrthancException(ErrorCode_Plugin); | 1032 if (error != OrthancPluginErrorCode_Success) |
1033 { | |
1034 throw OrthancException(Plugins::Convert(error)); | |
941 } | 1035 } |
942 } | 1036 } |
943 }; | 1037 }; |
944 | 1038 |
945 | 1039 |
986 unsigned int OrthancPluginDatabase::GetDatabaseVersion() | 1080 unsigned int OrthancPluginDatabase::GetDatabaseVersion() |
987 { | 1081 { |
988 if (extensions_.getDatabaseVersion != NULL) | 1082 if (extensions_.getDatabaseVersion != NULL) |
989 { | 1083 { |
990 uint32_t version; | 1084 uint32_t version; |
991 if (extensions_.getDatabaseVersion(&version, payload_) != 0) | 1085 OrthancPluginErrorCode error = extensions_.getDatabaseVersion(&version, payload_); |
992 { | 1086 |
993 throw OrthancException(ErrorCode_Plugin); | 1087 if (error != OrthancPluginErrorCode_Success) |
1088 { | |
1089 throw OrthancException(Plugins::Convert(error)); | |
994 } | 1090 } |
995 | 1091 |
996 return version; | 1092 return version; |
997 } | 1093 } |
998 else | 1094 else |
1008 void OrthancPluginDatabase::Upgrade(unsigned int targetVersion, | 1104 void OrthancPluginDatabase::Upgrade(unsigned int targetVersion, |
1009 IStorageArea& storageArea) | 1105 IStorageArea& storageArea) |
1010 { | 1106 { |
1011 if (extensions_.upgradeDatabase != NULL) | 1107 if (extensions_.upgradeDatabase != NULL) |
1012 { | 1108 { |
1013 if (extensions_.upgradeDatabase( | 1109 OrthancPluginErrorCode error = extensions_.upgradeDatabase( |
1014 payload_, targetVersion, | 1110 payload_, targetVersion, |
1015 reinterpret_cast<OrthancPluginStorageArea*>(&storageArea)) != 0) | 1111 reinterpret_cast<OrthancPluginStorageArea*>(&storageArea)); |
1016 { | 1112 |
1017 throw OrthancException(ErrorCode_Plugin); | 1113 if (error != OrthancPluginErrorCode_Success) |
1114 { | |
1115 throw OrthancException(Plugins::Convert(error)); | |
1018 } | 1116 } |
1019 } | 1117 } |
1020 } | 1118 } |
1021 | 1119 |
1022 | 1120 |