comparison OrthancServer/Sources/main.cpp @ 5809:023a99146dd0 attach-custom-data

merged find-refactoring -> attach-custom-data
author Alain Mazy <am@orthanc.team>
date Tue, 24 Sep 2024 12:53:43 +0200
parents b4e7a85cde80
children
comparison
equal deleted inserted replaced
5808:63c025cf6958 5809:023a99146dd0
823 PrintErrorCode(ErrorCode_DatabaseCannotSerialize, "Database could not serialize access due to concurrent update, the transaction should be retried"); 823 PrintErrorCode(ErrorCode_DatabaseCannotSerialize, "Database could not serialize access due to concurrent update, the transaction should be retried");
824 PrintErrorCode(ErrorCode_Revision, "A bad revision number was provided, which might indicate conflict between multiple writers"); 824 PrintErrorCode(ErrorCode_Revision, "A bad revision number was provided, which might indicate conflict between multiple writers");
825 PrintErrorCode(ErrorCode_MainDicomTagsMultiplyDefined, "A main DICOM Tag has been defined multiple times for the same resource level"); 825 PrintErrorCode(ErrorCode_MainDicomTagsMultiplyDefined, "A main DICOM Tag has been defined multiple times for the same resource level");
826 PrintErrorCode(ErrorCode_ForbiddenAccess, "Access to a resource is forbidden"); 826 PrintErrorCode(ErrorCode_ForbiddenAccess, "Access to a resource is forbidden");
827 PrintErrorCode(ErrorCode_DuplicateResource, "Duplicate resource"); 827 PrintErrorCode(ErrorCode_DuplicateResource, "Duplicate resource");
828 PrintErrorCode(ErrorCode_IncompatibleConfigurations, "Your configuration file contains configuration that are mutually incompatible");
828 PrintErrorCode(ErrorCode_SQLiteNotOpened, "SQLite: The database is not opened"); 829 PrintErrorCode(ErrorCode_SQLiteNotOpened, "SQLite: The database is not opened");
829 PrintErrorCode(ErrorCode_SQLiteAlreadyOpened, "SQLite: Connection is already open"); 830 PrintErrorCode(ErrorCode_SQLiteAlreadyOpened, "SQLite: Connection is already open");
830 PrintErrorCode(ErrorCode_SQLiteCannotOpen, "SQLite: Unable to open the database"); 831 PrintErrorCode(ErrorCode_SQLiteCannotOpen, "SQLite: Unable to open the database");
831 PrintErrorCode(ErrorCode_SQLiteStatementAlreadyUsed, "SQLite: This cached statement is already being referred to"); 832 PrintErrorCode(ErrorCode_SQLiteStatementAlreadyUsed, "SQLite: This cached statement is already being referred to");
832 PrintErrorCode(ErrorCode_SQLiteExecute, "SQLite: Cannot execute a command"); 833 PrintErrorCode(ErrorCode_SQLiteExecute, "SQLite: Cannot execute a command");
834 PrintErrorCode(ErrorCode_SQLiteCommitWithoutTransaction, "SQLite: Committing a nonexistent transaction"); 835 PrintErrorCode(ErrorCode_SQLiteCommitWithoutTransaction, "SQLite: Committing a nonexistent transaction");
835 PrintErrorCode(ErrorCode_SQLiteRegisterFunction, "SQLite: Unable to register a function"); 836 PrintErrorCode(ErrorCode_SQLiteRegisterFunction, "SQLite: Unable to register a function");
836 PrintErrorCode(ErrorCode_SQLiteFlush, "SQLite: Unable to flush the database"); 837 PrintErrorCode(ErrorCode_SQLiteFlush, "SQLite: Unable to flush the database");
837 PrintErrorCode(ErrorCode_SQLiteCannotRun, "SQLite: Cannot run a cached statement"); 838 PrintErrorCode(ErrorCode_SQLiteCannotRun, "SQLite: Cannot run a cached statement");
838 PrintErrorCode(ErrorCode_SQLiteCannotStep, "SQLite: Cannot step over a cached statement"); 839 PrintErrorCode(ErrorCode_SQLiteCannotStep, "SQLite: Cannot step over a cached statement");
839 PrintErrorCode(ErrorCode_SQLiteBindOutOfRange, "SQLite: Bing a value while out of range (serious error)"); 840 PrintErrorCode(ErrorCode_SQLiteBindOutOfRange, "SQLite: Bind a value while out of range (serious error)");
840 PrintErrorCode(ErrorCode_SQLitePrepareStatement, "SQLite: Cannot prepare a cached statement"); 841 PrintErrorCode(ErrorCode_SQLitePrepareStatement, "SQLite: Cannot prepare a cached statement");
841 PrintErrorCode(ErrorCode_SQLiteTransactionAlreadyStarted, "SQLite: Beginning the same transaction twice"); 842 PrintErrorCode(ErrorCode_SQLiteTransactionAlreadyStarted, "SQLite: Beginning the same transaction twice");
842 PrintErrorCode(ErrorCode_SQLiteTransactionCommit, "SQLite: Failure when committing the transaction"); 843 PrintErrorCode(ErrorCode_SQLiteTransactionCommit, "SQLite: Failure when committing the transaction");
843 PrintErrorCode(ErrorCode_SQLiteTransactionBegin, "SQLite: Cannot start a transaction"); 844 PrintErrorCode(ErrorCode_SQLiteTransactionBegin, "SQLite: Cannot start a transaction");
844 PrintErrorCode(ErrorCode_DirectoryOverFile, "The directory to be created is already occupied by a regular file"); 845 PrintErrorCode(ErrorCode_DirectoryOverFile, "The directory to be created is already occupied by a regular file");
1515 IStorageArea& storageArea, 1516 IStorageArea& storageArea,
1516 OrthancPlugins *plugins, 1517 OrthancPlugins *plugins,
1517 bool loadJobsFromDatabase) 1518 bool loadJobsFromDatabase)
1518 { 1519 {
1519 size_t maxCompletedJobs; 1520 size_t maxCompletedJobs;
1521 bool readOnly;
1520 1522
1521 { 1523 {
1522 OrthancConfiguration::ReaderLock lock; 1524 OrthancConfiguration::ReaderLock lock;
1523 1525
1524 // These configuration options must be set before creating the 1526 // These configuration options must be set before creating the
1542 if (maxCompletedJobs == 0) 1544 if (maxCompletedJobs == 0)
1543 { 1545 {
1544 LOG(WARNING) << "Setting option \"JobsHistorySize\" to zero is not recommended"; 1546 LOG(WARNING) << "Setting option \"JobsHistorySize\" to zero is not recommended";
1545 } 1547 }
1546 1548
1549 // New option in Orthanc 1.12.5
1550 readOnly = lock.GetConfiguration().GetBooleanParameter("ReadOnly", false);
1551
1547 // Configuration of DICOM TLS for Orthanc SCU (since Orthanc 1.9.0) 1552 // Configuration of DICOM TLS for Orthanc SCU (since Orthanc 1.9.0)
1548 DicomAssociationParameters::SetDefaultOwnCertificatePath( 1553 DicomAssociationParameters::SetDefaultOwnCertificatePath(
1549 lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_PRIVATE_KEY, ""), 1554 lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_PRIVATE_KEY, ""),
1550 lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_CERTIFICATE, "")); 1555 lock.GetConfiguration().GetStringParameter(KEY_DICOM_TLS_CERTIFICATE, ""));
1551 DicomAssociationParameters::SetDefaultTrustedCertificatesPath( 1556 DicomAssociationParameters::SetDefaultTrustedCertificatesPath(
1556 // New option in Orthanc 1.9.3 1561 // New option in Orthanc 1.9.3
1557 DicomAssociationParameters::SetDefaultRemoteCertificateRequired( 1562 DicomAssociationParameters::SetDefaultRemoteCertificateRequired(
1558 lock.GetConfiguration().GetBooleanParameter(KEY_DICOM_TLS_REMOTE_CERTIFICATE_REQUIRED, true)); 1563 lock.GetConfiguration().GetBooleanParameter(KEY_DICOM_TLS_REMOTE_CERTIFICATE_REQUIRED, true));
1559 } 1564 }
1560 1565
1561 ServerContext context(database, storageArea, false /* not running unit tests */, maxCompletedJobs); 1566 ServerContext context(database, storageArea, false /* not running unit tests */, maxCompletedJobs, readOnly);
1562 1567
1563 { 1568 {
1564 OrthancConfiguration::ReaderLock lock; 1569 OrthancConfiguration::ReaderLock lock;
1565 1570
1566 context.SetCompressionEnabled(lock.GetConfiguration().GetBooleanParameter("StorageCompression", false)); 1571 if (context.IsReadOnly())
1567 context.SetStoreMD5ForAttachments(lock.GetConfiguration().GetBooleanParameter("StoreMD5ForAttachments", true)); 1572 {
1568 1573 LOG(WARNING) << "READ-ONLY SYSTEM: ignoring these configurations: StorageCompression, StoreMD5ForAttachments, OverwriteInstances, MaximumPatientCount, MaximumStorageSize, MaximumStorageMode";
1569 // New option in Orthanc 1.4.2 1574
1570 context.SetOverwriteInstances(lock.GetConfiguration().GetBooleanParameter("OverwriteInstances", false)); 1575 if (context.IsSaveJobs())
1571 1576 {
1572 try 1577 throw OrthancException(ErrorCode_IncompatibleConfigurations, "\"SaveJobs\" can not be true when \"ReadOnly\" is true");
1573 { 1578 }
1574 context.GetIndex().SetMaximumPatientCount(lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumPatientCount", 0)); 1579 }
1575 } 1580 else
1576 catch (...) 1581 {
1577 { 1582 context.SetCompressionEnabled(lock.GetConfiguration().GetBooleanParameter("StorageCompression", false));
1578 context.GetIndex().SetMaximumPatientCount(0); 1583 context.SetStoreMD5ForAttachments(lock.GetConfiguration().GetBooleanParameter("StoreMD5ForAttachments", true));
1579 } 1584
1580 1585 // New option in Orthanc 1.4.2
1581 try 1586 context.SetOverwriteInstances(lock.GetConfiguration().GetBooleanParameter("OverwriteInstances", false));
1582 { 1587
1583 uint64_t size = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumStorageSize", 0); 1588 try
1584 context.GetIndex().SetMaximumStorageSize(size * 1024 * 1024); 1589 {
1585 } 1590 context.GetIndex().SetMaximumPatientCount(lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumPatientCount", 0));
1586 catch (...) 1591 }
1587 { 1592 catch (...)
1588 context.GetIndex().SetMaximumStorageSize(0); 1593 {
1589 } 1594 context.GetIndex().SetMaximumPatientCount(0);
1590 1595 }
1591 try 1596
1592 { 1597 try
1593 std::string mode = lock.GetConfiguration().GetStringParameter("MaximumStorageMode", "Recycle"); 1598 {
1594 context.GetIndex().SetMaximumStorageMode(StringToMaxStorageMode(mode)); 1599 uint64_t size = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumStorageSize", 0);
1595 } 1600 context.GetIndex().SetMaximumStorageSize(size * 1024 * 1024);
1596 catch (...) 1601 }
1597 { 1602 catch (...)
1598 context.GetIndex().SetMaximumStorageMode(MaxStorageMode_Recycle); 1603 {
1599 } 1604 context.GetIndex().SetMaximumStorageSize(0);
1600 1605 }
1606
1607 try
1608 {
1609 std::string mode = lock.GetConfiguration().GetStringParameter("MaximumStorageMode", "Recycle");
1610 context.GetIndex().SetMaximumStorageMode(StringToMaxStorageMode(mode));
1611 }
1612 catch (...)
1613 {
1614 context.GetIndex().SetMaximumStorageMode(MaxStorageMode_Recycle);
1615 }
1616 }
1617
1618 // note: this config is valid in ReadOnlyMode
1601 try 1619 try
1602 { 1620 {
1603 uint64_t size = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumStorageCacheSize", 128); 1621 uint64_t size = lock.GetConfiguration().GetUnsignedIntegerParameter("MaximumStorageCacheSize", 128);
1604 context.SetMaximumStorageCacheSize(size * 1024 * 1024); 1622 context.SetMaximumStorageCacheSize(size * 1024 * 1024);
1605 } 1623 }
1953 1971
1954 { 1972 {
1955 SQLiteDatabaseWrapper inMemoryDatabase; 1973 SQLiteDatabaseWrapper inMemoryDatabase;
1956 inMemoryDatabase.Open(); 1974 inMemoryDatabase.Open();
1957 MemoryStorageArea inMemoryStorage; 1975 MemoryStorageArea inMemoryStorage;
1958 ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */); 1976 ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */);
1959 OrthancRestApi restApi(context, false /* no Orthanc Explorer */); 1977 OrthancRestApi restApi(context, false /* no Orthanc Explorer */);
1960 restApi.GenerateOpenApiDocumentation(openapi); 1978 restApi.GenerateOpenApiDocumentation(openapi);
1961 context.Stop(); 1979 context.Stop();
1962 } 1980 }
1963 1981
2004 2022
2005 { 2023 {
2006 SQLiteDatabaseWrapper inMemoryDatabase; 2024 SQLiteDatabaseWrapper inMemoryDatabase;
2007 inMemoryDatabase.Open(); 2025 inMemoryDatabase.Open();
2008 MemoryStorageArea inMemoryStorage; 2026 MemoryStorageArea inMemoryStorage;
2009 ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */); 2027 ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */);
2010 OrthancRestApi restApi(context, false /* no Orthanc Explorer */); 2028 OrthancRestApi restApi(context, false /* no Orthanc Explorer */);
2011 restApi.GenerateReStructuredTextCheatSheet(cheatsheet, "https://orthanc.uclouvain.be/api/index.html"); 2029 restApi.GenerateReStructuredTextCheatSheet(cheatsheet, "https://orthanc.uclouvain.be/api/index.html");
2012 context.Stop(); 2030 context.Stop();
2013 } 2031 }
2014 2032