note description: "API interface to internal project services." author: "Peter Wyss " date: "$Date$" revision: "$Revision$" class INTERNAL_PROJECT_SERVICE inherit API_SERVICE O_PROJECT_CONSTANTS create make feature -- Basic operations change_type (a_session: STRING; a_project_id, a_project_type, a_rcs_type, a_project_visibility: INTEGER_REF): BOOLEAN_REF -- Change the project type (open/closed source, etc) and visibility (public -- listed/not, etc) of the project with `a_project_id' to `a_project_type' -- and `a_visibility' respectively. local l_msg: O_PROJECT_CHANGE_TYPE_MESSAGE 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_project_type <= 0 then last_fault := err_invalid_project_type elseif a_rcs_type <= 0 then last_fault := err_invalid_rcs_type elseif a_project_visibility <= 0 then last_fault := err_invalid_visibility_type else -- generate and send message create l_msg.make (a_session, a_project_id.item, a_project_type.item, a_rcs_type.item, a_project_visibility.item) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end retrieve (a_project: INTEGER_REF): DS_HASH_TABLE [ANY, STRING] -- Get project information. local l_msg: O_PROJECT_INTERNAL_MESSAGE l_project_reply_msg: O_PROJECT_REPLY_MESSAGE l_int_ref: INTEGER_REF l_project_type: INTEGER_REF l_rcs_type: INTEGER_REF do -- argument validiation if a_project <= 0 then last_fault := err_invalid_project else create l_msg.make (create {A_INTEGER_VALUE}.make (a_project.item)) 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 (4) create l_int_ref l_int_ref.set_item(l_project_reply_msg.project_id.value.to_integer) Result.force (l_int_ref, "project_id") Result.force (l_project_reply_msg.name.value, "name") Result.force (l_project_reply_msg.logo.value, "logo") create l_project_type l_project_type.set_item(l_project_reply_msg.project_type.value.to_integer_32) Result.force (l_project_type, "project_type") create l_rcs_type l_rcs_type.set_item(l_project_reply_msg.rcs_type.value.to_integer_32) Result.force (l_rcs_type, "rcs_type") end end end retrieve_statistics: DS_HASH_TABLE [ANY, STRING] -- Get statistics about projects in Origo local l_msg: O_PROJECT_RETRIEVE_STATISTICS_INTERNAL_MESSAGE l_project_statistics_reply_msg: O_PROJECT_RETRIEVE_STATISTICS_REPLY_MESSAGE l_project_count_ref: INTEGER_REF l_os_count_ref: INTEGER_REF l_project_count_ref_hidden: INTEGER_REF l_os_count_ref_hidden: INTEGER_REF l_user_count_ref: INTEGER_REF do create l_msg.make 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.value.to_integer) 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.value.to_integer) Result.force (l_os_count_ref, "open_source_count") create l_project_count_ref_hidden l_project_count_ref_hidden.set_item (l_project_statistics_reply_msg.project_count_hidden.value.to_integer) Result.force (l_project_count_ref_hidden, "project_count_hidden") create l_os_count_ref_hidden l_os_count_ref_hidden.set_item (l_project_statistics_reply_msg.open_source_count_hidden.value.to_integer) Result.force (l_os_count_ref_hidden, "open_source_count_hidden") create l_user_count_ref l_user_count_ref.set_item (l_project_statistics_reply_msg.user_count.value.to_integer) Result.force (l_user_count_ref, "user_count") Result.force (l_project_statistics_reply_msg.recent_projects.value, "recent_projects") end end list_repositories (a_session: STRING; a_project_id: INTEGER_REF): ARRAY [STRING] -- Retrieve a list of source repositories of `a_project' local l_msg: O_PROJECT_LIST_REPOSITORIES_MESSAGE l_reply: O_PROJECT_LIST_REPOSITORIES_REPLY_MESSAGE l_result: DS_ARRAYED_LIST [STRING] do 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.item) send_and_wait_for_reply (l_msg) if is_ok then l_reply ?= last_reply check message_ok: l_reply /= Void end create l_result.make (l_reply.repositories.sequence.count) from l_reply.repositories.sequence.start until l_reply.repositories.sequence.after loop l_result.force_last (l_reply.repositories.sequence.item_for_iteration.twin) -- inc l_reply.repositories.sequence.forth end Result := l_result.to_array end end end add_repository (a_session: STRING; a_project_id: INTEGER_REF; a_name: STRING): BOOLEAN_REF -- Add a repository with `a_name' to `a_project_id' local l_msg: O_PROJECT_ADD_REPOSITORY_MESSAGE l_name: STRING do 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_name = Void or else a_name.is_empty then last_fault := err_invalid_name else -- Trim whitespace before checking for a valid name l_name := a_name l_name.right_adjust l_name.left_adjust if not is_valid_project (l_name) then last_fault := err_invalid_name else create l_msg.make (a_session, a_project_id.item, l_name) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end end remove_repository (a_session: STRING; a_project_id: INTEGER_REF; a_name: STRING): BOOLEAN_REF -- Remove the repository `a_name' from `a_project_id' local l_msg: O_PROJECT_REMOVE_REPOSITORY_MESSAGE l_name: STRING do 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_name = Void or else a_name.is_empty then last_fault := err_invalid_name else -- Trim whitespace before checking for a valid name l_name := a_name l_name.right_adjust l_name.left_adjust if not is_valid_project (l_name) then last_fault := err_invalid_name else -- generate and send message create l_msg.make (a_session, a_project_id.item, l_name) 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 -- Tuple of default-valued arguments to pass to call `a_name'. do if a_name.is_equal (project_add_repository_name) then create {TUPLE [STRING, INTEGER_REF, STRING]}Result elseif a_name.is_equal (project_change_type_name) then create {TUPLE [STRING, INTEGER_REF, INTEGER_REF, INTEGER_REF, INTEGER_REF]}Result elseif a_name.is_equal (project_list_repositories_name) then create {TUPLE [STRING, INTEGER_REF]}Result elseif a_name.is_equal (project_get_name) then create {TUPLE [INTEGER_REF]}Result elseif a_name.is_equal (project_remove_repository_name) then create {TUPLE [STRING, INTEGER_REF, STRING]}Result elseif a_name.is_equal (project_retrieve_statistics_name) then create {TUPLE}Result end end feature -- Initialisation self_register -- Register all actions for this service do register_with_help (agent add_repository, project_add_repository_type, "Add a new repository to a project") register_with_help (agent change_type, project_change_type_name, "Change the type of a project..") register_with_help (agent list_repositories, project_list_repositories_name, "List all source repositories of a project.") register_with_help (agent retrieve, project_get_name, "Retrieve a project.") register_with_help (agent remove_repository, project_remove_repository_type, "Remove a repository from a project") register_with_help (agent retrieve_statistics, project_retrieve_statistics_name, "Retrieve statistics about projects in Origo.") end feature {NONE} -- Implementation project_add_repository_name: STRING = "add_repository" project_change_type_name: STRING = "change_type" project_list_repositories_name: STRING = "list_repositories" project_get_name: STRING = "retrieve" project_remove_repository_name: STRING = "remove_repository" project_retrieve_statistics_name: STRING = "retrieve_statistics" end