summaryrefslogtreecommitdiffstats
path: root/src/modules/UserListManager/Util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/UserListManager/Util.cpp')
-rw-r--r--src/modules/UserListManager/Util.cpp83
1 files changed, 63 insertions, 20 deletions
diff --git a/src/modules/UserListManager/Util.cpp b/src/modules/UserListManager/Util.cpp
index f9b6a55..9b986d8 100644
--- a/src/modules/UserListManager/Util.cpp
+++ b/src/modules/UserListManager/Util.cpp
@@ -19,6 +19,7 @@
#include "Util.h"
#include "UserList.h"
+#include "UserListDiff.h"
#include <Common/XmlData.h>
@@ -26,19 +27,34 @@ namespace Mad {
namespace Modules {
namespace UserListManager {
-void Util::serializeUserList(const UserList *list, Common::XmlData *data) {
- Common::XmlData::List *userList = data->createList("users");
+void Util::serializeUserListEntry(const UserListEntry *user, Common::XmlData::List::iterator entry) {
+ std::set<std::string> details = user->getDetailList();
+ for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail)
+ entry->set(*detail, user->getDetail(*detail));
+
+ entry->set("name", user->getName());
+ entry->set("group", user->getGroup());
+}
- for(UserList::const_iterator user = list->begin(); user != list->end(); ++user) {
- Common::XmlData::List::iterator entry = userList->addEntry();
+UserListEntry Util::deserializeUserListEntry(Common::XmlData::List::const_iterator entry) {
+ UserListEntry user(entry->get<const std::string&>("name"), entry->get<const std::string&>("group"));
- std::set<std::string> details = user->getDetailList();
- for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail)
- entry->set(*detail, user->getDetail(*detail));
+ std::set<std::string> details = entry->getChildren();
+ for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail) {
+ if(*detail == "user" || *detail == "group")
+ continue;
- entry->set("name", user->getName());
- entry->set("group", user->getGroup());
+ user.setDetail(*detail, entry->get<const std::string&>(*detail));
}
+
+ return user;
+}
+
+void Util::serializeUserList(const UserList *list, Common::XmlData *data) {
+ Common::XmlData::List *userList = data->createList("users");
+
+ for(UserList::const_iterator user = list->begin(); user != list->end(); ++user)
+ serializeUserListEntry(&*user, userList->addEntry());
}
boost::shared_ptr<UserList> Util::deserializeUserList(const Common::XmlData *data) {
@@ -47,22 +63,49 @@ boost::shared_ptr<UserList> Util::deserializeUserList(const Common::XmlData *dat
const Common::XmlData::List *userList = data->getList("users");
if(userList) {
- for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) {
- UserListEntry entry(user->get<const std::string&>("name"), user->get<const std::string&>("group"));
+ for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user)
+ users->push_back(deserializeUserListEntry(user));
+ }
- std::set<std::string> details = user->getChildren();
- for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail) {
- if(*detail == "user" || *detail == "group")
- continue;
+ return users;
+}
- entry.setDetail(*detail, user->get<const std::string&>(*detail));
- }
+void Util::serializeUserListDiff(const UserListDiff *diff, Common::XmlData *data) {
+ Common::XmlData::List *userList = data->createList("addedUsers");
+ for(std::set<UserListEntry>::const_iterator user = diff->getAddedUsers().begin(); user != diff->getAddedUsers().end(); ++user)
+ serializeUserListEntry(&*user, userList->addEntry());
- users->push_back(entry);
- }
+ userList = data->createList("deletedUsers");
+ for(std::set<UserListEntry>::const_iterator user = diff->getDeletedUsers().begin(); user != diff->getDeletedUsers().end(); ++user)
+ serializeUserListEntry(&*user, userList->addEntry());
+
+ userList = data->createList("unchangedUsers");
+ for(std::set<UserListEntry>::const_iterator user = diff->getUnchangedUsers().begin(); user != diff->getUnchangedUsers().end(); ++user)
+ serializeUserListEntry(&*user, userList->addEntry());
+}
+
+boost::shared_ptr<UserListDiff> Util::deserializeUserListDiff(const Common::XmlData *data) {
+ boost::shared_ptr<UserListDiff> diff(new UserListDiff);
+
+ const Common::XmlData::List *userList = data->getList("addedUsers");
+ if(userList) {
+ for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user)
+ diff->insertAddedUser(deserializeUserListEntry(user));
}
- return users;
+ userList = data->getList("deletedUsers");
+ if(userList) {
+ for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user)
+ diff->insertDeletedUser(deserializeUserListEntry(user));
+ }
+
+ userList = data->getList("unchangedUsers");
+ if(userList) {
+ for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user)
+ diff->insertUnchangedUser(deserializeUserListEntry(user));
+ }
+
+ return diff;
}
}