diff --git a/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.cpp b/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.cpp index c2cf3b6a8..3d1107916 100644 --- a/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.cpp +++ b/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.cpp @@ -1,70 +1,70 @@ #include "BlobItem.h" #include "AwsTools.h" #include "Constants.h" namespace comm { namespace network { namespace database { const std::string BlobItem::FIELD_BLOB_HASH = "blobHash"; const std::string BlobItem::FIELD_S3_PATH = "s3Path"; const std::string BlobItem::FIELD_CREATED = "created"; std::string BlobItem::tableName = BLOB_TABLE_NAME; BlobItem::BlobItem( const std::string blobHash, const S3Path s3Path, uint64_t created) : blobHash(blobHash), s3Path(s3Path), created(created) { this->validate(); } BlobItem::BlobItem(const AttributeValues &itemFromDB) { this->assignItemFromDatabase(itemFromDB); } void BlobItem::validate() const { if (!this->blobHash.size()) { throw std::runtime_error("blobHash empty"); } this->s3Path.validate(); } void BlobItem::assignItemFromDatabase(const AttributeValues &itemFromDB) { try { this->blobHash = itemFromDB.at(BlobItem::FIELD_BLOB_HASH).GetS(); this->s3Path = S3Path(itemFromDB.at(BlobItem::FIELD_S3_PATH).GetS()); this->created = std::stoll( std::string(itemFromDB.at(BlobItem::FIELD_CREATED).GetS()).c_str()); - } catch (std::out_of_range &e) { + } catch (std::logic_error &e) { throw std::runtime_error( "invalid blob item provided, " + std::string(e.what())); } this->validate(); } std::string BlobItem::getTableName() const { return BlobItem::tableName; } std::string BlobItem::getPrimaryKey() const { return BlobItem::FIELD_BLOB_HASH; } std::string BlobItem::getBlobHash() const { return this->blobHash; } S3Path BlobItem::getS3Path() const { return this->s3Path; } uint64_t BlobItem::getCreated() const { return this->created; } } // namespace database } // namespace network } // namespace comm diff --git a/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.cpp b/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.cpp index b3edf90a9..45e682d37 100644 --- a/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.cpp +++ b/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.cpp @@ -1,64 +1,59 @@ #include "ReverseIndexItem.h" #include "AwsTools.h" #include "Constants.h" namespace comm { namespace network { namespace database { const std::string ReverseIndexItem::FIELD_HOLDER = "holder"; const std::string ReverseIndexItem::FIELD_BLOB_HASH = "blobHash"; std::string ReverseIndexItem::tableName = REVERSE_INDEX_TABLE_NAME; ReverseIndexItem::ReverseIndexItem( const std::string holder, const std::string blobHash) : holder(holder), blobHash(blobHash) { this->validate(); } ReverseIndexItem::ReverseIndexItem(const AttributeValues &itemFromDB) { this->assignItemFromDatabase(itemFromDB); } void ReverseIndexItem::validate() const { if (!this->holder.size()) { throw std::runtime_error("reverse index empty"); } if (!this->blobHash.size()) { throw std::runtime_error("blobHash empty"); } } void ReverseIndexItem::assignItemFromDatabase( const AttributeValues &itemFromDB) { - try { - this->holder = itemFromDB.at(ReverseIndexItem::FIELD_HOLDER).GetS(); - this->blobHash = itemFromDB.at(ReverseIndexItem::FIELD_BLOB_HASH).GetS(); - } catch (std::out_of_range &e) { - throw std::runtime_error( - "invalid reverse index item provided, " + std::string(e.what())); - } + this->holder = itemFromDB.at(ReverseIndexItem::FIELD_HOLDER).GetS(); + this->blobHash = itemFromDB.at(ReverseIndexItem::FIELD_BLOB_HASH).GetS(); this->validate(); } std::string ReverseIndexItem::getTableName() const { return ReverseIndexItem::tableName; } std::string ReverseIndexItem::getPrimaryKey() const { return ReverseIndexItem::FIELD_HOLDER; } std::string ReverseIndexItem::getHolder() const { return this->holder; } std::string ReverseIndexItem::getBlobHash() const { return this->blobHash; } } // namespace database } // namespace network } // namespace comm diff --git a/services/tunnelbroker/docker-server/contents/server/src/Database/DeviceSessionItem.cpp b/services/tunnelbroker/docker-server/contents/server/src/Database/DeviceSessionItem.cpp index f311c6b37..f9f339933 100644 --- a/services/tunnelbroker/docker-server/contents/server/src/Database/DeviceSessionItem.cpp +++ b/services/tunnelbroker/docker-server/contents/server/src/Database/DeviceSessionItem.cpp @@ -1,113 +1,113 @@ #include "DeviceSessionItem.h" #include "ConfigManager.h" namespace comm { namespace network { namespace database { const std::string DeviceSessionItem::FIELD_SESSION_ID = "SessionId"; const std::string DeviceSessionItem::FIELD_DEVICE_ID = "DeviceId"; const std::string DeviceSessionItem::FIELD_PUBKEY = "PubKey"; const std::string DeviceSessionItem::FIELD_NOTIFY_TOKEN = "NotifyToken"; const std::string DeviceSessionItem::FIELD_DEVICE_TYPE = "DeviceType"; const std::string DeviceSessionItem::FIELD_APP_VERSION = "AppVersion"; const std::string DeviceSessionItem::FIELD_DEVICE_OS = "DeviceOS"; const std::string DeviceSessionItem::FIELD_CHECKPOINT_TIME = "CheckpointTime"; const std::string DeviceSessionItem::FIELD_EXPIRE = "Expire"; DeviceSessionItem::DeviceSessionItem( const std::string sessionId, const std::string deviceId, const std::string pubKey, const std::string notifyToken, const std::string deviceType, const std::string appVersion, const std::string deviceOs) : sessionId(sessionId), deviceId(deviceId), pubKey(pubKey), notifyToken(notifyToken), deviceType(deviceType), appVersion(appVersion), deviceOs(deviceOs) { this->validate(); } DeviceSessionItem::DeviceSessionItem(const AttributeValues &itemFromDB) { this->assignItemFromDatabase(itemFromDB); } void DeviceSessionItem::validate() const { if (!this->sessionId.size()) { throw std::runtime_error("Error: SessionId is empty."); } } void DeviceSessionItem::assignItemFromDatabase( const AttributeValues &itemFromDB) { try { this->sessionId = itemFromDB.at(DeviceSessionItem::FIELD_SESSION_ID).GetS(); this->deviceId = itemFromDB.at(DeviceSessionItem::FIELD_DEVICE_ID).GetS(); this->pubKey = itemFromDB.at(DeviceSessionItem::FIELD_PUBKEY).GetS(); this->notifyToken = itemFromDB.at(DeviceSessionItem::FIELD_NOTIFY_TOKEN).GetS(); this->deviceType = itemFromDB.at(DeviceSessionItem::FIELD_DEVICE_TYPE).GetS(); this->appVersion = itemFromDB.at(DeviceSessionItem::FIELD_APP_VERSION).GetS(); this->deviceOs = itemFromDB.at(DeviceSessionItem::FIELD_DEVICE_OS).GetS(); this->checkpointTime = std::stoll( std::string( itemFromDB.at(DeviceSessionItem::FIELD_CHECKPOINT_TIME).GetS()) .c_str()); - } catch (std::out_of_range &e) { + } catch (std::logic_error &e) { throw std::runtime_error( "Invalid device session database value " + std::string(e.what())); } this->validate(); } std::string DeviceSessionItem::getTableName() const { return config::ConfigManager::getInstance().getParameter( config::ConfigManager::OPTION_DYNAMODB_SESSIONS_TABLE); } std::string DeviceSessionItem::getPrimaryKey() const { return DeviceSessionItem::FIELD_SESSION_ID; } std::string DeviceSessionItem::getSessionId() const { return this->sessionId; } std::string DeviceSessionItem::getDeviceId() const { return this->deviceId; } std::string DeviceSessionItem::getPubKey() const { return this->pubKey; } std::string DeviceSessionItem::getNotifyToken() const { return this->notifyToken; } std::string DeviceSessionItem::getDeviceType() const { return this->deviceType; } std::string DeviceSessionItem::getAppVersion() const { return this->appVersion; } std::string DeviceSessionItem::getDeviceOs() const { return this->deviceOs; } long long DeviceSessionItem::getCheckpointTime() const { return this->checkpointTime; } } // namespace database } // namespace network } // namespace comm