Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 1237:0f3716b88af7
cleaning
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 05 Dec 2014 15:33:16 +0100 |
parents | 21d84e3acc0d |
children | 6c07108ff1e2 |
comparison
equal
deleted
inserted
replaced
1236:21d84e3acc0d | 1237:0f3716b88af7 |
---|---|
416 { | 416 { |
417 } | 417 } |
418 } | 418 } |
419 | 419 |
420 | 420 |
421 | |
422 | |
423 bool ServerIndex::GetMetadataAsInteger(int& result, | |
424 int64_t id, | |
425 MetadataType type) | |
426 { | |
427 std::string s = db_->GetMetadata(id, type, ""); | |
428 if (s.size() == 0) | |
429 { | |
430 return false; | |
431 } | |
432 | |
433 try | |
434 { | |
435 result = boost::lexical_cast<int>(s); | |
436 return true; | |
437 } | |
438 catch (boost::bad_lexical_cast&) | |
439 { | |
440 return false; | |
441 } | |
442 } | |
443 | |
444 | |
445 | |
446 uint64_t ServerIndex::IncrementGlobalSequenceInternal(GlobalProperty property) | |
447 { | |
448 std::string oldValue; | |
449 | |
450 if (db_->LookupGlobalProperty(oldValue, property)) | |
451 { | |
452 uint64_t oldNumber; | |
453 | |
454 try | |
455 { | |
456 oldNumber = boost::lexical_cast<uint64_t>(oldValue); | |
457 db_->SetGlobalProperty(property, boost::lexical_cast<std::string>(oldNumber + 1)); | |
458 return oldNumber + 1; | |
459 } | |
460 catch (boost::bad_lexical_cast&) | |
461 { | |
462 throw OrthancException(ErrorCode_InternalError); | |
463 } | |
464 } | |
465 else | |
466 { | |
467 // Initialize the sequence at "1" | |
468 db_->SetGlobalProperty(property, "1"); | |
469 return 1; | |
470 } | |
471 } | |
472 | |
473 | |
474 | |
421 ServerIndex::ServerIndex(ServerContext& context, | 475 ServerIndex::ServerIndex(ServerContext& context, |
422 const std::string& dbPath) : | 476 const std::string& dbPath) : |
423 done_(false), | 477 done_(false), |
424 maximumStorageSize_(0), | 478 maximumStorageSize_(0), |
425 maximumPatients_(0) | 479 maximumPatients_(0) |
670 } | 724 } |
671 | 725 |
672 SeriesStatus seriesStatus = GetSeriesStatus(series); | 726 SeriesStatus seriesStatus = GetSeriesStatus(series); |
673 if (seriesStatus == SeriesStatus_Complete) | 727 if (seriesStatus == SeriesStatus_Complete) |
674 { | 728 { |
675 db_->LogChange(series, ChangeType_CompletedSeries, ResourceType_Series, hasher.HashSeries()); | 729 LogChange(series, ChangeType_CompletedSeries, ResourceType_Series, hasher.HashSeries()); |
676 } | 730 } |
677 | 731 |
678 // Mark the parent resources of this instance as unstable | 732 // Mark the parent resources of this instance as unstable |
679 MarkAsUnstable(series, ResourceType_Series, hasher.HashSeries()); | 733 MarkAsUnstable(series, ResourceType_Series, hasher.HashSeries()); |
680 MarkAsUnstable(study, ResourceType_Study, hasher.HashStudy()); | 734 MarkAsUnstable(study, ResourceType_Study, hasher.HashStudy()); |
881 { | 935 { |
882 result["Type"] = "Series"; | 936 result["Type"] = "Series"; |
883 result["Status"] = EnumerationToString(GetSeriesStatus(id)); | 937 result["Status"] = EnumerationToString(GetSeriesStatus(id)); |
884 | 938 |
885 int i; | 939 int i; |
886 if (db_->GetMetadataAsInteger(i, id, MetadataType_Series_ExpectedNumberOfInstances)) | 940 if (GetMetadataAsInteger(i, id, MetadataType_Series_ExpectedNumberOfInstances)) |
887 result["ExpectedNumberOfInstances"] = i; | 941 result["ExpectedNumberOfInstances"] = i; |
888 else | 942 else |
889 result["ExpectedNumberOfInstances"] = Json::nullValue; | 943 result["ExpectedNumberOfInstances"] = Json::nullValue; |
890 | 944 |
891 break; | 945 break; |
903 | 957 |
904 result["FileSize"] = static_cast<unsigned int>(attachment.GetUncompressedSize()); | 958 result["FileSize"] = static_cast<unsigned int>(attachment.GetUncompressedSize()); |
905 result["FileUuid"] = attachment.GetUuid(); | 959 result["FileUuid"] = attachment.GetUuid(); |
906 | 960 |
907 int i; | 961 int i; |
908 if (db_->GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries)) | 962 if (GetMetadataAsInteger(i, id, MetadataType_Instance_IndexInSeries)) |
909 result["IndexInSeries"] = i; | 963 result["IndexInSeries"] = i; |
910 else | 964 else |
911 result["IndexInSeries"] = Json::nullValue; | 965 result["IndexInSeries"] = Json::nullValue; |
912 | 966 |
913 break; | 967 break; |
1444 boost::mutex::scoped_lock lock(mutex_); | 1498 boost::mutex::scoped_lock lock(mutex_); |
1445 | 1499 |
1446 std::auto_ptr<SQLite::ITransaction> transaction(db_->StartTransaction()); | 1500 std::auto_ptr<SQLite::ITransaction> transaction(db_->StartTransaction()); |
1447 | 1501 |
1448 transaction->Begin(); | 1502 transaction->Begin(); |
1449 uint64_t seq = db_->IncrementGlobalSequence(sequence); | 1503 uint64_t seq = IncrementGlobalSequenceInternal(sequence); |
1450 transaction->Commit(); | 1504 transaction->Commit(); |
1451 | 1505 |
1452 return seq; | 1506 return seq; |
1453 } | 1507 } |
1454 | 1508 |
1466 if (!db_->LookupResource(publicId, id, type)) | 1520 if (!db_->LookupResource(publicId, id, type)) |
1467 { | 1521 { |
1468 throw OrthancException(ErrorCode_UnknownResource); | 1522 throw OrthancException(ErrorCode_UnknownResource); |
1469 } | 1523 } |
1470 | 1524 |
1471 db_->LogChange(id, changeType, type, publicId); | 1525 LogChange(id, changeType, type, publicId); |
1472 | 1526 |
1473 transaction->Commit(); | 1527 transaction->Commit(); |
1474 } | 1528 } |
1475 | 1529 |
1476 | 1530 |
1666 if (that->db_->IsExistingResource(id)) | 1720 if (that->db_->IsExistingResource(id)) |
1667 { | 1721 { |
1668 switch (payload.GetResourceType()) | 1722 switch (payload.GetResourceType()) |
1669 { | 1723 { |
1670 case ResourceType_Patient: | 1724 case ResourceType_Patient: |
1671 that->db_->LogChange(id, ChangeType_StablePatient, ResourceType_Patient, payload.GetPublicId()); | 1725 that->LogChange(id, ChangeType_StablePatient, ResourceType_Patient, payload.GetPublicId()); |
1672 break; | 1726 break; |
1673 | 1727 |
1674 case ResourceType_Study: | 1728 case ResourceType_Study: |
1675 that->db_->LogChange(id, ChangeType_StableStudy, ResourceType_Study, payload.GetPublicId()); | 1729 that->LogChange(id, ChangeType_StableStudy, ResourceType_Study, payload.GetPublicId()); |
1676 break; | 1730 break; |
1677 | 1731 |
1678 case ResourceType_Series: | 1732 case ResourceType_Series: |
1679 that->db_->LogChange(id, ChangeType_StableSeries, ResourceType_Series, payload.GetPublicId()); | 1733 that->LogChange(id, ChangeType_StableSeries, ResourceType_Series, payload.GetPublicId()); |
1680 break; | 1734 break; |
1681 | 1735 |
1682 default: | 1736 default: |
1683 throw OrthancException(ErrorCode_InternalError); | 1737 throw OrthancException(ErrorCode_InternalError); |
1684 } | 1738 } |
1704 | 1758 |
1705 UnstableResourcePayload payload(type, publicId); | 1759 UnstableResourcePayload payload(type, publicId); |
1706 unstableResources_.AddOrMakeMostRecent(id, payload); | 1760 unstableResources_.AddOrMakeMostRecent(id, payload); |
1707 //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id; | 1761 //LOG(INFO) << "Unstable resource: " << EnumerationToString(type) << " " << id; |
1708 | 1762 |
1709 db_->LogChange(id, ChangeType_NewChildInstance, type, publicId); | 1763 LogChange(id, ChangeType_NewChildInstance, type, publicId); |
1710 } | 1764 } |
1711 | 1765 |
1712 | 1766 |
1713 | 1767 |
1714 void ServerIndex::LookupIdentifier(std::list<std::string>& result, | 1768 void ServerIndex::LookupIdentifier(std::list<std::string>& result, |