Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3536848
D3087.id9440.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D3087.id9440.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
@@ -24,8 +24,10 @@
#ifdef COMM_TEST_SERVICES
const std::string LOG_TABLE_NAME = "backup-service-log-test";
+const std::string BACKUP_TABLE_NAME = "backup-service-backup-test";
#else
const std::string LOG_TABLE_NAME = "backup-service-log";
+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,58 @@
+#pragma once
+
+#include "Item.h"
+
+#include <string>
+#include <vector>
+
+namespace comm {
+namespace network {
+namespace database {
+
+class BackupItem : public Item {
+
+ std::string userID;
+ uint64_t created;
+ std::string backupID;
+ std::string recoveryData;
+ std::string compactionHolder;
+ std::vector<std::string> attachmentHolders;
+
+ void validate() const override;
+
+public:
+ static std::string tableName;
+ static const std::string FIELD_USER_ID;
+ static const std::string FIELD_CREATED;
+ static const std::string FIELD_BACKUP_ID;
+ static const std::string FIELD_RECOVERY_DATA;
+ static const std::string FIELD_COMPACTION_HOLDER;
+ static const std::string FIELD_ATTACHMENT_HOLDERS;
+
+ BackupItem() {
+ }
+ BackupItem(
+ std::string userID,
+ uint64_t created,
+ std::string backupID,
+ std::string recoveryData,
+ std::string compactionHolder,
+ std::vector<std::string> attachmentHolders);
+ BackupItem(const AttributeValues &itemFromDB);
+
+ void assignItemFromDatabase(const AttributeValues &itemFromDB) override;
+
+ std::string getTableName() const override;
+ std::string getPrimaryKey() const override;
+
+ std::string getUserID() const;
+ uint64_t getCreated() const;
+ std::string getBackupID() const;
+ std::string getRecoveryData() const;
+ std::string getCompactionHolder() const;
+ std::vector<std::string> getAttachmentHolders() 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,108 @@
+#include "BackupItem.h"
+
+#include "Constants.h"
+
+namespace comm {
+namespace network {
+namespace database {
+
+const std::string BackupItem::FIELD_USER_ID = "userID";
+const std::string BackupItem::FIELD_CREATED = "created";
+const std::string BackupItem::FIELD_BACKUP_ID = "backupID";
+const std::string BackupItem::FIELD_RECOVERY_DATA = "recoveryData";
+const std::string BackupItem::FIELD_COMPACTION_HOLDER = "compactionHolder";
+const std::string BackupItem::FIELD_ATTACHMENT_HOLDERS = "attachmentHolders";
+
+std::string BackupItem::tableName = BACKUP_TABLE_NAME;
+
+BackupItem::BackupItem(
+ std::string userID,
+ uint64_t created,
+ std::string backupID,
+ std::string recoveryData,
+ std::string compactionHolder,
+ std::vector<std::string> attachmentHolders)
+ : userID(userID),
+ created(created),
+ backupID(backupID),
+ recoveryData(recoveryData),
+ compactionHolder(compactionHolder),
+ attachmentHolders(attachmentHolders) {
+ this->validate();
+}
+
+BackupItem::BackupItem(const AttributeValues &itemFromDB) {
+ this->assignItemFromDatabase(itemFromDB);
+}
+
+void BackupItem::validate() const {
+ if (!this->userID.size()) {
+ throw std::runtime_error("userID empty");
+ }
+ if (!this->created) {
+ throw std::runtime_error("created not provided");
+ }
+ if (!this->backupID.size()) {
+ throw std::runtime_error("backupID empty");
+ }
+ if (!this->recoveryData.size()) {
+ throw std::runtime_error("recoveryData empty");
+ }
+ if (!this->compactionHolder.size()) {
+ throw std::runtime_error("compactionHolder empty");
+ }
+}
+
+void BackupItem::assignItemFromDatabase(const AttributeValues &itemFromDB) {
+ try {
+ this->userID = itemFromDB.at(BackupItem::FIELD_USER_ID).GetS();
+ this->created = std::stoll(
+ std::string(itemFromDB.at(BackupItem::FIELD_CREATED).GetS()).c_str());
+ this->backupID = itemFromDB.at(BackupItem::FIELD_BACKUP_ID).GetS();
+ this->recoveryData = itemFromDB.at(BackupItem::FIELD_RECOVERY_DATA).GetS();
+ this->compactionHolder =
+ itemFromDB.at(BackupItem::FIELD_COMPACTION_HOLDER).GetS();
+ this->attachmentHolders =
+ itemFromDB.at(BackupItem::FIELD_ATTACHMENT_HOLDERS).GetSS();
+ } catch (std::logic_error &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_USER_ID;
+}
+
+std::string BackupItem::getUserID() const {
+ return this->userID;
+}
+
+uint64_t BackupItem::getCreated() const {
+ return this->created;
+}
+
+std::string BackupItem::getBackupID() const {
+ return this->backupID;
+}
+
+std::string BackupItem::getRecoveryData() const {
+ return this->recoveryData;
+}
+
+std::string BackupItem::getCompactionHolder() const {
+ return this->compactionHolder;
+}
+
+std::vector<std::string> BackupItem::getAttachmentHolders() const {
+ return this->attachmentHolders;
+}
+
+} // 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
@@ -3,6 +3,7 @@
#include "Item.h"
#include "LogItem.h"
+#include "BackupItem.h"
#include <memory>
#include <type_traits>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 26, 7:09 PM (34 m, 22 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2707460
Default Alt Text
D3087.id9440.diff (6 KB)
Attached To
Mode
D3087: [services] Backup - Database - add Backup Item
Attached
Detach File
Event Timeline
Log In to Comment