indexing description: "API interface for community services" author: "Marco Zietzling " date: "$Date$" revision: "$Revision$" class COMMUNITY_SERVICE inherit API_SERVICE create make feature -- Basic operations community_list (a_session: STRING): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List all available communities. local l_msg: O_COMMUNITY_LIST_MESSAGE l_reply: O_COMMUNITY_LIST_REPLY_MESSAGE l_community_list: DS_ARRAYED_LIST [STRING] l_cursor: DS_ARRAYED_LIST_CURSOR [STRING] l_community: DS_HASH_TABLE [ANY, STRING] i: INTEGER do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session else -- generate and send message create l_msg.make (a_session) send_and_wait_for_reply (l_msg) if is_ok then l_reply ?= last_reply check valid_reply: l_reply /= Void end l_community_list := l_reply.community_list l_cursor := l_community_list.new_cursor create Result.make (0, l_community_list.count-1) from l_cursor.start i := 0 until l_cursor.after loop create l_community.make (1) l_community.force (l_cursor.item, "name") Result.force (l_community, i) i := i + 1 l_cursor.forth end end end end community_retrieve (a_session: STRING; a_community_name: STRING): DS_HASH_TABLE [ANY, STRING] is -- Retrieve all informations for a community. local l_msg: O_COMMUNITY_RETRIEVE_MESSAGE l_reply: O_COMMUNITY_RETRIEVE_REPLY_MESSAGE l_cid_ref: INTEGER_REF do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community_name = Void or else a_community_name.is_empty then last_fault := err_invalid_community else -- generate and send message create l_msg.make (a_session, a_community_name) send_and_wait_for_reply (l_msg) if is_ok then l_reply ?= last_reply check valid_reply: l_reply /= Void end create l_cid_ref l_cid_ref.set_item (l_reply.community_id) create Result.make (5) Result.force (l_cid_ref, "community_id") Result.force (l_reply.name, "name") Result.force (l_reply.description, "description") Result.force (l_reply.logo, "logo") end end end community_create (a_session: STRING; a_name: STRING; a_description: STRING): BOOLEAN_REF is -- Create a new community. local l_msg: O_COMMUNITY_CREATE_MESSAGE do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif not is_valid_community (a_name) then last_fault := err_invalid_name elseif a_description = Void or else a_description.is_empty then last_fault := err_invalid_description else -- generate and send message create l_msg.make (a_session, a_name, a_description) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end community_change_group (a_session: STRING; a_community_name: STRING; a_user_name: STRING; an_access_group: INTEGER_REF): BOOLEAN_REF is -- Change access group of a_user in a_community_name to an_access_group (0=no rights, 6=administrator, 7=member) local l_msg: O_COMMUNITY_CHANGE_GROUP_MESSAGE do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif not is_valid_name (a_user_name) then last_fault := err_invalid_user elseif a_community_name = Void or else a_community_name.is_empty then last_fault := err_invalid_community elseif not (an_access_group.item = 0 or else an_access_group.item = 6 or else an_access_group.item = 7) then last_fault := err_invalid_group else -- generate and send message create l_msg.make (a_session, a_community_name, a_user_name, an_access_group.item) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end community_list_members (a_session: STRING; a_community_name: STRING; an_access_group: INTEGER_REF): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List all users that are in a_group for a community. local l_msg: O_COMMUNITY_LIST_MEMBERS_MESSAGE l_reply: O_USER_LIST_MESSAGE l_user_list: HASH_TABLE [STRING, INTEGER] l_user: DS_HASH_TABLE [ANY, STRING] i: INTEGER do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community_name = Void or else a_community_name.is_empty then last_fault := err_invalid_community elseif not (an_access_group = 6 or else an_access_group = 7) then last_fault := err_invalid_group else create l_msg.make (a_session, a_community_name, an_access_group) send_and_wait_for_reply (l_msg) if is_ok then l_reply ?= last_reply check valid_reply: l_reply /= Void end l_user_list := l_reply.user_list create Result.make (0, l_user_list.count - 1) from l_user_list.start i := 0 until l_user_list.after loop create l_user.make (1) l_user.force (l_user_list.item_for_iteration, "name") Result.force (l_user, i) i := i + 1 l_user_list.forth end end end end community_list_projects (a_session: STRING; a_community_name: STRING): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List all projects that are associated with a community. local l_msg: O_COMMUNITY_LIST_PROJECTS_MESSAGE l_reply: O_PROJECT_LIST_MESSAGE l_project_list: HASH_TABLE [STRING, INTEGER] l_project: DS_HASH_TABLE [ANY, STRING] i: INTEGER do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community_name = Void or else a_community_name.is_empty then last_fault := err_invalid_community else create l_msg.make (a_session, a_community_name) send_and_wait_for_reply (l_msg) if is_ok then l_reply ?= last_reply check valid_reply: l_reply /= Void end l_project_list := l_reply.project_list create Result.make (0, l_project_list.count - 1) from l_project_list.start i := 0 until l_project_list.after loop create l_project.make (1) l_project.force (l_project_list.item_for_iteration, "name") Result.force (l_project, i) i := i + 1 l_project_list.forth end end end end community_add_project (a_session: STRING; a_community: STRING; a_project: STRING): BOOLEAN_REF is -- Add a project to a community local l_msg: O_COMMUNITY_ADD_PROJECT_MESSAGE do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community = Void or else a_community.is_empty then last_fault := err_invalid_community elseif a_project = Void or else a_project.is_empty then last_fault := err_invalid_project else -- generate and send message create l_msg.make (a_session, a_community, a_project) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end community_remove_project (a_session: STRING; a_community: STRING; a_project: STRING): BOOLEAN_REF is -- Remove a project from a community local l_msg: O_COMMUNITY_REMOVE_PROJECT_MESSAGE do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community = Void or else a_community.is_empty then last_fault := err_invalid_community elseif a_project = Void or else a_project.is_empty then last_fault := err_invalid_project else -- generate and send message create l_msg.make (a_session, a_community, a_project) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end community_delete (a_session: STRING; a_community: STRING): BOOLEAN_REF is -- Delete an entire community. local l_msg: O_COMMUNITY_DELETE_MESSAGE do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community = Void or else a_community.is_empty then last_fault := err_invalid_community else -- generate and send message create l_msg.make (a_session, a_community) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end community_change_description (a_session: STRING; a_community_name: STRING; a_description: STRING): BOOLEAN_REF is -- Change description of a community. local l_msg: O_COMMUNITY_CHANGE_DESCRIPTION_MESSAGE do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community_name = Void or else a_community_name.is_empty then last_fault := err_invalid_community elseif a_description = Void or else a_description.is_empty then last_fault := err_invalid_description else -- generate and send message create l_msg.make (a_session, a_community_name, a_description) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end community_list_wiki_pages (a_session: STRING; a_community_name: STRING): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List all wiki pages of a community. local l_msg: O_COMMUNITY_LIST_WIKI_PAGES_MESSAGE l_reply: O_COMMUNITY_LIST_WIKI_PAGES_REPLY_MESSAGE l_wiki_list: DS_ARRAYED_LIST [STRING] l_wiki: DS_HASH_TABLE [ANY, STRING] i: INTEGER do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community_name = Void or else a_community_name.is_empty then last_fault := err_invalid_community else create l_msg.make (a_session, a_community_name) send_and_wait_for_reply (l_msg) if is_ok then l_reply ?= last_reply check valid_reply: l_reply /= Void end l_wiki_list := l_reply.wiki_list create Result.make (0, l_wiki_list.count - 1) from l_wiki_list.start i := 0 until l_wiki_list.after loop create l_wiki.make (1) l_wiki.force (l_wiki_list.item_for_iteration, "title") Result.force (l_wiki, i) i := i + 1 l_wiki_list.forth end end end end community_retrieve_wiki_page (a_session: STRING; a_community_name: STRING; a_wiki_title: STRING): DS_HASH_TABLE [ANY, STRING] is -- Retrieve a wiki page for a community. local l_msg: O_COMMUNITY_RETRIEVE_WIKI_PAGE_MESSAGE l_reply: O_COMMUNITY_RETRIEVE_WIKI_PAGE_REPLY_MESSAGE l_private_ref: BOOLEAN_REF do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community_name = Void or else a_community_name.is_empty then last_fault := err_invalid_community elseif a_wiki_title = Void or else a_wiki_title.is_empty then last_fault := err_invalid_wiki_title else -- generate and send message create l_msg.make (a_session, a_community_name, a_wiki_title) send_and_wait_for_reply (l_msg) if is_ok then l_reply ?= last_reply check valid_reply: l_reply /= Void end create l_private_ref l_private_ref.set_item (l_reply.private) create Result.make (3) Result.force (l_reply.title, "title") Result.force (l_reply.text, "text") Result.force (l_private_ref, "is_private") end end end community_add_wiki_page (a_session: STRING; a_community_name: STRING; a_title: STRING; a_text: STRING; a_private: BOOLEAN_REF): BOOLEAN_REF is -- Add a new wiki page to a community. local l_msg: O_COMMUNITY_ADD_WIKI_PAGE_MESSAGE do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community_name = Void or else a_community_name.is_empty then last_fault := err_invalid_community elseif not is_valid_wiki_title (a_title) then last_fault := err_invalid_wiki_title elseif a_text = Void then last_fault := err_invalid_wiki_text else -- generate and send message create l_msg.make (a_session, a_community_name, a_title, a_text, a_private) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end community_edit_wiki_page (a_session: STRING; a_community_name: STRING; a_title: STRING; a_text: STRING; a_private: BOOLEAN_REF): BOOLEAN_REF is -- Edit a wiki page of a community. local l_msg: O_COMMUNITY_EDIT_WIKI_PAGE_MESSAGE do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community_name = Void or else a_community_name.is_empty then last_fault := err_invalid_community elseif not is_valid_wiki_title (a_title) then last_fault := err_invalid_wiki_title elseif a_text = Void then last_fault := err_invalid_wiki_text else -- generate and send message create l_msg.make (a_session, a_community_name, a_title, a_text, a_private) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end community_rename_wiki_page (a_session: STRING; a_community_name: STRING; an_old_title: STRING; a_new_title: STRING): BOOLEAN_REF is -- Rename a wiki page of a community. local l_msg: O_COMMUNITY_RENAME_WIKI_PAGE_MESSAGE do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community_name = Void or else a_community_name.is_empty then last_fault := err_invalid_community elseif not is_valid_wiki_title (an_old_title) then last_fault := err_invalid_wiki_title elseif not is_valid_wiki_title (a_new_title) then last_fault := err_invalid_wiki_title else -- generate and send message create l_msg.make (a_session, a_community_name, an_old_title, a_new_title) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end community_delete_wiki_page (a_session: STRING; a_community_name: STRING; a_title: STRING): BOOLEAN_REF is -- Delete a wiki page of a community. local l_msg: O_COMMUNITY_DELETE_WIKI_PAGE_MESSAGE do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_community_name = Void or else a_community_name.is_empty then last_fault := err_invalid_community elseif not is_valid_wiki_title (a_title) then last_fault := err_invalid_wiki_title else -- generate and send message create l_msg.make (a_session, a_community_name, a_title) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end feature -- Creation new_tuple (a_name: STRING): TUPLE is -- Tuple of default-valued arguments to pass to call `a_name'. do if a_name.is_equal (community_list_name) then create {TUPLE [STRING]}Result elseif a_name.is_equal (community_retrieve_name) then create {TUPLE [STRING, STRING]}Result elseif a_name.is_equal (community_create_name) then create {TUPLE [STRING, STRING, STRING]}Result elseif a_name.is_equal (community_change_group_name) then create {TUPLE [STRING, STRING, STRING, INTEGER_REF]}Result elseif a_name.is_equal (community_list_members_name) then create {TUPLE [STRING, STRING, INTEGER_REF]}Result elseif a_name.is_equal (community_list_projects_name) then create {TUPLE [STRING, STRING]}Result elseif a_name.is_equal (community_add_project_name) then create {TUPLE [STRING, STRING, STRING]}Result elseif a_name.is_equal (community_remove_project_name) then create {TUPLE [STRING, STRING, STRING]}Result elseif a_name.is_equal (community_delete_name) then create {TUPLE [STRING, STRING]}Result elseif a_name.is_equal (community_change_description_name) then create {TUPLE [STRING, STRING, STRING]}Result elseif a_name.is_equal (community_list_wiki_pages_name) then create {TUPLE [STRING, STRING]}Result elseif a_name.is_equal (community_retrieve_wiki_page_name) then create {TUPLE [STRING, STRING, STRING]}Result elseif a_name.is_equal (community_add_wiki_page_name) then create {TUPLE [STRING, STRING, STRING, STRING, BOOLEAN_REF]}Result elseif a_name.is_equal (community_edit_wiki_page_name) then create {TUPLE [STRING, STRING, STRING, STRING, BOOLEAN_REF]}Result elseif a_name.is_equal (community_rename_wiki_page_name) then create {TUPLE [STRING, STRING, STRING, STRING]}Result elseif a_name.is_equal (community_delete_wiki_page_name) then create {TUPLE [STRING, STRING, STRING]}Result end end feature -- Initialisation self_register is -- Register all actions for this service do register_with_help (agent community_list, community_list_name, "List all communities.") register_with_help (agent community_retrieve, community_retrieve_name, "Retrieve informations for a community.") register_with_help (agent community_create, community_create_name, "Create a community.") register_with_help (agent community_change_group, community_change_group_name, "Change access group of user in community to access_group (0=no rights, 6=administrator, 7=member).") register_with_help (agent community_list_members, community_list_members_name, "List all members of a community with access group (6 = community admin, 7 = community member).") register_with_help (agent community_list_projects, community_list_projects_name, "List all projects associated with a community.") register_with_help (agent community_add_project, community_add_project_name, "Add a project to a community.") register_with_help (agent community_remove_project, community_remove_project_name, "Remove a project from a community.") register_with_help (agent community_delete, community_delete_name, "Delete a community.") register_with_help (agent community_change_description, community_change_description_name, "Change description of a community.") register_with_help (agent community_list_wiki_pages, community_list_wiki_pages_name, "List all wiki pages of a community.") register_with_help (agent community_retrieve_wiki_page, community_retrieve_wiki_page_name, "Retrieve a wiki page of a community.") register_with_help (agent community_add_wiki_page, community_add_wiki_page_name, "Add a wiki page to a community.") register_with_help (agent community_edit_wiki_page, community_edit_wiki_page_name, "Edit a wiki page of a community.") register_with_help (agent community_rename_wiki_page, community_rename_wiki_page_name, "Rename a wiki page of a community.") register_with_help (agent community_delete_wiki_page, community_delete_wiki_page_name, "Delete a wiki page of a community.") end feature {NONE} -- Implementation community_list_name: STRING is "list" community_retrieve_name: STRING is "retrieve" community_create_name: STRING is "create" community_change_group_name: STRING is "change_group" community_list_members_name: STRING is "list_members" community_list_projects_name: STRING is "list_projects" community_add_project_name: STRING is "add_project" community_remove_project_name: STRING is "remove_project" community_delete_name: STRING is "delete" community_change_description_name: STRING is "change_description" community_list_wiki_pages_name: STRING is "list_wiki_pages" community_retrieve_wiki_page_name: STRING is "retrieve_wiki_page" community_add_wiki_page_name: STRING is "add_wiki_page" community_edit_wiki_page_name: STRING is "edit_wiki_page" community_rename_wiki_page_name: STRING is "rename_wiki_page" community_delete_wiki_page_name: STRING is "delete_wiki_page" end