Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3377608
D3084.id9366.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
D3084.id9366.diff
View Options
diff --git a/services/backup/docker-server/contents/server/CMakeLists.txt b/services/backup/docker-server/contents/server/CMakeLists.txt
--- a/services/backup/docker-server/contents/server/CMakeLists.txt
+++ b/services/backup/docker-server/contents/server/CMakeLists.txt
@@ -49,7 +49,7 @@
set(DEV_HEADERS_PATH "./dev")
endif()
-file(GLOB SOURCE_CODE "./src/*.cpp")
+file(GLOB SOURCE_CODE "./src/*.cpp" "./src/**/*.cpp")
list(FILTER SOURCE_CODE EXCLUDE REGEX ".*.dev.cpp$")
foreach (ITEM ${DEV_SOURCE_CODE})
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
@@ -22,5 +22,11 @@
const std::string AWS_REGION = "us-east-2";
+#ifdef COMM_TEST_SERVICES
+const std::string LOG_TABLE_NAME = "backup-service-log-test";
+#else
+const std::string LOG_TABLE_NAME = "backup-service-log";
+#endif
+
} // 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,8 @@
#include "Item.h"
+#include "LogItem.h"
+
#include <memory>
#include <type_traits>
diff --git a/services/backup/docker-server/contents/server/src/DatabaseEntities/LogItem.h b/services/backup/docker-server/contents/server/src/DatabaseEntities/LogItem.h
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/DatabaseEntities/LogItem.h
@@ -0,0 +1,53 @@
+#pragma once
+
+#include "Item.h"
+
+#include <string>
+
+namespace comm {
+namespace network {
+namespace database {
+
+class LogItem : public Item {
+
+ std::string backupID;
+ std::string logID;
+ bool persistedInBlob;
+ std::string value;
+ std::vector<std::string> attachmentHolders;
+
+ void validate() const override;
+
+public:
+ static std::string tableName;
+ static const std::string FIELD_BACKUP_ID;
+ static const std::string FIELD_LOG_ID;
+ static const std::string FIELD_PERSISTED_IN_BLOB;
+ static const std::string FIELD_VALUE;
+ static const std::string FIELD_ATTACHMENT_HOLDERS;
+
+ LogItem() {
+ }
+ LogItem(
+ const std::string backupID,
+ const std::string logID,
+ const bool persistedInBlob,
+ const std::string value,
+ std::vector<std::string> attachmentHolders);
+ LogItem(const AttributeValues &itemFromDB);
+
+ void assignItemFromDatabase(const AttributeValues &itemFromDB) override;
+
+ std::string getTableName() const override;
+ std::string getPrimaryKey() const override;
+
+ std::string getBackupID() const;
+ std::string getLogID() const;
+ bool getPersistedInBlob() const;
+ std::string getValue() const;
+ std::vector<std::string> getAttachmentHolders() const;
+};
+
+} // namespace database
+} // namespace network
+} // namespace comm
diff --git a/services/backup/docker-server/contents/server/src/DatabaseEntities/LogItem.cpp b/services/backup/docker-server/contents/server/src/DatabaseEntities/LogItem.cpp
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/DatabaseEntities/LogItem.cpp
@@ -0,0 +1,98 @@
+#include "LogItem.h"
+
+#include "AwsTools.h"
+#include "Constants.h"
+
+#include <stdexcept>
+
+namespace comm {
+namespace network {
+namespace database {
+
+const std::string LogItem::FIELD_BACKUP_ID = "backupID";
+const std::string LogItem::FIELD_LOG_ID = "logID";
+const std::string LogItem::FIELD_PERSISTED_IN_BLOB = "persistedInBlob";
+const std::string LogItem::FIELD_VALUE = "value";
+const std::string LogItem::FIELD_ATTACHMENT_HOLDERS = "attachmentHolders";
+
+std::string LogItem::tableName = LOG_TABLE_NAME;
+
+LogItem::LogItem(
+ const std::string backupID,
+ const std::string logID,
+ const bool persistedInBlob,
+ const std::string value,
+ std::vector<std::string> attachmentHolders)
+ : backupID(backupID),
+ logID(logID),
+ persistedInBlob(persistedInBlob),
+ value(value),
+ attachmentHolders(attachmentHolders) {
+ this->validate();
+}
+
+LogItem::LogItem(const AttributeValues &itemFromDB) {
+ this->assignItemFromDatabase(itemFromDB);
+}
+
+void LogItem::validate() const {
+ if (!this->backupID.size()) {
+ throw std::runtime_error("backupID empty");
+ }
+ if (!this->logID.size()) {
+ throw std::runtime_error("logID empty");
+ }
+ if (!this->value.size()) {
+ throw std::runtime_error("value empty");
+ }
+ // todo maybe check if values is not too big if persistedInBlob is false
+}
+
+void LogItem::assignItemFromDatabase(const AttributeValues &itemFromDB) {
+ try {
+ this->backupID = itemFromDB.at(LogItem::FIELD_BACKUP_ID).GetS();
+ this->logID = itemFromDB.at(LogItem::FIELD_LOG_ID).GetS();
+ this->persistedInBlob = std::stoi(
+ std::string(itemFromDB.at(LogItem::FIELD_PERSISTED_IN_BLOB).GetS())
+ .c_str());
+ this->value = itemFromDB.at(LogItem::FIELD_VALUE).GetS();
+ this->attachmentHolders =
+ itemFromDB.at(LogItem::FIELD_ATTACHMENT_HOLDERS).GetSS();
+ } catch (std::logic_error &e) {
+ throw std::runtime_error(
+ "invalid log item provided, " + std::string(e.what()));
+ }
+ this->validate();
+}
+
+std::string LogItem::getTableName() const {
+ return LogItem::tableName;
+}
+
+std::string LogItem::getPrimaryKey() const {
+ return LogItem::FIELD_BACKUP_ID;
+}
+
+std::string LogItem::getBackupID() const {
+ return this->backupID;
+}
+
+std::string LogItem::getLogID() const {
+ return this->logID;
+}
+
+bool LogItem::getPersistedInBlob() const {
+ return this->persistedInBlob;
+}
+
+std::string LogItem::getValue() const {
+ return this->value;
+}
+
+std::vector<std::string> LogItem::getAttachmentHolders() const {
+ return this->attachmentHolders;
+}
+
+} // namespace database
+} // namespace network
+} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 6:37 AM (21 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2593090
Default Alt Text
D3084.id9366.diff (6 KB)
Attached To
Mode
D3084: [services] Backup - Database - add Log Item
Attached
Detach File
Event Timeline
Log In to Comment