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 #include 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 + +namespace comm { +namespace network { +namespace database { + +class LogItem : public Item { + + std::string backupID; + std::string logID; + bool persistedInBlob; + std::string value; + std::vector 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 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 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 + +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 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 LogItem::getAttachmentHolders() const { + return this->attachmentHolders; +} + +} // namespace database +} // namespace network +} // namespace comm