Page MenuHomePhabricator

D3087.id9800.diff
No OneTemporary

D3087.id9800.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
@@ -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;
+ std::string backupID;
+ uint64_t created;
+ 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_BACKUP_ID;
+ static const std::string FIELD_CREATED;
+ 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,
+ std::string backupID,
+ uint64_t created,
+ 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;
+ std::string getBackupID() const;
+ uint64_t getCreated() 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,111 @@
+#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_BACKUP_ID = "backupID";
+const std::string BackupItem::FIELD_CREATED = "created";
+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,
+ std::string backupID,
+ uint64_t created,
+ std::string recoveryData,
+ std::string compactionHolder,
+ std::vector<std::string> attachmentHolders)
+ : userID(userID),
+ backupID(backupID),
+ created(created),
+ 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->backupID.size()) {
+ throw std::runtime_error("backupID empty");
+ }
+ if (!this->created) {
+ throw std::runtime_error("created not provided");
+ }
+ if (!this->recoveryData.size()) {
+ throw std::runtime_error("recoveryData empty");
+ }
+}
+
+void BackupItem::assignItemFromDatabase(const AttributeValues &itemFromDB) {
+ try {
+ this->userID = itemFromDB.at(BackupItem::FIELD_USER_ID).GetS();
+ this->backupID = itemFromDB.at(BackupItem::FIELD_BACKUP_ID).GetS();
+ this->created = std::stoll(
+ std::string(itemFromDB.at(BackupItem::FIELD_CREATED).GetS()).c_str());
+ this->recoveryData = itemFromDB.at(BackupItem::FIELD_RECOVERY_DATA).GetS();
+ auto compactionHolder =
+ itemFromDB.find(BackupItem::FIELD_COMPACTION_HOLDER);
+ if (compactionHolder != itemFromDB.end()) {
+ this->compactionHolder = compactionHolder->second.GetS();
+ }
+ auto attachmentsHolders =
+ itemFromDB.find(BackupItem::FIELD_ATTACHMENT_HOLDERS);
+ if (attachmentsHolders != itemFromDB.end()) {
+ this->attachmentHolders = attachmentsHolders->second.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;
+}
+
+std::string BackupItem::getBackupID() const {
+ return this->backupID;
+}
+
+uint64_t BackupItem::getCreated() const {
+ return this->created;
+}
+
+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
@@ -2,6 +2,7 @@
#include "Item.h"
+#include "BackupItem.h"
#include "LogItem.h"
#include <memory>

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 26, 7:09 PM (1 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2703928
Default Alt Text
D3087.id9800.diff (6 KB)

Event Timeline