Page MenuHomePhabricator

D3087.id9217.diff
No OneTemporary

D3087.id9217.diff

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

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)

Event Timeline