comparison Common/BaseStoragePlugin.cpp @ 15:2a02b21f0a19

migration + storage structure
author Alain Mazy
date Tue, 01 Sep 2020 13:08:49 +0200
parents
children 968eb1c78aed
comparison
equal deleted inserted replaced
14:234946ea2038 15:2a02b21f0a19
1 #include "BaseStoragePlugin.h"
2 #include <boost/filesystem/fstream.hpp>
3
4 std::string BaseStoragePlugin::GetOrthancFileSystemPath(const std::string& uuid, const std::string& fileSystemRootPath)
5 {
6 boost::filesystem::path path = fileSystemRootPath;
7
8 path /= std::string(&uuid[0], &uuid[2]);
9 path /= std::string(&uuid[2], &uuid[4]);
10 path /= uuid;
11
12 path.make_preferred();
13
14 return path.string();
15 }
16
17
18 std::string BaseStoragePlugin::GetPath(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled)
19 {
20 if (enableLegacyStorageStructure_)
21 {
22 return GetOrthancFileSystemPath(uuid, std::string()); // there's no "root" path in an object store
23 }
24 else
25 {
26 std::string path = std::string(uuid);
27
28 if (type == OrthancPluginContentType_Dicom)
29 {
30 path += ".dcm";
31 }
32 else if (type == OrthancPluginContentType_DicomAsJson)
33 {
34 path += ".json";
35 }
36 else
37 {
38 path += ".unk";
39 }
40
41 if (encryptionEnabled)
42 {
43 path += ".enc";
44 }
45 return path;
46 }
47 }
48
49 bool BaseStoragePlugin::ReadCommonConfiguration(bool& enableLegacyStorageStructure, const OrthancPlugins::OrthancConfiguration& pluginSection)
50 {
51 std::string storageStructure = pluginSection.GetStringValue("StorageStructure", "flat");
52 if (storageStructure == "flat")
53 {
54 enableLegacyStorageStructure = false;
55 }
56 else
57 {
58 enableLegacyStorageStructure = true;
59 if (storageStructure != "legacy")
60 {
61 OrthancPlugins::LogError("ObjectStorage/StorageStructure configuration invalid value: " + storageStructure + ", allowed values are 'flat' and 'legacy'");
62 return false;
63 }
64 }
65
66 return true;
67 }