diff --git a/libs/client/ClientAPI.hpp b/libs/client/ClientAPI.hpp index 92a967c346c708bf1344b502049917a18f5ca3fe..b6870ee72d6820705ef25e67ad469d68d143676e 100644 --- a/libs/client/ClientAPI.hpp +++ b/libs/client/ClientAPI.hpp @@ -27,22 +27,22 @@ public: * * @param requester The identity of the user requesting the creation of the * administrator. - * @param admin The identity of the administrator. + * @param adminUser The identity of the administrator. */ virtual void createAdminUser( const UserIdentity &requester, - const UserIdentity &admin) = 0; + const UserIdentity &adminUser) = 0; /** * Deletes the specified administrator. * * @param requester The identity of the user requesting the deletion of the * administrator. - * @param admin The identity of the administrator. + * @param adminUser The identity of the administrator. */ virtual void deleteAdminUser( const UserIdentity &requester, - const UserIdentity &admin) = 0; + const UserIdentity &adminUser) = 0; /** * Returns the current list of administrators. diff --git a/libs/client/MockClientAPI.cpp b/libs/client/MockClientAPI.cpp index f39d9e8ffe0bdadaf7b1516a22ac573e9b24c41d..59058b16ebd90da258eb99fae8a4834f878b5c5a 100644 --- a/libs/client/MockClientAPI.cpp +++ b/libs/client/MockClientAPI.cpp @@ -20,7 +20,25 @@ cta::MockClientAPI::~MockClientAPI() throw() { //------------------------------------------------------------------------------ void cta::MockClientAPI::createAdminUser( const UserIdentity &requester, - const UserIdentity &admin) { + const UserIdentity &adminUser) { + checkAdminUserDoesNotAlreadyExist(adminUser); + m_adminUsers.push_back(adminUser); +} + +//------------------------------------------------------------------------------ +// checkAdminUserDoesNotAlreadyExist +//------------------------------------------------------------------------------ +void cta::MockClientAPI::checkAdminUserDoesNotAlreadyExist( + const UserIdentity &adminUser) { + for(std::list<UserIdentity>::const_iterator itor = m_adminUsers.begin(); + itor != m_adminUsers.end(); itor++) { + if(adminUser.uid == itor->uid) { + std::ostringstream message; + message << "Administrator with uid " << adminUser.uid << + " already exists"; + throw(Exception(message.str())); + } + } } //------------------------------------------------------------------------------ @@ -28,7 +46,19 @@ void cta::MockClientAPI::createAdminUser( //------------------------------------------------------------------------------ void cta::MockClientAPI::deleteAdminUser( const UserIdentity &requester, - const UserIdentity &admin) { + const UserIdentity &adminUser) { + for(std::list<UserIdentity>::iterator itor = m_adminUsers.begin(); + itor != m_adminUsers.end(); itor++) { + if(adminUser.uid == itor->uid) { + m_adminUsers.erase(itor); + return; + } + } + + // Reaching this point means the administrator to be deleted does not exist + std::ostringstream message; + message << "Administration with uid " << adminUser.uid << " does not exist"; + throw Exception(message.str()); } //------------------------------------------------------------------------------ @@ -45,6 +75,23 @@ std::list<cta::UserIdentity> cta::MockClientAPI::getAdminUsers( void cta::MockClientAPI::createAdminHost( const UserIdentity &requester, const std::string &adminHost) { + checkAdminHostDoesNotAlreadyExist(adminHost); + m_adminHosts.push_back(adminHost); +} + +//------------------------------------------------------------------------------ +// checkAdminHostDoesNotAlreadyExist +//------------------------------------------------------------------------------ +void cta::MockClientAPI::checkAdminHostDoesNotAlreadyExist( + const std::string &adminHost) { + for(std::list<std::string>::const_iterator itor = m_adminHosts.begin(); + itor != m_adminHosts.end(); itor++) { + if(adminHost == *itor) { + std::ostringstream message; + message << "Administration host " << adminHost << " already exists"; + throw(Exception(message.str())); + } + } } //------------------------------------------------------------------------------ @@ -53,6 +100,19 @@ void cta::MockClientAPI::createAdminHost( void cta::MockClientAPI::deleteAdminHost( const UserIdentity &requester, const std::string &adminHost) { + for(std::list<std::string>::iterator itor = m_adminHosts.begin(); + itor != m_adminHosts.end(); itor++) { + if(adminHost == *itor) { + m_adminHosts.erase(itor); + return; + } + } + + // Reaching this point means the administration host to be deleted does not + // exist + std::ostringstream message; + message << "Administration host " << adminHost << " does not exist"; + throw Exception(message.str()); } //------------------------------------------------------------------------------ diff --git a/libs/client/MockClientAPI.hpp b/libs/client/MockClientAPI.hpp index 324e8482d976bca6d045b5a41518f0f3c6541c35..a3cc345a1eb39e72593e2a1bb4a5726634e2ad9a 100644 --- a/libs/client/MockClientAPI.hpp +++ b/libs/client/MockClientAPI.hpp @@ -27,22 +27,22 @@ public: * * @param requester The identity of the user requesting the creation of the * administrator. - * @param admin The identity of the administrator. + * @param adminUser The identity of the administrator. */ void createAdminUser( const UserIdentity &requester, - const UserIdentity &admin); + const UserIdentity &adminUser); /** * Deletes the specified administrator. * * @param requester The identity of the user requesting the deletion of the * administrator. - * @param admin The identity of the administrator. + * @param adminUser The identity of the administrator. */ void deleteAdminUser( const UserIdentity &requester, - const UserIdentity &admin); + const UserIdentity &adminUser); /** * Returns the current list of administrators. @@ -177,6 +177,20 @@ protected: */ std::map<std::string, StorageClass> m_storageClasses; + /** + * Throws an exception if the specified administrator already exists. + * + * @param adminUser The identity of the administrator. + */ + void checkAdminUserDoesNotAlreadyExist(const UserIdentity &adminUser); + + /** + * Throws an exception if the specified administration host already exists. + * + * @param adminHost The network name of the administration host. + */ + void checkAdminHostDoesNotAlreadyExist(const std::string &adminHost); + /** * Throws an exception if the specified storage class already exists. *