indexing description: "API interface to project services." author: "Patrick Ruckstuhl " date: "$Date$" revision: "$Revision$" class PROJECT_SERVICE inherit API_SERVICE O_PROJECT_CONSTANTS create make feature -- Basic operations project_create (a_session, a_name, a_description: STRING; a_is_closed_source, is_hidden: BOOLEAN_REF): BOOLEAN_REF is -- Create a new project. local l_msg: O_PROJECT_CREATE_MESSAGE do -- argument validation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif not is_valid_project (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, a_is_closed_source, is_hidden) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end project_retrieve_id (a_session, a_name: STRING): INTEGER_REF is -- Retrieve project id for project. local l_msg: O_PROJECT_RETRIEVE_ID_MESSAGE l_msg_reply: O_PROJECT_RETRIEVE_ID_REPLY_MESSAGE do -- argument validation if not is_valid_session (a_session) then last_fault := err_invalid_session elseif not is_valid_project (a_name) then last_fault := err_invalid_name else -- generate and send message create l_msg.make (a_session, a_name) send_and_wait_for_reply (l_msg) if is_ok then l_msg_reply ?= last_reply check project_iretrieve_id_reply_message: l_msg_reply /= Void end create Result Result.set_item (l_msg_reply.project_id) end end end project_request_add (a_session, a_name, a_description: STRING; a_is_closed_source: BOOLEAN_REF; a_message: STRING): BOOLEAN_REF is -- Create a new project request. local l_msg: O_PROJECT_REQUEST_ADD_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_project (a_name) then last_fault := err_invalid_name elseif a_description = Void or else a_description.is_empty then last_fault := err_invalid_description elseif a_message = Void then last_fault := err_invalid_message else -- generate and send message create l_msg.make (a_session, a_name, a_description, a_is_closed_source, a_message) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end project_list (a_session: STRING; a_show_hidden: BOOLEAN_REF): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List all existing projects. local l_msg: O_PROJECT_LIST_ALL_MESSAGE l_project_list_msg: O_PROJECT_LIST_MESSAGE l_pl: HASH_TABLE [STRING, INTEGER] l_project: DS_HASH_TABLE [ANY, STRING] i: INTEGER l_pid_ref: INTEGER_REF do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session else create l_msg.make (a_session, a_show_hidden) send_and_wait_for_reply (l_msg) if is_ok then l_project_list_msg ?= last_reply check project_list_message: l_project_list_msg /= Void end l_pl := l_project_list_msg.project_list create Result.make (0, l_pl.count-1) from l_pl.start i := 0 until l_pl.after loop create l_project.make (2) l_project.force (l_pl.item_for_iteration, "name") create l_pid_ref l_pid_ref.set_item (l_pl.key_for_iteration) l_project.force (l_pid_ref, "project_id") Result.force (l_project, i) i := i + 1 l_pl.forth end end end end project_list_partial (a_session: STRING; a_show_hidden: BOOLEAN_REF; a_start_index: INTEGER_REF; a_count: INTEGER_REF): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List count projects starting at start_index (the returned array is sorted lexicographically wrt. project names). local l_msg: O_PROJECT_LIST_PARTIAL_MESSAGE l_project_list_msg: O_PROJECT_LIST_MESSAGE l_pl: HASH_TABLE [STRING, INTEGER] l_project: DS_HASH_TABLE [ANY, STRING] l_pid_ref: INTEGER_REF l_sorted_list: DS_ARRAYED_LIST[DS_HASH_TABLE [ANY, STRING]] l_sorter: DS_QUICK_SORTER[DS_HASH_TABLE [ANY, STRING]] l_comparator: PROJECT_COMPARATOR do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_start_index < 0 then last_fault := err_invalid_index elseif a_count < 1 then last_fault := err_invalid_count else create l_msg.make (a_session, a_show_hidden, a_start_index, a_count) send_and_wait_for_reply (l_msg) if is_ok then l_project_list_msg ?= last_reply check project_list_message: l_project_list_msg /= Void end -- TODO currently the list is not sorted l_pl := l_project_list_msg.project_list create l_sorted_list.make (l_pl.count) from l_pl.start until l_pl.after loop create l_project.make (2) l_project.force (l_pl.item_for_iteration, "name") create l_pid_ref l_pid_ref.set_item (l_pl.key_for_iteration) l_project.force (l_pid_ref, "project_id") l_sorted_list.put_last (l_project) l_pl.forth end -- sort the project list create l_comparator create l_sorter.make (l_comparator) l_sorted_list.sort (l_sorter) Result := l_sorted_list.to_array end end end project_list_of_user (a_session: STRING; a_user: STRING): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List all existing projects. local l_msg: O_PROJECT_LIST_OF_USER_MESSAGE l_reply: O_PROJECT_LIST_OF_USER_REPLY_MESSAGE l_pl: HASH_TABLE [TUPLE[project_name: STRING; group: INTEGER], INTEGER] l_project: DS_HASH_TABLE [ANY, STRING] i: INTEGER l_group_id_ref: INTEGER_REF l_project_id_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 not is_valid_name (a_user) then last_fault := err_invalid_user else create l_msg.make (a_session, a_user) send_and_wait_for_reply (l_msg) if is_ok then l_reply ?= last_reply check reply_message: l_reply /= Void end l_pl := l_reply.project_list create Result.make (0, l_pl.count-1) from l_pl.start i := 0 until l_pl.after loop create l_project.make (3) l_project.force (l_pl.item_for_iteration.project_name, "project_name") create l_group_id_ref l_group_id_ref.set_item (l_pl.item_for_iteration.group) l_project.force (l_group_id_ref, "group_id") create l_project_id_ref l_project_id_ref.set_item (l_pl.key_for_iteration) l_project.force (l_project_id_ref, "project_id") Result.force (l_project, i) i := i + 1 l_pl.forth end end end end project_retrieve (a_session: STRING; a_project: INTEGER_REF): DS_HASH_TABLE [ANY, STRING] is -- Get project information. local l_msg: O_PROJECT_MESSAGE l_project_reply_msg: O_PROJECT_REPLY_MESSAGE l_pid_ref: INTEGER_REF l_closed_source_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_project <= 0 then last_fault := err_invalid_project else create l_msg.make (a_session, a_project) send_and_wait_for_reply (l_msg) if is_ok then l_project_reply_msg ?= last_reply check project_reply_message: l_project_reply_msg /= Void end create Result.make (5) create l_pid_ref l_pid_ref.set_item (l_project_reply_msg.project_id) Result.force (l_pid_ref, "project_id") Result.force (l_project_reply_msg.name, "name") Result.force (l_project_reply_msg.description, "description") Result.force (l_project_reply_msg.logo, "logo") create l_closed_source_ref l_closed_source_ref.set_item (l_project_reply_msg.is_closed_source) Result.force (l_closed_source_ref, "is_closed_source") end end end project_retrieve_statistics (a_session: STRING): DS_HASH_TABLE [ANY, STRING] is -- Get statistics about projects in Origo local l_msg: O_PROJECT_RETRIEVE_STATISTICS_MESSAGE l_project_statistics_reply_msg: O_PROJECT_RETRIEVE_STATISTICS_REPLY_MESSAGE l_project_count_ref: INTEGER_REF l_os_count_ref: INTEGER_REF do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session else create l_msg.make (a_session) send_and_wait_for_reply (l_msg) if is_ok then l_project_statistics_reply_msg ?= last_reply check l_project_statistics_reply_msg: l_project_statistics_reply_msg /= Void end create Result.make (2) create l_project_count_ref l_project_count_ref.set_item (l_project_statistics_reply_msg.project_count) Result.force (l_project_count_ref, "project_count") create l_os_count_ref l_os_count_ref.set_item (l_project_statistics_reply_msg.open_source_count) Result.force (l_os_count_ref, "open_source_count") end end end project_request_retrieve (a_session: STRING; a_request_project_name: STRING): DS_HASH_TABLE [ANY, STRING] is -- Get project request information. local l_msg: O_PROJECT_REQUEST_RETRIEVE_MESSAGE l_project_reply_msg: O_PROJECT_REQUEST_RETRIEVE_REPLY_MESSAGE l_rid_ref: INTEGER_REF l_closed_source_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_request_project_name = Void or a_request_project_name.is_empty then last_fault := err_invalid_project else create l_msg.make (a_session, a_request_project_name) send_and_wait_for_reply (l_msg) if is_ok then l_project_reply_msg ?= last_reply check project_reply_message: l_project_reply_msg /= Void end create Result.make (7) create l_rid_ref l_rid_ref.set_item (l_project_reply_msg.request_id) Result.force (l_rid_ref, "request_id") Result.force (l_project_reply_msg.user_name, "user_name") Result.force (l_project_reply_msg.user_email, "user_email") Result.force (l_project_reply_msg.name, "name") Result.force (l_project_reply_msg.description, "description") create l_closed_source_ref l_closed_source_ref.set_item (l_project_reply_msg.is_closed_source) Result.force (l_closed_source_ref, "is_closed_source") Result.force (l_project_reply_msg.message, "message") end end end project_members (a_session: STRING; a_project: INTEGER_REF; an_access_group: INTEGER_REF): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List all users that are in an_access_group for a_project. local l_msg: O_PROJECT_MEMBERS_MESSAGE l_user_list_msg: O_USER_LIST_MESSAGE l_pl: 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_project <= 0 then last_fault := err_invalid_project elseif not (an_access_group = 3 or else an_access_group = 4) then last_fault := err_invalid_group else create l_msg.make (a_session, a_project, an_access_group) send_and_wait_for_reply (l_msg) if is_ok then l_user_list_msg ?= last_reply check user_list_message: l_user_list_msg /= Void end l_pl := l_user_list_msg.user_list create Result.make (0, l_pl.count-1) from l_pl.start i := 0 until l_pl.after loop create l_user.make (1) l_user.force (l_pl.item_for_iteration, "name") Result.force (l_user, i) i := i + 1 l_pl.forth end end end end project_change_group (a_session: STRING; a_project_id: INTEGER_REF; a_user: STRING; an_access_group: INTEGER_REF): BOOLEAN_REF is -- Change access group of a_user in a_project to an_access_group (0=no rights, 3=administrator, 4=developer) local l_msg: O_PROJECT_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) then last_fault := err_invalid_user elseif a_project_id <= 0 then last_fault := err_invalid_project elseif not (an_access_group.item = 0 or else an_access_group.item = 3 or else an_access_group.item = 4) then last_fault := err_invalid_group else -- generate and send message create l_msg.make (a_session, a_project_id, a_user, an_access_group.item) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end project_change_description (a_session: STRING; a_project_id: INTEGER_REF; a_description: STRING): BOOLEAN_REF is -- Change description of a project. local l_msg: O_PROJECT_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_project_id <= 0 then last_fault := err_invalid_project 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_project_id, a_description) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end project_change_logo (a_session: STRING; a_project_id: INTEGER_REF; a_logo: STRING): BOOLEAN_REF is -- Change logo of a project. local l_msg: O_PROJECT_CHANGE_LOGO_MESSAGE do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_project_id <= 0 then last_fault := err_invalid_project elseif a_logo = Void or else a_logo.is_empty then last_fault := err_invalid_logo else -- generate and send message create l_msg.make (a_session, a_project_id, a_logo) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end project_list_bookmarkers (a_session: STRING; a_project: INTEGER_REF): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List all bookmarkers for a_project. local l_msg: O_PROJECT_LIST_BOOKMARKERS_MESSAGE l_user_list_msg: O_USER_LIST_MESSAGE l_pl: 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_project <= 0 then last_fault := err_invalid_project else create l_msg.make (a_session, a_project) send_and_wait_for_reply (l_msg) if is_ok then l_user_list_msg ?= last_reply check user_list_message: l_user_list_msg /= Void end l_pl := l_user_list_msg.user_list create Result.make (0, l_pl.count-1) from l_pl.start i := 0 until l_pl.after loop create l_user.make (2) l_user.force (l_pl.item_for_iteration, "name") Result.force (l_user, i) i := i + 1 l_pl.forth end end end end project_list_communities (a_session: STRING; a_project_id: INTEGER_REF): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List communities of user a_username. local l_msg: O_PROJECT_LIST_COMMUNITIES_MESSAGE l_reply: O_COMMUNITY_LIST_REPLY_MESSAGE l_communitiy_list: DS_ARRAYED_LIST [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 elseif a_project_id <= 0 then last_fault := err_invalid_project else create l_msg.make (a_session, a_project_id) send_and_wait_for_reply (l_msg) if is_ok then l_reply ?= last_reply check valid_reply: l_reply /= Void end l_communitiy_list := l_reply.community_list create Result.make (0, l_communitiy_list.count - 1) from l_communitiy_list.start i := 0 until l_communitiy_list.after loop create l_community.make (1) l_community.force (l_communitiy_list.item_for_iteration, "name") Result.force (l_community, i) i := i + 1 l_communitiy_list.forth end end end end project_change_settings (a_session: STRING; a_project_id: INTEGER_REF; a_settings: ARRAY [ANY]): BOOLEAN_REF is -- Set new settings for project with id project_id. local l_msg: O_PROJECT_CHANGE_SETTINGS_MESSAGE l_settings: ARRAYED_LIST [TUPLE [setting_type: STRING; setting_value: STRING]] l_tuple: TUPLE [setting_type: STRING; setting_value: STRING] l_setting: DS_HASH_TABLE [ANY, STRING] l_setting_type: STRING l_setting_value: STRING i: INTEGER do -- argument validation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_project_id <= 0 then last_fault := err_invalid_project elseif a_settings = Void or else a_settings.is_empty then last_fault := err_invalid_information else -- generate and send message -- FIXME the ARRAYED_LIST should be validated (do all required keys exist, etc) from i := 1 create l_settings.make (a_settings.count) until i > a_settings.count loop l_setting ?= a_settings.item (i) if l_setting = Void then last_fault := err_invalid_setting else l_setting_type := l_setting.item ("setting_type").out l_setting_value := l_setting.item ("setting_value").out l_setting_value.left_adjust l_setting_value.right_adjust l_setting_type.left_adjust l_setting_type.right_adjust if l_setting_type.is_equal ("svn_path_doc") then if l_setting_value.is_equal ("/") then last_fault := err_invalid_settings end end create l_tuple.default_create l_tuple.setting_type := l_setting_type l_tuple.setting_value := l_setting_value l_settings.force (l_tuple) end i := i + 1 end if last_fault = Void then create l_msg.make (a_session, a_project_id, l_settings) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end 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 (project_create_name) then create {TUPLE [STRING, STRING, STRING, BOOLEAN_REF, BOOLEAN_REF]}Result elseif a_name.is_equal (project_retrieve_id_name) then create {TUPLE [STRING, STRING]}Result elseif a_name.is_equal (project_request_add_name) then create {TUPLE [STRING, STRING, STRING, BOOLEAN_REF, STRING]}Result elseif a_name.is_equal (project_list_name) then create {TUPLE [STRING, BOOLEAN_REF]}Result elseif a_name.is_equal (project_list_partial_name) then create {TUPLE [STRING, BOOLEAN_REF, INTEGER_REF, INTEGER_REF]}Result elseif a_name.is_equal (project_retrieve_name) then create {TUPLE [STRING, INTEGER_REF]}Result elseif a_name.is_equal (project_retrieve_statistics_name) then create {TUPLE [STRING]}Result elseif a_name.is_equal (project_request_retrieve_name) then create {TUPLE [STRING, STRING]}Result elseif a_name.is_equal (project_list_of_user_name) then create {TUPLE [STRING, STRING]}Result elseif a_name.is_equal (project_members_name) then create {TUPLE [STRING, INTEGER_REF, INTEGER_REF]}Result elseif a_name.is_equal (project_change_group_name) then create {TUPLE [STRING, INTEGER_REF, STRING, INTEGER_REF]}Result elseif a_name.is_equal (project_change_description_name) then create {TUPLE [STRING, INTEGER_REF, STRING]}Result elseif a_name.is_equal (project_change_logo_name) then create {TUPLE [STRING, INTEGER_REF, STRING]}Result elseif a_name.is_equal (project_list_bookmarkers_name) then create {TUPLE [STRING, INTEGER_REF]}Result elseif a_name.is_equal (project_list_communities_name) then create {TUPLE [STRING, INTEGER_REF]}Result elseif a_name.is_equal (project_change_settings_name) then create {TUPLE [STRING, INTEGER_REF, ARRAY [ANY]]}Result end end feature -- Initialisation self_register is -- Register all actions for this service do register_with_help (agent project_create, project_create_name, "Create a new project. (needs project_create permission)") register_with_help (agent project_retrieve_id, project_retrieve_id_name, "Retrieve project id for project. (needs project_list permission)") register_with_help (agent project_request_add, project_request_add_name, "Add a new project request. (needs project_request_add permission)") register_with_help (agent project_list, project_list_name, "List all available projects. (needs project_list permission)") register_with_help (agent project_list_partial, project_list_partial_name, "List a number of projects starting at a specific index. (needs project_list permission)") register_with_help (agent project_retrieve, project_retrieve_name, "Retrieve a project.") register_with_help (agent project_retrieve_statistics, project_retrieve_statistics_name, "Retrieve Origo-wide project statistics") register_with_help (agent project_request_retrieve, project_request_retrieve_name, "Retrieve a project request.") register_with_help (agent project_list_of_user, project_list_of_user_name, "List all projects of which a_user is developer or owner. group_id 3 is a project owner and 4 is project developer. (needs project_list_of_user permission)") register_with_help (agent project_members, project_members_name, "List project members with a certain access group. access_group 3 is project owner and 4 is project developer. (needs project_members_list permission)") register_with_help (agent project_change_group, project_change_group_name, "Change access group of user in project to access_group (0=no rights, 3=administrator, 4=developer).") register_with_help (agent project_change_description, project_change_description_name, "Change description of a project.") register_with_help (agent project_change_logo, project_change_logo_name, "Change logo of a project.") register_with_help (agent project_list_bookmarkers, project_list_bookmarkers_name, "List all bookmarkers of a project.") register_with_help (agent project_list_communities, project_list_communities_name, "List all communities associated with a project.") register_with_help (agent project_change_settings, project_change_settings_name, "Change the project settings.") end feature {NONE} -- Implementation project_create_name: STRING is "add" project_retrieve_id_name: STRING is "retrieve_id" project_request_add_name: STRING is "request_add" project_list_name: STRING is "list" project_list_partial_name: STRING is "list_partial" project_retrieve_name: STRING is "retrieve" project_retrieve_statistics_name: STRING is "retrieve_statistics" project_request_retrieve_name: STRING is "request_retrieve" project_members_name: STRING is "members" project_change_group_name: STRING is "change_group" project_list_of_user_name: STRING is "list_of_user" project_change_description_name: STRING is "change_description" project_change_logo_name: STRING is "change_logo" project_list_bookmarkers_name: STRING is "list_bookmarkers" project_list_communities_name: STRING is "list_communities" project_change_settings_name: STRING is "change_settings" end