00001
00002
00003 #include "Role.h"
00004
00005 #include <sstream>
00006
00007 using namespace Yosokumo;
00008
00009
00010
00011 Role::Role() :
00012 userIdentifier(""),
00013 userName(""),
00014 studyIdentifier(""),
00015 studyName(""),
00016 roleLocation("")
00017 {
00018 privilegeSet.reset();
00019 }
00020
00021 Role::Role(
00022 const std::string &userIdentifier,
00023 const std::string &studyIdentifier) :
00024 userIdentifier(userIdentifier),
00025 userName(""),
00026 studyIdentifier(studyIdentifier),
00027 studyName(""),
00028 roleLocation("")
00029 {
00030 privilegeSet.reset();
00031 }
00032
00033 Role::Role(const Role &rhs)
00034 {
00035 operator=(rhs);
00036 }
00037
00038 Role::~Role()
00039 {}
00040
00041 Role &Role::operator=(const Role& rhs)
00042 {
00043 if (this == &rhs)
00044 return *this;
00045
00046 userIdentifier = rhs.userIdentifier ;
00047 userName = rhs.userName ;
00048 studyIdentifier = rhs.studyIdentifier;
00049 studyName = rhs.studyName ;
00050 roleLocation = rhs.roleLocation ;
00051
00052 privilegeSet = rhs.privilegeSet;
00053
00054 return *this;
00055 }
00056
00057
00058
00059
00060 bool Role::operator==(const Role &rhs) const
00061 {
00062 return
00063 (
00064 userIdentifier == rhs.userIdentifier &&
00065 userName == rhs.userName &&
00066 studyIdentifier == rhs.studyIdentifier&&
00067 studyName == rhs.studyName &&
00068 roleLocation == rhs.roleLocation &&
00069 privilegeSet == rhs.privilegeSet
00070 );
00071 }
00072
00073 bool Role::operator!=(const Role &rhs) const
00074 {
00075 return !(*this == rhs);
00076 }
00077
00078
00079
00080
00081 Role &Role::setRoleLocation(const std::string &loc)
00082 {
00083 roleLocation = loc;
00084 return *this;
00085 }
00086
00087 std::string Role::getRoleLocation() const
00088 {
00089 return roleLocation;
00090 }
00091
00092 Role &Role::setUserIdentifier(const std::string &userIdentifier)
00093 {
00094 this->userIdentifier = userIdentifier;
00095 return *this;
00096 }
00097
00098 std::string Role::getUserIdentifier() const
00099 {
00100 return userIdentifier;
00101 }
00102
00103 Role &Role::setUserName(const std::string &name)
00104 {
00105 userName = name;
00106 return *this;
00107 }
00108
00109 std::string Role::getUserName() const
00110 {
00111 return userName;
00112 }
00113
00114 Role &Role::setStudyIdentifier(const std::string &studyIdentifier)
00115 {
00116 this->studyIdentifier = studyIdentifier;
00117 return *this;
00118 }
00119
00120 std::string Role::getStudyIdentifier() const
00121 {
00122 return studyIdentifier;
00123 }
00124
00125 Role &Role::setStudyName(const std::string &name)
00126 {
00127 studyName = name;
00128 return *this;
00129 }
00130
00131 std::string Role::getStudyName() const
00132 {
00133 return studyName;
00134 }
00135
00136
00137
00138
00139 Role &Role::addPrivilege(Privilege privilege)
00140 {
00141 privilegeSet.set(privilege.getNumber()-1, true);
00142
00143 return *this;
00144 }
00145
00146 Role &Role::removePrivilege(Privilege privilege)
00147 {
00148 privilegeSet.reset(privilege.getNumber()-1);
00149
00150 return *this;
00151 }
00152
00153 Role &Role::addAllPrivileges()
00154 {
00155 privilegeSet.set();
00156
00157 return *this;
00158 }
00159
00160 Role &Role::removeAllPrivileges()
00161 {
00162 privilegeSet.reset();
00163
00164 return *this;
00165 }
00166
00167 bool Role::getPrivilege(Privilege privilege) const
00168 {
00169 return privilegeSet.test(privilege.getNumber()-1);
00170 }
00171
00172
00173
00174
00175 std::string Role::toString() const
00176 {
00177 return toStringInternal(false);
00178 }
00179
00180 std::string Role::toStringInternal(bool showAll) const
00181 {
00182 std::stringstream s;
00183
00184 s <<
00185 "Role:" << "\n" <<
00186 " userIdentifier = " << getUserIdentifier() << "\n" <<
00187 " userName = " << getUserName() << "\n" <<
00188 "\n" <<
00189 " studyIdentifier = " << getStudyIdentifier() << "\n" <<
00190 " studyName = " << getStudyName() << "\n"
00191 ;
00192
00193 if (showAll)
00194 s <<
00195 "\n" <<
00196 " roleLocation = " << getRoleLocation() << "\n"
00197 ;
00198
00199 s <<
00200 "\n" <<
00201 " privilegeSet" << "\n"
00202 ;
00203
00204 for (int i = 1; i <= Privilege::NUMBER_OF_PRIVILEGES; ++i)
00205 {
00206 Privilege privilege = Privilege::valueOf(i);
00207
00208 s << " ";
00209 s << (getPrivilege(privilege) ? "yes " : "no ");
00210 s << privilege.getName();
00211 s << "\n";
00212 }
00213
00214 return s.str();
00215 }
00216
00217