Commit 9c8f0150 authored by Daniele Kruse's avatar Daniele Kruse
Browse files

changed common data structures from classes to plain structs

parent 0ccbdab0
......@@ -98,13 +98,13 @@ void cta::catalogue::SqliteCatalogue::createBootstrapAdminAndHostNoAuth(
SqliteStmt stmt(m_conn, sql);
const uint64_t now = time(NULL);
stmt.bind(":USER_NAME", user.getName());
stmt.bind(":GROUP_NAME", user.getGroup());
stmt.bind(":USER_NAME", user.name);
stmt.bind(":GROUP_NAME", user.group);
stmt.bind(":COMMENT", comment);
stmt.bind(":CREATOR_USER", cliIdentity.getUser().getName());
stmt.bind(":CREATOR_GROUP", cliIdentity.getUser().getGroup());
stmt.bind(":CREATOR_HOST", cliIdentity.getHost());
stmt.bind(":CREATOR_USER", cliIdentity.user.name);
stmt.bind(":CREATOR_GROUP", cliIdentity.user.group);
stmt.bind(":CREATOR_HOST", cliIdentity.host);
stmt.bind(":CREATION_TIME", now);
stmt.step();
......@@ -146,13 +146,13 @@ void cta::catalogue::SqliteCatalogue::createAdminUser(const common::dataStructur
SqliteStmt stmt(m_conn, sql);
const uint64_t now = time(NULL);
stmt.bind(":USER_NAME", user.getName());
stmt.bind(":GROUP_NAME", user.getGroup());
stmt.bind(":USER_NAME", user.name);
stmt.bind(":GROUP_NAME", user.group);
stmt.bind(":COMMENT", comment);
stmt.bind(":CREATOR_USER", cliIdentity.getUser().getName());
stmt.bind(":CREATOR_GROUP", cliIdentity.getUser().getGroup());
stmt.bind(":CREATOR_HOST", cliIdentity.getHost());
stmt.bind(":CREATOR_USER", cliIdentity.user.name);
stmt.bind(":CREATOR_GROUP", cliIdentity.user.group);
stmt.bind(":CREATOR_HOST", cliIdentity.host);
stmt.bind(":CREATION_TIME", now);
stmt.step();
......
......@@ -9,22 +9,22 @@ class cta_catalogue_SqliteCatalogueTest : public ::testing::Test {
public:
cta_catalogue_SqliteCatalogueTest() {
cta::common::dataStructures::UserIdentity user;
user.setGroup("1");
user.setName("2");
m_cliIdentity.setUser(user);
m_cliIdentity.setHost("cliIdentityHost");
user.group = "1";
user.name = "2";
m_cliIdentity.user = user;
m_cliIdentity.host = "cliIdentityHost";
cta::common::dataStructures::UserIdentity user1;
user1.setGroup("3");
user1.setName("4");
m_admin1.setUser(user1);
m_admin1.setHost("admin1Host");
user1.group = "3";
user1.name = "4";
m_admin1.user = user1;
m_admin1.host = "admin1Host";
cta::common::dataStructures::UserIdentity user2;
user2.setGroup("5");
user2.setName("6");
m_admin1.setUser(user2);
m_admin2.setHost("admin2Host");
user2.group = "5";
user2.name = "6";
m_admin2.user = user2;
m_admin2.host = "admin2Host";
}
protected:
......@@ -53,10 +53,10 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createBootstrapAdminAndHostNoAuth) {
std::unique_ptr<catalogue::Catalogue> catalogue;
ASSERT_NO_THROW(catalogue.reset(new catalogue::SqliteCatalogue()));
common::dataStructures::UserIdentity admin1User = m_admin1.getUser();
common::dataStructures::UserIdentity admin1User = m_admin1.user;
const std::string bootstrapComment = "createBootstrapAdminAndHostNoAuth";
ASSERT_NO_THROW(catalogue->createBootstrapAdminAndHostNoAuth(
m_cliIdentity, admin1User, m_admin1.getHost(), bootstrapComment));
m_cliIdentity, admin1User, m_admin1.host, bootstrapComment));
{
std::list<common::dataStructures::AdminUser> admins;
......@@ -64,16 +64,16 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createBootstrapAdminAndHostNoAuth) {
ASSERT_EQ(1, admins.size());
const common::dataStructures::AdminUser admin = admins.front();
ASSERT_EQ(bootstrapComment, admin.getComment());
ASSERT_EQ(bootstrapComment, admin.comment);
const common::dataStructures::EntryLog creationLog = admin.getCreationLog();
ASSERT_EQ(m_cliIdentity.getUser().getName(), creationLog.getUser().getName());
ASSERT_EQ(m_cliIdentity.getUser().getGroup(), creationLog.getUser().getGroup());
ASSERT_EQ(m_cliIdentity.getHost(), creationLog.getHost());
const common::dataStructures::EntryLog creationLog = admin.creationLog;
ASSERT_EQ(m_cliIdentity.user.name, creationLog.user.name);
ASSERT_EQ(m_cliIdentity.user.group, creationLog.user.group);
ASSERT_EQ(m_cliIdentity.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
admin.getLastModificationLog();
// ASSERT_EQ(creationLog, lastModificationLog);
admin.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
}
......@@ -83,10 +83,10 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createAdminUser) {
std::unique_ptr<catalogue::Catalogue> catalogue;
ASSERT_NO_THROW(catalogue.reset(new catalogue::SqliteCatalogue()));
common::dataStructures::UserIdentity admin1User = m_admin1.getUser();
common::dataStructures::UserIdentity admin1User = m_admin1.user;
const std::string bootstrapComment = "createBootstrapAdminAndHostNoAuth";
ASSERT_NO_THROW(catalogue->createBootstrapAdminAndHostNoAuth(
m_cliIdentity, admin1User, m_admin1.getHost(), bootstrapComment));
m_cliIdentity, admin1User, m_admin1.host, bootstrapComment));
{
std::list<common::dataStructures::AdminUser> admins;
......@@ -94,20 +94,20 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createAdminUser) {
ASSERT_EQ(1, admins.size());
const common::dataStructures::AdminUser admin = admins.front();
ASSERT_EQ(bootstrapComment, admin.getComment());
ASSERT_EQ(bootstrapComment, admin.comment);
const common::dataStructures::EntryLog creationLog = admin.getCreationLog();
ASSERT_EQ(m_cliIdentity.getUser().getName(), creationLog.getUser().getName());
ASSERT_EQ(m_cliIdentity.getUser().getGroup(), creationLog.getUser().getGroup());
ASSERT_EQ(m_cliIdentity.getHost(), creationLog.getHost());
const common::dataStructures::EntryLog creationLog = admin.creationLog;
ASSERT_EQ(m_cliIdentity.user.name, creationLog.user.name);
ASSERT_EQ(m_cliIdentity.user.group, creationLog.user.group);
ASSERT_EQ(m_cliIdentity.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
admin.getLastModificationLog();
// ASSERT_EQ(creationLog, lastModificationLog);
admin.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
const std::string createAdminUserComment = "createAdminUser";
common::dataStructures::UserIdentity admin2User = m_admin2.getUser();
common::dataStructures::UserIdentity admin2User = m_admin2.user;
ASSERT_NO_THROW(catalogue->createAdminUser(m_admin1, admin2User,
createAdminUserComment));
......
......@@ -36,6 +36,7 @@ set (COMMON_LIB_SRC_FILES
dataStructures/UserIdentity.cpp
dataStructures/VerifyInfo.cpp
dataStructures/WriteTestResult.cpp
dataStructures/utils.cpp
admin/AdminHost.cpp
admin/AdminUser.cpp
archiveRoutes/ArchiveRoute.cpp
......
......@@ -17,18 +17,9 @@
*/
#include "common/dataStructures/AdminHost.hpp"
#include "common/dataStructures/utils.hpp"
#include "common/exception/Exception.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::common::dataStructures::AdminHost::AdminHost() {
m_commentSet = false;
m_creationLogSet = false;
m_lastModificationLogSet = false;
m_nameSet = false;
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
......@@ -36,83 +27,30 @@ cta::common::dataStructures::AdminHost::~AdminHost() throw() {
}
//------------------------------------------------------------------------------
// allFieldsSet
//------------------------------------------------------------------------------
bool cta::common::dataStructures::AdminHost::allFieldsSet() const {
return m_commentSet
&& m_creationLogSet
&& m_lastModificationLogSet
&& m_nameSet;
}
//------------------------------------------------------------------------------
// setComment
// operator==
//------------------------------------------------------------------------------
void cta::common::dataStructures::AdminHost::setComment(const std::string &comment) {
m_comment = comment;
m_commentSet = true;
bool cta::common::dataStructures::AdminHost::operator==(const AdminHost &rhs) const {
return comment==rhs.comment
&& creationLog==rhs.creationLog
&& lastModificationLog==rhs.lastModificationLog
&& name==rhs.name;
}
//------------------------------------------------------------------------------
// getComment
// operator!=
//------------------------------------------------------------------------------
std::string cta::common::dataStructures::AdminHost::getComment() const {
if(!allFieldsSet()) {
throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the AdminHost have been set!");
}
return m_comment;
bool cta::common::dataStructures::AdminHost::operator!=(const AdminHost &rhs) const {
return !operator==(rhs);
}
//------------------------------------------------------------------------------
// setCreationLog
// operator<<
//------------------------------------------------------------------------------
void cta::common::dataStructures::AdminHost::setCreationLog(const cta::common::dataStructures::EntryLog &creationLog) {
m_creationLog = creationLog;
m_creationLogSet = true;
std::ostream &operator<<(std::ostream &os, const cta::common::dataStructures::AdminHost &obj) {
os << "(comment=" << obj.comment
<< " creationLog=" << obj.creationLog
<< " lastModificationLog=" << obj.lastModificationLog
<< " name=" << obj.name << ")";
return os;
}
//------------------------------------------------------------------------------
// getCreationLog
//------------------------------------------------------------------------------
cta::common::dataStructures::EntryLog cta::common::dataStructures::AdminHost::getCreationLog() const {
if(!allFieldsSet()) {
throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the AdminHost have been set!");
}
return m_creationLog;
}
//------------------------------------------------------------------------------
// setLastModificationLog
//------------------------------------------------------------------------------
void cta::common::dataStructures::AdminHost::setLastModificationLog(const cta::common::dataStructures::EntryLog &lastModificationLog) {
m_lastModificationLog = lastModificationLog;
m_lastModificationLogSet = true;
}
//------------------------------------------------------------------------------
// getLastModificationLog
//------------------------------------------------------------------------------
cta::common::dataStructures::EntryLog cta::common::dataStructures::AdminHost::getLastModificationLog() const {
if(!allFieldsSet()) {
throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the AdminHost have been set!");
}
return m_lastModificationLog;
}
//------------------------------------------------------------------------------
// setName
//------------------------------------------------------------------------------
void cta::common::dataStructures::AdminHost::setName(const std::string &name) {
m_name = name;
m_nameSet = true;
}
//------------------------------------------------------------------------------
// getName
//------------------------------------------------------------------------------
std::string cta::common::dataStructures::AdminHost::getName() const {
if(!allFieldsSet()) {
throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the AdminHost have been set!");
}
return m_name;
}
......@@ -29,54 +29,23 @@ namespace cta {
namespace common {
namespace dataStructures {
class AdminHost {
struct AdminHost {
public:
/**
* Constructor
*/
AdminHost();
/**
* Destructor
*/
~AdminHost() throw();
void setComment(const std::string &comment);
std::string getComment() const;
void setCreationLog(const cta::common::dataStructures::EntryLog &creationLog);
cta::common::dataStructures::EntryLog getCreationLog() const;
void setLastModificationLog(const cta::common::dataStructures::EntryLog &lastModificationLog);
cta::common::dataStructures::EntryLog getLastModificationLog() const;
void setName(const std::string &name);
std::string getName() const;
bool operator==(const AdminHost &rhs) const;
private:
/**
* @return true if all fields have been set, false otherwise
*/
bool allFieldsSet() const;
bool operator!=(const AdminHost &rhs) const;
std::string m_comment;
bool m_commentSet;
std::string comment;
cta::common::dataStructures::EntryLog creationLog;
cta::common::dataStructures::EntryLog lastModificationLog;
std::string name;
cta::common::dataStructures::EntryLog m_creationLog;
bool m_creationLogSet;
cta::common::dataStructures::EntryLog m_lastModificationLog;
bool m_lastModificationLogSet;
std::string m_name;
bool m_nameSet;
}; // class AdminHost
}; // struct AdminHost
} // namespace dataStructures
} // namespace common
} // namespace cta
std::ostream &operator<<(std::ostream &os, const cta::common::dataStructures::AdminHost &obj);
......@@ -17,18 +17,9 @@
*/
#include "common/dataStructures/AdminUser.hpp"
#include "common/dataStructures/utils.hpp"
#include "common/exception/Exception.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::common::dataStructures::AdminUser::AdminUser() {
m_commentSet = false;
m_creationLogSet = false;
m_lastModificationLogSet = false;
m_userSet = false;
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
......@@ -36,83 +27,30 @@ cta::common::dataStructures::AdminUser::~AdminUser() throw() {
}
//------------------------------------------------------------------------------
// allFieldsSet
//------------------------------------------------------------------------------
bool cta::common::dataStructures::AdminUser::allFieldsSet() const {
return m_commentSet
&& m_creationLogSet
&& m_lastModificationLogSet
&& m_userSet;
}
//------------------------------------------------------------------------------
// setComment
// operator==
//------------------------------------------------------------------------------
void cta::common::dataStructures::AdminUser::setComment(const std::string &comment) {
m_comment = comment;
m_commentSet = true;
bool cta::common::dataStructures::AdminUser::operator==(const AdminUser &rhs) const {
return comment==rhs.comment
&& creationLog==rhs.creationLog
&& lastModificationLog==rhs.lastModificationLog
&& user==rhs.user;
}
//------------------------------------------------------------------------------
// getComment
// operator!=
//------------------------------------------------------------------------------
std::string cta::common::dataStructures::AdminUser::getComment() const {
if(!allFieldsSet()) {
throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the AdminUser have been set!");
}
return m_comment;
bool cta::common::dataStructures::AdminUser::operator!=(const AdminUser &rhs) const {
return !operator==(rhs);
}
//------------------------------------------------------------------------------
// setCreationLog
// operator<<
//------------------------------------------------------------------------------
void cta::common::dataStructures::AdminUser::setCreationLog(const cta::common::dataStructures::EntryLog &creationLog) {
m_creationLog = creationLog;
m_creationLogSet = true;
std::ostream &operator<<(std::ostream &os, const cta::common::dataStructures::AdminUser &obj) {
os << "(comment=" << obj.comment
<< " creationLog=" << obj.creationLog
<< " lastModificationLog=" << obj.lastModificationLog
<< " user=" << obj.user << ")";
return os;
}
//------------------------------------------------------------------------------
// getCreationLog
//------------------------------------------------------------------------------
cta::common::dataStructures::EntryLog cta::common::dataStructures::AdminUser::getCreationLog() const {
if(!allFieldsSet()) {
throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the AdminUser have been set!");
}
return m_creationLog;
}
//------------------------------------------------------------------------------
// setLastModificationLog
//------------------------------------------------------------------------------
void cta::common::dataStructures::AdminUser::setLastModificationLog(const cta::common::dataStructures::EntryLog &lastModificationLog) {
m_lastModificationLog = lastModificationLog;
m_lastModificationLogSet = true;
}
//------------------------------------------------------------------------------
// getLastModificationLog
//------------------------------------------------------------------------------
cta::common::dataStructures::EntryLog cta::common::dataStructures::AdminUser::getLastModificationLog() const {
if(!allFieldsSet()) {
throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the AdminUser have been set!");
}
return m_lastModificationLog;
}
//------------------------------------------------------------------------------
// setUser
//------------------------------------------------------------------------------
void cta::common::dataStructures::AdminUser::setUser(const cta::common::dataStructures::UserIdentity &user) {
m_user = user;
m_userSet = true;
}
//------------------------------------------------------------------------------
// getUser
//------------------------------------------------------------------------------
cta::common::dataStructures::UserIdentity cta::common::dataStructures::AdminUser::getUser() const {
if(!allFieldsSet()) {
throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the AdminUser have been set!");
}
return m_user;
}
......@@ -30,54 +30,23 @@ namespace cta {
namespace common {
namespace dataStructures {
class AdminUser {
struct AdminUser {
public:
/**
* Constructor
*/
AdminUser();
/**
* Destructor
*/
~AdminUser() throw();
void setComment(const std::string &comment);
std::string getComment() const;
void setCreationLog(const cta::common::dataStructures::EntryLog &creationLog);
cta::common::dataStructures::EntryLog getCreationLog() const;
void setLastModificationLog(const cta::common::dataStructures::EntryLog &lastModificationLog);
cta::common::dataStructures::EntryLog getLastModificationLog() const;
void setUser(const cta::common::dataStructures::UserIdentity &user);
cta::common::dataStructures::UserIdentity getUser() const;
bool operator==(const AdminUser &rhs) const;
private:
/**
* @return true if all fields have been set, false otherwise
*/
bool allFieldsSet() const;
bool operator!=(const AdminUser &rhs) const;
std::string m_comment;
bool m_commentSet;
std::string comment;
cta::common::dataStructures::EntryLog creationLog;
cta::common::dataStructures::EntryLog lastModificationLog;
cta::common::dataStructures::UserIdentity user;
cta::common::dataStructures::EntryLog m_creationLog;
bool m_creationLogSet;
cta::common::dataStructures::EntryLog m_lastModificationLog;
bool m_lastModificationLogSet;
cta::common::dataStructures::UserIdentity m_user;
bool m_userSet;
}; // class AdminUser
}; // struct AdminUser
} // namespace dataStructures
} // namespace common
} // namespace cta
std::ostream &operator<<(std::ostream &os, const cta::common::dataStructures::AdminUser &obj);
......@@ -17,22 +17,9 @@
*/
#include "common/dataStructures/ArchiveFile.hpp"
#include "common/dataStructures/utils.hpp"
#include "common/exception/Exception.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::common::dataStructures::ArchiveFile::ArchiveFile() {
m_archiveFileIDSet = false;
m_checksumTypeSet = false;
m_checksumValueSet = false;
m_drDataSet = false;
m_eosFileIDSet = false;
m_fileSizeSet = false;
m_storageClassSet = false;
m_tapeCopiesSet = false;
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
......@@ -40,159 +27,38 @@ cta::common::dataStructures::ArchiveFile::~ArchiveFile() throw() {
}
//------------------------------------------------------------------------------
// allFieldsSet
//------------------------------------------------------------------------------
bool cta::common::dataStructures::ArchiveFile::allFieldsSet() const {
return m_archiveFileIDSet
&& m_checksumTypeSet
&& m_checksumValueSet
&& m_drDataSet
&& m_eosFileIDSet
&& m_fileSizeSet
&& m_storageClassSet
&& m_tapeCopiesSet;
}
//------------------------------------------------------------------------------
// setArchiveFileID
//------------------------------------------------------------------------------
void cta::common::dataStructures::ArchiveFile::setArchiveFileID(const uint64_t archiveFileID) {
m_archiveFileID = archiveFileID;
m_archiveFileIDSet = true;
}
//------------------------------------------------------------------------------
// getArchiveFileID
//------------------------------------------------------------------------------
uint64_t cta::common::dataStructures::ArchiveFile::getArchiveFileID() const {
if(!allFieldsSet()) {
throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the ArchiveFile have been set!");
}
return m_archiveFileID;
}
//------------------------------------------------------------------------------
// setChecksumType
//------------------------------------------------------------------------------
void cta::common::dataStructures::ArchiveFile::setChecksumType(const std::string &checksumType) {
m_checksumType = checksumType;
m_checksumTypeSet = true;
}