# HG changeset patch # User Sebastien Jodogne # Date 1618850870 -7200 # Node ID 34e2b93a7ac1dcd2f6143ba1eb6981959dd5fed6 # Parent 793bbbe11287383a59294f9a5b886c6a9041e64f implementing interface for revisions in attachments diff -r 793bbbe11287 -r 34e2b93a7ac1 Framework/Plugins/DatabaseBackendAdapterV2.cpp --- a/Framework/Plugins/DatabaseBackendAdapterV2.cpp Mon Apr 19 16:45:15 2021 +0200 +++ b/Framework/Plugins/DatabaseBackendAdapterV2.cpp Mon Apr 19 18:47:50 2021 +0200 @@ -362,7 +362,8 @@ try { DatabaseBackendAdapterV2::Adapter::DatabaseAccessor accessor(*adapter); - adapter->GetBackend().AddAttachment(accessor.GetManager(), id, *attachment); + adapter->GetBackend().AddAttachment(accessor.GetManager(), id, *attachment, + 0 /* revision number, unused in old API */); return OrthancPluginErrorCode_Success; } ORTHANC_PLUGINS_DATABASE_CATCH; @@ -962,8 +963,9 @@ try { - DatabaseBackendAdapterV2::Adapter::DatabaseAccessor accessor(*adapter); - adapter->GetBackend().LookupAttachment(*output, accessor.GetManager(), id, contentType); + DatabaseBackendAdapterV2::Adapter::DatabaseAccessor accessor(*adapter); + int64_t revision; // not handled in this API + adapter->GetBackend().LookupAttachment(*output, revision, accessor.GetManager(), id, contentType); return OrthancPluginErrorCode_Success; } ORTHANC_PLUGINS_DATABASE_CATCH; diff -r 793bbbe11287 -r 34e2b93a7ac1 Framework/Plugins/DatabaseBackendAdapterV3.cpp --- a/Framework/Plugins/DatabaseBackendAdapterV3.cpp Mon Apr 19 16:45:15 2021 +0200 +++ b/Framework/Plugins/DatabaseBackendAdapterV3.cpp Mon Apr 19 18:47:50 2021 +0200 @@ -1118,14 +1118,15 @@ static OrthancPluginErrorCode AddAttachment(OrthancPluginDatabaseTransaction* transaction, int64_t id, - const OrthancPluginAttachment* attachment) + const OrthancPluginAttachment* attachment, + int64_t revision) { DatabaseBackendAdapterV3::Transaction* t = reinterpret_cast(transaction); try { t->GetOutput().Clear(); - t->GetBackend().AddAttachment(t->GetManager(), id, *attachment); + t->GetBackend().AddAttachment(t->GetManager(), id, *attachment, revision); return OrthancPluginErrorCode_Success; } ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); @@ -1669,6 +1670,7 @@ static OrthancPluginErrorCode LookupAttachment(OrthancPluginDatabaseTransaction* transaction, + int64_t* revision /* out */, int64_t resourceId, int32_t contentType) { @@ -1677,7 +1679,7 @@ try { t->GetOutput().Clear(); - t->GetBackend().LookupAttachment(t->GetOutput(), t->GetManager(), resourceId, contentType); + t->GetBackend().LookupAttachment(t->GetOutput(), *revision, t->GetManager(), resourceId, contentType); return OrthancPluginErrorCode_Success; } ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); @@ -2007,7 +2009,6 @@ params.rollback = Rollback; params.commit = Commit; - params.addAttachment = AddAttachment; params.clearChanges = ClearChanges; params.clearExportedResources = ClearExportedResources; params.clearMainDicomTags = ClearMainDicomTags; @@ -2028,8 +2029,8 @@ params.getLastExportedResource = GetLastExportedResource; params.getMainDicomTags = GetMainDicomTags; params.getPublicId = GetPublicId; + params.getResourceType = GetResourceType; params.getResourcesCount = GetResourcesCount; - params.getResourceType = GetResourceType; params.getTotalCompressedSize = GetTotalCompressedSize; params.getTotalUncompressedSize = GetTotalUncompressedSize; params.isDiskSizeAbove = IsDiskSizeAbove; @@ -2043,10 +2044,11 @@ params.lookupMetadata = LookupMetadata; params.lookupParent = LookupParent; params.lookupResource = LookupResource; + params.lookupResourceAndParent = LookupResourceAndParent; params.lookupResources = LookupResources; - params.lookupResourceAndParent = LookupResourceAndParent; params.selectPatientToRecycle = SelectPatientToRecycle; params.selectPatientToRecycle2 = SelectPatientToRecycle2; + params.setAttachment = AddAttachment; params.setGlobalProperty = SetGlobalProperty; params.setMetadata = SetMetadata; params.setProtectedPatient = SetProtectedPatient; diff -r 793bbbe11287 -r 34e2b93a7ac1 Framework/Plugins/IDatabaseBackend.h --- a/Framework/Plugins/IDatabaseBackend.h Mon Apr 19 16:45:15 2021 +0200 +++ b/Framework/Plugins/IDatabaseBackend.h Mon Apr 19 18:47:50 2021 +0200 @@ -52,7 +52,8 @@ virtual void AddAttachment(DatabaseManager& manager, int64_t id, - const OrthancPluginAttachment& attachment) = 0; + const OrthancPluginAttachment& attachment, + int64_t revision) = 0; virtual void AttachChild(DatabaseManager& manager, int64_t parent, @@ -166,6 +167,7 @@ /* Use GetOutput().AnswerAttachment() */ virtual bool LookupAttachment(IDatabaseBackendOutput& output, + int64_t& revision /*out*/, DatabaseManager& manager, int64_t id, int32_t contentType) = 0; diff -r 793bbbe11287 -r 34e2b93a7ac1 Framework/Plugins/IndexBackend.cpp --- a/Framework/Plugins/IndexBackend.cpp Mon Apr 19 16:45:15 2021 +0200 +++ b/Framework/Plugins/IndexBackend.cpp Mon Apr 19 18:47:50 2021 +0200 @@ -352,8 +352,11 @@ void IndexBackend::AddAttachment(DatabaseManager& manager, int64_t id, - const OrthancPluginAttachment& attachment) + const OrthancPluginAttachment& attachment, + int64_t revision) { + // TODO - REVISIONS + DatabaseManager::CachedStatement statement( STATEMENT_FROM_HERE, manager, "INSERT INTO AttachedFiles VALUES(${id}, ${type}, ${uuid}, " @@ -1026,6 +1029,7 @@ /* Use GetOutput().AnswerAttachment() */ bool IndexBackend::LookupAttachment(IDatabaseBackendOutput& output, + int64_t& revision /*out*/, DatabaseManager& manager, int64_t id, int32_t contentType) @@ -1058,6 +1062,9 @@ ReadInteger32(statement, 2), ReadInteger64(statement, 3), ReadString(statement, 5)); + + revision = 0; // TODO - REVISIONS + return true; } } diff -r 793bbbe11287 -r 34e2b93a7ac1 Framework/Plugins/IndexBackend.h --- a/Framework/Plugins/IndexBackend.h Mon Apr 19 16:45:15 2021 +0200 +++ b/Framework/Plugins/IndexBackend.h Mon Apr 19 18:47:50 2021 +0200 @@ -101,7 +101,8 @@ virtual void AddAttachment(DatabaseManager& manager, int64_t id, - const OrthancPluginAttachment& attachment) ORTHANC_OVERRIDE; + const OrthancPluginAttachment& attachment, + int64_t revision) ORTHANC_OVERRIDE; virtual void AttachChild(DatabaseManager& manager, int64_t parent, @@ -205,6 +206,7 @@ const OrthancPluginExportedResource& resource) ORTHANC_OVERRIDE; virtual bool LookupAttachment(IDatabaseBackendOutput& output, + int64_t& revision /*out*/, DatabaseManager& manager, int64_t id, int32_t contentType) ORTHANC_OVERRIDE; diff -r 793bbbe11287 -r 34e2b93a7ac1 Framework/Plugins/IndexUnitTests.h --- a/Framework/Plugins/IndexUnitTests.h Mon Apr 19 16:45:15 2021 +0200 +++ b/Framework/Plugins/IndexUnitTests.h Mon Apr 19 18:47:50 2021 +0200 @@ -354,14 +354,14 @@ a2.compressedSize = 4242; a2.compressedHash = "md5_2"; - db.AddAttachment(*manager, a, a1); + db.AddAttachment(*manager, a, a1, 42); db.ListAvailableAttachments(fc, *manager, a); ASSERT_EQ(1u, fc.size()); ASSERT_EQ(Orthanc::FileContentType_Dicom, fc.front()); - db.AddAttachment(*manager, a, a2); + db.AddAttachment(*manager, a, a2, 43); db.ListAvailableAttachments(fc, *manager, a); ASSERT_EQ(2u, fc.size()); - ASSERT_FALSE(db.LookupAttachment(*output, *manager, b, Orthanc::FileContentType_Dicom)); + ASSERT_FALSE(db.LookupAttachment(*output, revision, *manager, b, Orthanc::FileContentType_Dicom)); ASSERT_EQ(4284u, db.GetTotalCompressedSize(*manager)); ASSERT_EQ(4284u, db.GetTotalUncompressedSize(*manager)); @@ -374,7 +374,8 @@ expectedAttachment->compressionType = Orthanc::CompressionType_None; expectedAttachment->compressedSize = 42; expectedAttachment->compressedHash = "md5_1"; - ASSERT_TRUE(db.LookupAttachment(*output, *manager, a, Orthanc::FileContentType_Dicom)); + ASSERT_TRUE(db.LookupAttachment(*output, revision, *manager, a, Orthanc::FileContentType_Dicom)); + ASSERT_EQ(0, revision); // TODO - REVISIONS expectedAttachment.reset(new OrthancPluginAttachment); expectedAttachment->uuid = "uuid2"; @@ -384,7 +385,9 @@ expectedAttachment->compressionType = Orthanc::CompressionType_None; expectedAttachment->compressedSize = 4242; expectedAttachment->compressedHash = "md5_2"; - ASSERT_TRUE(db.LookupAttachment(*output, *manager, a, Orthanc::FileContentType_DicomAsJson)); + revision = -1; + ASSERT_TRUE(db.LookupAttachment(*output, revision, *manager, a, Orthanc::FileContentType_DicomAsJson)); + ASSERT_EQ(0, revision); // TODO - REVISIONS db.ListAvailableAttachments(fc, *manager, b); ASSERT_EQ(0u, fc.size());