Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3536844
D3087.id9217.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D3087.id9217.diff
View Options
diff --git a/services/backup/docker-server/contents/server/src/Constants.h b/services/backup/docker-server/contents/server/src/Constants.h
--- a/services/backup/docker-server/contents/server/src/Constants.h
+++ b/services/backup/docker-server/contents/server/src/Constants.h
@@ -26,8 +26,10 @@
#ifdef COMM_TEST_SERVICES
const std::string USER_PERSIST_TABLE_NAME = "backup-service-user-persist-test";
+const std::string BACKUP_TABLE_NAME = "backup-service-backup-test";
#else
const std::string USER_PERSIST_TABLE_NAME = "backup-service-user-persist";
+const std::string BACKUP_TABLE_NAME = "backup-service-backup";
#endif
} // namespace network
diff --git a/services/backup/docker-server/contents/server/src/DatabaseEntities/BackupItem.h b/services/backup/docker-server/contents/server/src/DatabaseEntities/BackupItem.h
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/DatabaseEntities/BackupItem.h
@@ -0,0 +1,49 @@
+#pragma once
+
+#include "Item.h"
+
+#include <string>
+
+namespace comm {
+namespace network {
+namespace database {
+
+class BackupItem : public Item {
+
+ std::string id;
+ std::string compactionID;
+ std::string encryptedBackupKey;
+ uint64_t created = 0;
+
+ void validate() const override;
+
+public:
+ static std::string tableName;
+ static const std::string FIELD_ID;
+ static const std::string FIELD_COMPACTION_ID;
+ static const std::string FIELD_ENCRYPTED_BACKUP_KEY;
+ static const std::string FIELD_CREATED;
+
+ BackupItem() {
+ }
+ BackupItem(
+ std::string id,
+ std::string compactionID,
+ std::string encryptedBackupKey,
+ uint64_t created = 0);
+ BackupItem(const AttributeValues &itemFromDB);
+
+ void assignItemFromDatabase(const AttributeValues &itemFromDB) override;
+
+ std::string getTableName() const override;
+ std::string getPrimaryKey() const override;
+
+ std::string getID() const;
+ std::string getCompactionID() const;
+ std::string getEncryptedBackupKey() const;
+ uint64_t getCreated() const;
+};
+
+} // namespace database
+} // namespace network
+} // namespace comm
diff --git a/services/backup/docker-server/contents/server/src/DatabaseEntities/BackupItem.cpp b/services/backup/docker-server/contents/server/src/DatabaseEntities/BackupItem.cpp
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/DatabaseEntities/BackupItem.cpp
@@ -0,0 +1,85 @@
+#include "BackupItem.h"
+
+#include "Constants.h"
+
+namespace comm {
+namespace network {
+namespace database {
+
+const std::string BackupItem::FIELD_ID = "id";
+const std::string BackupItem::FIELD_COMPACTION_ID = "compactionID";
+const std::string BackupItem::FIELD_ENCRYPTED_BACKUP_KEY = "encryptedBackupKey";
+const std::string BackupItem::FIELD_CREATED = "created";
+
+std::string BackupItem::tableName = BACKUP_TABLE_NAME;
+
+BackupItem::BackupItem(
+ std::string id,
+ std::string compactionID,
+ std::string encryptedBackupKey,
+ uint64_t created)
+ : id(id),
+ compactionID(compactionID),
+ encryptedBackupKey(encryptedBackupKey),
+ created(created) {
+ this->validate();
+}
+
+BackupItem::BackupItem(const AttributeValues &itemFromDB) {
+ this->assignItemFromDatabase(itemFromDB);
+}
+
+void BackupItem::validate() const {
+ if (!this->id.size()) {
+ throw std::runtime_error("id empty");
+ }
+ if (!this->compactionID.size()) {
+ throw std::runtime_error("compactionID empty");
+ }
+ if (!this->encryptedBackupKey.size()) {
+ throw std::runtime_error("encryptedBackupKey empty");
+ }
+}
+
+void BackupItem::assignItemFromDatabase(const AttributeValues &itemFromDB) {
+ try {
+ this->id = itemFromDB.at(BackupItem::FIELD_ID).GetS();
+ this->compactionID = itemFromDB.at(BackupItem::FIELD_COMPACTION_ID).GetS();
+ this->encryptedBackupKey =
+ itemFromDB.at(BackupItem::FIELD_ENCRYPTED_BACKUP_KEY).GetS();
+ this->created = std::stoll(
+ std::string(itemFromDB.at(BackupItem::FIELD_CREATED).GetS()).c_str());
+ } catch (std::out_of_range &e) {
+ throw std::runtime_error(
+ "invalid backup item provided, " + std::string(e.what()));
+ }
+ this->validate();
+}
+
+std::string BackupItem::getTableName() const {
+ return BackupItem::tableName;
+}
+
+std::string BackupItem::getPrimaryKey() const {
+ return BackupItem::FIELD_ID;
+}
+
+std::string BackupItem::getID() const {
+ return this->id;
+}
+
+std::string BackupItem::getCompactionID() const {
+ return this->compactionID;
+}
+
+std::string BackupItem::getEncryptedBackupKey() const {
+ return this->encryptedBackupKey;
+}
+
+uint64_t BackupItem::getCreated() const {
+ return this->created;
+}
+
+} // namespace database
+} // namespace network
+} // namespace comm
diff --git a/services/backup/docker-server/contents/server/src/DatabaseEntities/DatabaseEntitiesTools.h b/services/backup/docker-server/contents/server/src/DatabaseEntities/DatabaseEntitiesTools.h
--- a/services/backup/docker-server/contents/server/src/DatabaseEntities/DatabaseEntitiesTools.h
+++ b/services/backup/docker-server/contents/server/src/DatabaseEntities/DatabaseEntitiesTools.h
@@ -2,6 +2,7 @@
#include "Item.h"
+#include "BackupItem.h"
#include "UserPersistItem.h"
#include <memory>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 26, 7:09 PM (1 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2707658
Default Alt Text
D3087.id9217.diff (5 KB)
Attached To
Mode
D3087: [services] Backup - Database - add Backup Item
Attached
Detach File
Event Timeline
Log In to Comment