fileserver/backend/model/Inode.cc

1255 lines
32 KiB
C++
Raw Normal View History

2022-08-28 15:37:09 +00:00
/**
*
* Inode.cc
* DO NOT EDIT. This file is generated by drogon_ctl
*
*/
#include "Inode.h"
2022-09-03 21:32:20 +00:00
#include "drogon/utils/Utilities.h"
2022-08-28 15:37:09 +00:00
#include <string>
using namespace drogon;
using namespace drogon::orm;
using namespace drogon_model::sqlite3;
const std::string Inode::Cols::_id = "id";
const std::string Inode::Cols::_is_file = "is_file";
const std::string Inode::Cols::_name = "name";
const std::string Inode::Cols::_parent_id = "parent_id";
const std::string Inode::Cols::_owner_id = "owner_id";
const std::string Inode::Cols::_size = "size";
2022-09-03 21:32:20 +00:00
const std::string Inode::Cols::_has_preview = "has_preview";
2022-08-28 15:37:09 +00:00
const std::string Inode::primaryKeyName = "id";
const bool Inode::hasPrimaryKey = true;
const std::string Inode::tableName = "inode";
const std::vector<typename Inode::MetaData> Inode::metaData_={
{"id","uint64_t","integer",8,1,1,1},
{"is_file","uint64_t","integer",8,0,0,1},
{"name","std::string","text",0,0,0,0},
{"parent_id","uint64_t","integer",8,0,0,0},
{"owner_id","uint64_t","integer",8,0,0,1},
2022-09-03 21:32:20 +00:00
{"size","uint64_t","integer",8,0,0,0},
{"has_preview","uint64_t","integer",8,0,0,1}
2022-08-28 15:37:09 +00:00
};
const std::string &Inode::getColumnName(size_t index) noexcept(false)
{
assert(index < metaData_.size());
return metaData_[index].colName_;
}
Inode::Inode(const Row &r, const ssize_t indexOffset) noexcept
{
if(indexOffset < 0)
{
if(!r["id"].isNull())
{
id_=std::make_shared<uint64_t>(r["id"].as<uint64_t>());
}
if(!r["is_file"].isNull())
{
isFile_=std::make_shared<uint64_t>(r["is_file"].as<uint64_t>());
}
if(!r["name"].isNull())
{
name_=std::make_shared<std::string>(r["name"].as<std::string>());
}
if(!r["parent_id"].isNull())
{
parentId_=std::make_shared<uint64_t>(r["parent_id"].as<uint64_t>());
}
if(!r["owner_id"].isNull())
{
ownerId_=std::make_shared<uint64_t>(r["owner_id"].as<uint64_t>());
}
if(!r["size"].isNull())
{
size_=std::make_shared<uint64_t>(r["size"].as<uint64_t>());
}
2022-09-03 21:32:20 +00:00
if(!r["has_preview"].isNull())
{
hasPreview_=std::make_shared<uint64_t>(r["has_preview"].as<uint64_t>());
}
2022-08-28 15:37:09 +00:00
}
else
{
size_t offset = (size_t)indexOffset;
2022-09-03 21:32:20 +00:00
if(offset + 7 > r.size())
2022-08-28 15:37:09 +00:00
{
LOG_FATAL << "Invalid SQL result for this model";
return;
}
size_t index;
index = offset + 0;
if(!r[index].isNull())
{
id_=std::make_shared<uint64_t>(r[index].as<uint64_t>());
}
index = offset + 1;
if(!r[index].isNull())
{
isFile_=std::make_shared<uint64_t>(r[index].as<uint64_t>());
}
index = offset + 2;
if(!r[index].isNull())
{
name_=std::make_shared<std::string>(r[index].as<std::string>());
}
index = offset + 3;
if(!r[index].isNull())
{
parentId_=std::make_shared<uint64_t>(r[index].as<uint64_t>());
}
index = offset + 4;
if(!r[index].isNull())
{
ownerId_=std::make_shared<uint64_t>(r[index].as<uint64_t>());
}
index = offset + 5;
if(!r[index].isNull())
{
size_=std::make_shared<uint64_t>(r[index].as<uint64_t>());
}
2022-09-03 21:32:20 +00:00
index = offset + 6;
if(!r[index].isNull())
{
hasPreview_=std::make_shared<uint64_t>(r[index].as<uint64_t>());
}
2022-08-28 15:37:09 +00:00
}
}
Inode::Inode(const Json::Value &pJson, const std::vector<std::string> &pMasqueradingVector) noexcept(false)
{
2022-09-03 21:32:20 +00:00
if(pMasqueradingVector.size() != 7)
2022-08-28 15:37:09 +00:00
{
LOG_ERROR << "Bad masquerading vector";
return;
}
if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
{
dirtyFlag_[0] = true;
if(!pJson[pMasqueradingVector[0]].isNull())
{
id_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[0]].asUInt64());
}
}
if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
{
dirtyFlag_[1] = true;
if(!pJson[pMasqueradingVector[1]].isNull())
{
isFile_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[1]].asUInt64());
}
}
if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
{
dirtyFlag_[2] = true;
if(!pJson[pMasqueradingVector[2]].isNull())
{
name_=std::make_shared<std::string>(pJson[pMasqueradingVector[2]].asString());
}
}
if(!pMasqueradingVector[3].empty() && pJson.isMember(pMasqueradingVector[3]))
{
dirtyFlag_[3] = true;
if(!pJson[pMasqueradingVector[3]].isNull())
{
parentId_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[3]].asUInt64());
}
}
if(!pMasqueradingVector[4].empty() && pJson.isMember(pMasqueradingVector[4]))
{
dirtyFlag_[4] = true;
if(!pJson[pMasqueradingVector[4]].isNull())
{
ownerId_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[4]].asUInt64());
}
}
if(!pMasqueradingVector[5].empty() && pJson.isMember(pMasqueradingVector[5]))
{
dirtyFlag_[5] = true;
if(!pJson[pMasqueradingVector[5]].isNull())
{
size_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[5]].asUInt64());
}
}
2022-09-03 21:32:20 +00:00
if(!pMasqueradingVector[6].empty() && pJson.isMember(pMasqueradingVector[6]))
{
dirtyFlag_[6] = true;
if(!pJson[pMasqueradingVector[6]].isNull())
{
hasPreview_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[6]].asUInt64());
}
}
2022-08-28 15:37:09 +00:00
}
Inode::Inode(const Json::Value &pJson) noexcept(false)
{
if(pJson.isMember("id"))
{
dirtyFlag_[0]=true;
if(!pJson["id"].isNull())
{
id_=std::make_shared<uint64_t>((uint64_t)pJson["id"].asUInt64());
}
}
if(pJson.isMember("is_file"))
{
dirtyFlag_[1]=true;
if(!pJson["is_file"].isNull())
{
isFile_=std::make_shared<uint64_t>((uint64_t)pJson["is_file"].asUInt64());
}
}
if(pJson.isMember("name"))
{
dirtyFlag_[2]=true;
if(!pJson["name"].isNull())
{
name_=std::make_shared<std::string>(pJson["name"].asString());
}
}
if(pJson.isMember("parent_id"))
{
dirtyFlag_[3]=true;
if(!pJson["parent_id"].isNull())
{
parentId_=std::make_shared<uint64_t>((uint64_t)pJson["parent_id"].asUInt64());
}
}
if(pJson.isMember("owner_id"))
{
dirtyFlag_[4]=true;
if(!pJson["owner_id"].isNull())
{
ownerId_=std::make_shared<uint64_t>((uint64_t)pJson["owner_id"].asUInt64());
}
}
if(pJson.isMember("size"))
{
dirtyFlag_[5]=true;
if(!pJson["size"].isNull())
{
size_=std::make_shared<uint64_t>((uint64_t)pJson["size"].asUInt64());
}
}
2022-09-03 21:32:20 +00:00
if(pJson.isMember("has_preview"))
{
dirtyFlag_[6]=true;
if(!pJson["has_preview"].isNull())
{
hasPreview_=std::make_shared<uint64_t>((uint64_t)pJson["has_preview"].asUInt64());
}
}
2022-08-28 15:37:09 +00:00
}
void Inode::updateByMasqueradedJson(const Json::Value &pJson,
const std::vector<std::string> &pMasqueradingVector) noexcept(false)
{
2022-09-03 21:32:20 +00:00
if(pMasqueradingVector.size() != 7)
2022-08-28 15:37:09 +00:00
{
LOG_ERROR << "Bad masquerading vector";
return;
}
if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
{
if(!pJson[pMasqueradingVector[0]].isNull())
{
id_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[0]].asUInt64());
}
}
if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
{
dirtyFlag_[1] = true;
if(!pJson[pMasqueradingVector[1]].isNull())
{
isFile_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[1]].asUInt64());
}
}
if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
{
dirtyFlag_[2] = true;
if(!pJson[pMasqueradingVector[2]].isNull())
{
name_=std::make_shared<std::string>(pJson[pMasqueradingVector[2]].asString());
}
}
if(!pMasqueradingVector[3].empty() && pJson.isMember(pMasqueradingVector[3]))
{
dirtyFlag_[3] = true;
if(!pJson[pMasqueradingVector[3]].isNull())
{
parentId_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[3]].asUInt64());
}
}
if(!pMasqueradingVector[4].empty() && pJson.isMember(pMasqueradingVector[4]))
{
dirtyFlag_[4] = true;
if(!pJson[pMasqueradingVector[4]].isNull())
{
ownerId_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[4]].asUInt64());
}
}
if(!pMasqueradingVector[5].empty() && pJson.isMember(pMasqueradingVector[5]))
{
dirtyFlag_[5] = true;
if(!pJson[pMasqueradingVector[5]].isNull())
{
size_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[5]].asUInt64());
}
}
2022-09-03 21:32:20 +00:00
if(!pMasqueradingVector[6].empty() && pJson.isMember(pMasqueradingVector[6]))
{
dirtyFlag_[6] = true;
if(!pJson[pMasqueradingVector[6]].isNull())
{
hasPreview_=std::make_shared<uint64_t>((uint64_t)pJson[pMasqueradingVector[6]].asUInt64());
}
}
2022-08-28 15:37:09 +00:00
}
void Inode::updateByJson(const Json::Value &pJson) noexcept(false)
{
if(pJson.isMember("id"))
{
if(!pJson["id"].isNull())
{
id_=std::make_shared<uint64_t>((uint64_t)pJson["id"].asUInt64());
}
}
if(pJson.isMember("is_file"))
{
dirtyFlag_[1] = true;
if(!pJson["is_file"].isNull())
{
isFile_=std::make_shared<uint64_t>((uint64_t)pJson["is_file"].asUInt64());
}
}
if(pJson.isMember("name"))
{
dirtyFlag_[2] = true;
if(!pJson["name"].isNull())
{
name_=std::make_shared<std::string>(pJson["name"].asString());
}
}
if(pJson.isMember("parent_id"))
{
dirtyFlag_[3] = true;
if(!pJson["parent_id"].isNull())
{
parentId_=std::make_shared<uint64_t>((uint64_t)pJson["parent_id"].asUInt64());
}
}
if(pJson.isMember("owner_id"))
{
dirtyFlag_[4] = true;
if(!pJson["owner_id"].isNull())
{
ownerId_=std::make_shared<uint64_t>((uint64_t)pJson["owner_id"].asUInt64());
}
}
if(pJson.isMember("size"))
{
dirtyFlag_[5] = true;
if(!pJson["size"].isNull())
{
size_=std::make_shared<uint64_t>((uint64_t)pJson["size"].asUInt64());
}
}
2022-09-03 21:32:20 +00:00
if(pJson.isMember("has_preview"))
{
dirtyFlag_[6] = true;
if(!pJson["has_preview"].isNull())
{
hasPreview_=std::make_shared<uint64_t>((uint64_t)pJson["has_preview"].asUInt64());
}
}
2022-08-28 15:37:09 +00:00
}
const uint64_t &Inode::getValueOfId() const noexcept
{
const static uint64_t defaultValue = uint64_t();
if(id_)
return *id_;
return defaultValue;
}
const std::shared_ptr<uint64_t> &Inode::getId() const noexcept
{
return id_;
}
void Inode::setId(const uint64_t &pId) noexcept
{
id_ = std::make_shared<uint64_t>(pId);
dirtyFlag_[0] = true;
}
const typename Inode::PrimaryKeyType & Inode::getPrimaryKey() const
{
assert(id_);
return *id_;
}
const uint64_t &Inode::getValueOfIsFile() const noexcept
{
const static uint64_t defaultValue = uint64_t();
if(isFile_)
return *isFile_;
return defaultValue;
}
const std::shared_ptr<uint64_t> &Inode::getIsFile() const noexcept
{
return isFile_;
}
void Inode::setIsFile(const uint64_t &pIsFile) noexcept
{
isFile_ = std::make_shared<uint64_t>(pIsFile);
dirtyFlag_[1] = true;
}
const std::string &Inode::getValueOfName() const noexcept
{
const static std::string defaultValue = std::string();
if(name_)
return *name_;
return defaultValue;
}
const std::shared_ptr<std::string> &Inode::getName() const noexcept
{
return name_;
}
void Inode::setName(const std::string &pName) noexcept
{
name_ = std::make_shared<std::string>(pName);
dirtyFlag_[2] = true;
}
void Inode::setName(std::string &&pName) noexcept
{
name_ = std::make_shared<std::string>(std::move(pName));
dirtyFlag_[2] = true;
}
void Inode::setNameToNull() noexcept
{
name_.reset();
dirtyFlag_[2] = true;
}
const uint64_t &Inode::getValueOfParentId() const noexcept
{
const static uint64_t defaultValue = uint64_t();
if(parentId_)
return *parentId_;
return defaultValue;
}
const std::shared_ptr<uint64_t> &Inode::getParentId() const noexcept
{
return parentId_;
}
void Inode::setParentId(const uint64_t &pParentId) noexcept
{
parentId_ = std::make_shared<uint64_t>(pParentId);
dirtyFlag_[3] = true;
}
void Inode::setParentIdToNull() noexcept
{
parentId_.reset();
dirtyFlag_[3] = true;
}
const uint64_t &Inode::getValueOfOwnerId() const noexcept
{
const static uint64_t defaultValue = uint64_t();
if(ownerId_)
return *ownerId_;
return defaultValue;
}
const std::shared_ptr<uint64_t> &Inode::getOwnerId() const noexcept
{
return ownerId_;
}
void Inode::setOwnerId(const uint64_t &pOwnerId) noexcept
{
ownerId_ = std::make_shared<uint64_t>(pOwnerId);
dirtyFlag_[4] = true;
}
const uint64_t &Inode::getValueOfSize() const noexcept
{
const static uint64_t defaultValue = uint64_t();
if(size_)
return *size_;
return defaultValue;
}
const std::shared_ptr<uint64_t> &Inode::getSize() const noexcept
{
return size_;
}
void Inode::setSize(const uint64_t &pSize) noexcept
{
size_ = std::make_shared<uint64_t>(pSize);
dirtyFlag_[5] = true;
}
void Inode::setSizeToNull() noexcept
{
size_.reset();
dirtyFlag_[5] = true;
}
2022-09-03 21:32:20 +00:00
const uint64_t &Inode::getValueOfHasPreview() const noexcept
{
const static uint64_t defaultValue = uint64_t();
if(hasPreview_)
return *hasPreview_;
return defaultValue;
}
const std::shared_ptr<uint64_t> &Inode::getHasPreview() const noexcept
{
return hasPreview_;
}
void Inode::setHasPreview(const uint64_t &pHasPreview) noexcept
{
hasPreview_ = std::make_shared<uint64_t>(pHasPreview);
dirtyFlag_[6] = true;
}
2022-08-28 15:37:09 +00:00
void Inode::updateId(const uint64_t id)
{
id_ = std::make_shared<uint64_t>(id);
}
const std::vector<std::string> &Inode::insertColumns() noexcept
{
static const std::vector<std::string> inCols={
"is_file",
"name",
"parent_id",
"owner_id",
2022-09-03 21:32:20 +00:00
"size",
"has_preview"
2022-08-28 15:37:09 +00:00
};
return inCols;
}
void Inode::outputArgs(drogon::orm::internal::SqlBinder &binder) const
{
if(dirtyFlag_[1])
{
if(getIsFile())
{
binder << getValueOfIsFile();
}
else
{
binder << nullptr;
}
}
if(dirtyFlag_[2])
{
if(getName())
{
binder << getValueOfName();
}
else
{
binder << nullptr;
}
}
if(dirtyFlag_[3])
{
if(getParentId())
{
binder << getValueOfParentId();
}
else
{
binder << nullptr;
}
}
if(dirtyFlag_[4])
{
if(getOwnerId())
{
binder << getValueOfOwnerId();
}
else
{
binder << nullptr;
}
}
if(dirtyFlag_[5])
{
if(getSize())
{
binder << getValueOfSize();
}
else
{
binder << nullptr;
}
}
2022-09-03 21:32:20 +00:00
if(dirtyFlag_[6])
{
if(getHasPreview())
{
binder << getValueOfHasPreview();
}
else
{
binder << nullptr;
}
}
2022-08-28 15:37:09 +00:00
}
const std::vector<std::string> Inode::updateColumns() const
{
std::vector<std::string> ret;
if(dirtyFlag_[1])
{
ret.push_back(getColumnName(1));
}
if(dirtyFlag_[2])
{
ret.push_back(getColumnName(2));
}
if(dirtyFlag_[3])
{
ret.push_back(getColumnName(3));
}
if(dirtyFlag_[4])
{
ret.push_back(getColumnName(4));
}
if(dirtyFlag_[5])
{
ret.push_back(getColumnName(5));
}
2022-09-03 21:32:20 +00:00
if(dirtyFlag_[6])
{
ret.push_back(getColumnName(6));
}
2022-08-28 15:37:09 +00:00
return ret;
}
void Inode::updateArgs(drogon::orm::internal::SqlBinder &binder) const
{
if(dirtyFlag_[1])
{
if(getIsFile())
{
binder << getValueOfIsFile();
}
else
{
binder << nullptr;
}
}
if(dirtyFlag_[2])
{
if(getName())
{
binder << getValueOfName();
}
else
{
binder << nullptr;
}
}
if(dirtyFlag_[3])
{
if(getParentId())
{
binder << getValueOfParentId();
}
else
{
binder << nullptr;
}
}
if(dirtyFlag_[4])
{
if(getOwnerId())
{
binder << getValueOfOwnerId();
}
else
{
binder << nullptr;
}
}
if(dirtyFlag_[5])
{
if(getSize())
{
binder << getValueOfSize();
}
else
{
binder << nullptr;
}
}
2022-09-03 21:32:20 +00:00
if(dirtyFlag_[6])
{
if(getHasPreview())
{
binder << getValueOfHasPreview();
}
else
{
binder << nullptr;
}
}
2022-08-28 15:37:09 +00:00
}
Json::Value Inode::toJson() const
{
Json::Value ret;
if(getId())
{
ret["id"]=(Json::UInt64)getValueOfId();
}
else
{
ret["id"]=Json::Value();
}
if(getIsFile())
{
ret["is_file"]=(Json::UInt64)getValueOfIsFile();
}
else
{
ret["is_file"]=Json::Value();
}
if(getName())
{
ret["name"]=getValueOfName();
}
else
{
ret["name"]=Json::Value();
}
if(getParentId())
{
ret["parent_id"]=(Json::UInt64)getValueOfParentId();
}
else
{
ret["parent_id"]=Json::Value();
}
if(getOwnerId())
{
ret["owner_id"]=(Json::UInt64)getValueOfOwnerId();
}
else
{
ret["owner_id"]=Json::Value();
}
if(getSize())
{
ret["size"]=(Json::UInt64)getValueOfSize();
}
else
{
ret["size"]=Json::Value();
}
2022-09-03 21:32:20 +00:00
if(getHasPreview())
{
ret["has_preview"]=(Json::UInt64)getValueOfHasPreview();
}
else
{
ret["has_preview"]=Json::Value();
}
2022-08-28 15:37:09 +00:00
return ret;
}
Json::Value Inode::toMasqueradedJson(
const std::vector<std::string> &pMasqueradingVector) const
{
Json::Value ret;
2022-09-03 21:32:20 +00:00
if(pMasqueradingVector.size() == 7)
2022-08-28 15:37:09 +00:00
{
if(!pMasqueradingVector[0].empty())
{
if(getId())
{
ret[pMasqueradingVector[0]]=(Json::UInt64)getValueOfId();
}
else
{
ret[pMasqueradingVector[0]]=Json::Value();
}
}
if(!pMasqueradingVector[1].empty())
{
if(getIsFile())
{
ret[pMasqueradingVector[1]]=(Json::UInt64)getValueOfIsFile();
}
else
{
ret[pMasqueradingVector[1]]=Json::Value();
}
}
if(!pMasqueradingVector[2].empty())
{
if(getName())
{
ret[pMasqueradingVector[2]]=getValueOfName();
}
else
{
ret[pMasqueradingVector[2]]=Json::Value();
}
}
if(!pMasqueradingVector[3].empty())
{
if(getParentId())
{
ret[pMasqueradingVector[3]]=(Json::UInt64)getValueOfParentId();
}
else
{
ret[pMasqueradingVector[3]]=Json::Value();
}
}
if(!pMasqueradingVector[4].empty())
{
if(getOwnerId())
{
ret[pMasqueradingVector[4]]=(Json::UInt64)getValueOfOwnerId();
}
else
{
ret[pMasqueradingVector[4]]=Json::Value();
}
}
if(!pMasqueradingVector[5].empty())
{
if(getSize())
{
ret[pMasqueradingVector[5]]=(Json::UInt64)getValueOfSize();
}
else
{
ret[pMasqueradingVector[5]]=Json::Value();
}
}
2022-09-03 21:32:20 +00:00
if(!pMasqueradingVector[6].empty())
{
if(getHasPreview())
{
ret[pMasqueradingVector[6]]=(Json::UInt64)getValueOfHasPreview();
}
else
{
ret[pMasqueradingVector[6]]=Json::Value();
}
}
2022-08-28 15:37:09 +00:00
return ret;
}
LOG_ERROR << "Masquerade failed";
if(getId())
{
ret["id"]=(Json::UInt64)getValueOfId();
}
else
{
ret["id"]=Json::Value();
}
if(getIsFile())
{
ret["is_file"]=(Json::UInt64)getValueOfIsFile();
}
else
{
ret["is_file"]=Json::Value();
}
if(getName())
{
ret["name"]=getValueOfName();
}
else
{
ret["name"]=Json::Value();
}
if(getParentId())
{
ret["parent_id"]=(Json::UInt64)getValueOfParentId();
}
else
{
ret["parent_id"]=Json::Value();
}
if(getOwnerId())
{
ret["owner_id"]=(Json::UInt64)getValueOfOwnerId();
}
else
{
ret["owner_id"]=Json::Value();
}
if(getSize())
{
ret["size"]=(Json::UInt64)getValueOfSize();
}
else
{
ret["size"]=Json::Value();
}
2022-09-03 21:32:20 +00:00
if(getHasPreview())
{
ret["has_preview"]=(Json::UInt64)getValueOfHasPreview();
}
else
{
ret["has_preview"]=Json::Value();
}
2022-08-28 15:37:09 +00:00
return ret;
}
bool Inode::validateJsonForCreation(const Json::Value &pJson, std::string &err)
{
if(pJson.isMember("id"))
{
if(!validJsonOfField(0, "id", pJson["id"], err, true))
return false;
}
if(pJson.isMember("is_file"))
{
if(!validJsonOfField(1, "is_file", pJson["is_file"], err, true))
return false;
}
else
{
err="The is_file column cannot be null";
return false;
}
if(pJson.isMember("name"))
{
if(!validJsonOfField(2, "name", pJson["name"], err, true))
return false;
}
if(pJson.isMember("parent_id"))
{
if(!validJsonOfField(3, "parent_id", pJson["parent_id"], err, true))
return false;
}
if(pJson.isMember("owner_id"))
{
if(!validJsonOfField(4, "owner_id", pJson["owner_id"], err, true))
return false;
}
else
{
err="The owner_id column cannot be null";
return false;
}
if(pJson.isMember("size"))
{
if(!validJsonOfField(5, "size", pJson["size"], err, true))
return false;
}
2022-09-03 21:32:20 +00:00
if(pJson.isMember("has_preview"))
{
if(!validJsonOfField(6, "has_preview", pJson["has_preview"], err, true))
return false;
}
else
{
err="The has_preview column cannot be null";
return false;
}
2022-08-28 15:37:09 +00:00
return true;
}
bool Inode::validateMasqueradedJsonForCreation(const Json::Value &pJson,
const std::vector<std::string> &pMasqueradingVector,
std::string &err)
{
2022-09-03 21:32:20 +00:00
if(pMasqueradingVector.size() != 7)
2022-08-28 15:37:09 +00:00
{
err = "Bad masquerading vector";
return false;
}
try {
if(!pMasqueradingVector[0].empty())
{
if(pJson.isMember(pMasqueradingVector[0]))
{
if(!validJsonOfField(0, pMasqueradingVector[0], pJson[pMasqueradingVector[0]], err, true))
return false;
}
}
if(!pMasqueradingVector[1].empty())
{
if(pJson.isMember(pMasqueradingVector[1]))
{
if(!validJsonOfField(1, pMasqueradingVector[1], pJson[pMasqueradingVector[1]], err, true))
return false;
}
else
{
err="The " + pMasqueradingVector[1] + " column cannot be null";
return false;
}
}
if(!pMasqueradingVector[2].empty())
{
if(pJson.isMember(pMasqueradingVector[2]))
{
if(!validJsonOfField(2, pMasqueradingVector[2], pJson[pMasqueradingVector[2]], err, true))
return false;
}
}
if(!pMasqueradingVector[3].empty())
{
if(pJson.isMember(pMasqueradingVector[3]))
{
if(!validJsonOfField(3, pMasqueradingVector[3], pJson[pMasqueradingVector[3]], err, true))
return false;
}
}
if(!pMasqueradingVector[4].empty())
{
if(pJson.isMember(pMasqueradingVector[4]))
{
if(!validJsonOfField(4, pMasqueradingVector[4], pJson[pMasqueradingVector[4]], err, true))
return false;
}
else
{
err="The " + pMasqueradingVector[4] + " column cannot be null";
return false;
}
}
if(!pMasqueradingVector[5].empty())
{
if(pJson.isMember(pMasqueradingVector[5]))
{
if(!validJsonOfField(5, pMasqueradingVector[5], pJson[pMasqueradingVector[5]], err, true))
return false;
}
}
2022-09-03 21:32:20 +00:00
if(!pMasqueradingVector[6].empty())
{
if(pJson.isMember(pMasqueradingVector[6]))
{
if(!validJsonOfField(6, pMasqueradingVector[6], pJson[pMasqueradingVector[6]], err, true))
return false;
}
else
{
err="The " + pMasqueradingVector[6] + " column cannot be null";
return false;
}
}
2022-08-28 15:37:09 +00:00
}
catch(const Json::LogicError &e)
{
err = e.what();
return false;
}
return true;
}
bool Inode::validateJsonForUpdate(const Json::Value &pJson, std::string &err)
{
if(pJson.isMember("id"))
{
if(!validJsonOfField(0, "id", pJson["id"], err, false))
return false;
}
else
{
err = "The value of primary key must be set in the json object for update";
return false;
}
if(pJson.isMember("is_file"))
{
if(!validJsonOfField(1, "is_file", pJson["is_file"], err, false))
return false;
}
if(pJson.isMember("name"))
{
if(!validJsonOfField(2, "name", pJson["name"], err, false))
return false;
}
if(pJson.isMember("parent_id"))
{
if(!validJsonOfField(3, "parent_id", pJson["parent_id"], err, false))
return false;
}
if(pJson.isMember("owner_id"))
{
if(!validJsonOfField(4, "owner_id", pJson["owner_id"], err, false))
return false;
}
if(pJson.isMember("size"))
{
if(!validJsonOfField(5, "size", pJson["size"], err, false))
return false;
}
2022-09-03 21:32:20 +00:00
if(pJson.isMember("has_preview"))
{
if(!validJsonOfField(6, "has_preview", pJson["has_preview"], err, false))
return false;
}
2022-08-28 15:37:09 +00:00
return true;
}
bool Inode::validateMasqueradedJsonForUpdate(const Json::Value &pJson,
const std::vector<std::string> &pMasqueradingVector,
std::string &err)
{
2022-09-03 21:32:20 +00:00
if(pMasqueradingVector.size() != 7)
2022-08-28 15:37:09 +00:00
{
err = "Bad masquerading vector";
return false;
}
try {
if(!pMasqueradingVector[0].empty() && pJson.isMember(pMasqueradingVector[0]))
{
if(!validJsonOfField(0, pMasqueradingVector[0], pJson[pMasqueradingVector[0]], err, false))
return false;
}
else
{
err = "The value of primary key must be set in the json object for update";
return false;
}
if(!pMasqueradingVector[1].empty() && pJson.isMember(pMasqueradingVector[1]))
{
if(!validJsonOfField(1, pMasqueradingVector[1], pJson[pMasqueradingVector[1]], err, false))
return false;
}
if(!pMasqueradingVector[2].empty() && pJson.isMember(pMasqueradingVector[2]))
{
if(!validJsonOfField(2, pMasqueradingVector[2], pJson[pMasqueradingVector[2]], err, false))
return false;
}
if(!pMasqueradingVector[3].empty() && pJson.isMember(pMasqueradingVector[3]))
{
if(!validJsonOfField(3, pMasqueradingVector[3], pJson[pMasqueradingVector[3]], err, false))
return false;
}
if(!pMasqueradingVector[4].empty() && pJson.isMember(pMasqueradingVector[4]))
{
if(!validJsonOfField(4, pMasqueradingVector[4], pJson[pMasqueradingVector[4]], err, false))
return false;
}
if(!pMasqueradingVector[5].empty() && pJson.isMember(pMasqueradingVector[5]))
{
if(!validJsonOfField(5, pMasqueradingVector[5], pJson[pMasqueradingVector[5]], err, false))
return false;
}
2022-09-03 21:32:20 +00:00
if(!pMasqueradingVector[6].empty() && pJson.isMember(pMasqueradingVector[6]))
{
if(!validJsonOfField(6, pMasqueradingVector[6], pJson[pMasqueradingVector[6]], err, false))
return false;
}
2022-08-28 15:37:09 +00:00
}
catch(const Json::LogicError &e)
{
err = e.what();
return false;
}
return true;
}
bool Inode::validJsonOfField(size_t index,
const std::string &fieldName,
const Json::Value &pJson,
std::string &err,
bool isForCreation)
{
switch(index)
{
case 0:
if(pJson.isNull())
{
err="The " + fieldName + " column cannot be null";
return false;
}
if(isForCreation)
{
err="The automatic primary key cannot be set";
return false;
}
if(!pJson.isUInt64())
{
err="Type error in the "+fieldName+" field";
return false;
}
break;
case 1:
if(pJson.isNull())
{
err="The " + fieldName + " column cannot be null";
return false;
}
if(!pJson.isUInt64())
{
err="Type error in the "+fieldName+" field";
return false;
}
break;
case 2:
if(pJson.isNull())
{
return true;
}
if(!pJson.isString())
{
err="Type error in the "+fieldName+" field";
return false;
}
break;
case 3:
if(pJson.isNull())
{
return true;
}
if(!pJson.isUInt64())
{
err="Type error in the "+fieldName+" field";
return false;
}
break;
case 4:
if(pJson.isNull())
{
err="The " + fieldName + " column cannot be null";
return false;
}
if(!pJson.isUInt64())
{
err="Type error in the "+fieldName+" field";
return false;
}
break;
case 5:
if(pJson.isNull())
{
return true;
}
if(!pJson.isUInt64())
{
err="Type error in the "+fieldName+" field";
return false;
}
break;
2022-09-03 21:32:20 +00:00
case 6:
if(pJson.isNull())
{
err="The " + fieldName + " column cannot be null";
return false;
}
if(!pJson.isUInt64())
{
err="Type error in the "+fieldName+" field";
return false;
}
break;
2022-08-28 15:37:09 +00:00
default:
err="Internal error in the server";
return false;
break;
}
return true;
}