indexing 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 list (a_show_hidden: BOOLEAN_REF): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List all existing projects. local l_msg: O_PROJECT_LIST_ALL_INTERNAL_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_int_ref: INTEGER_REF do create l_msg.make(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_int_ref l_int_ref.set_item(l_pl.key_for_iteration) l_project.force (l_int_ref, "project_id") Result.force (l_project, i) i := i + 1 l_pl.forth end end end list_partial ( 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_INTERNAL_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 if 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_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 in the message 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 retrieve (a_project: INTEGER_REF): DS_HASH_TABLE [ANY, STRING] is -- Get project information. local l_msg: O_PROJECT_INTERNAL_MESSAGE l_project_reply_msg: O_PROJECT_REPLY_MESSAGE l_int_ref: INTEGER_REF l_bool_ref: BOOLEAN_REF do -- argument validiation if a_project <= 0 then last_fault := err_invalid_project else create l_msg.make (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_int_ref l_int_ref.set_item(l_project_reply_msg.project_id) Result.force (l_int_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_bool_ref l_bool_ref.set_item(l_project_reply_msg.is_closed_source) Result.force (l_bool_ref, "is_closed_source") end end end retrieve_statistics: DS_HASH_TABLE [ANY, STRING] is -- 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 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) 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 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_list_name) then create {TUPLE [BOOLEAN_REF]}Result elseif a_name.is_equal (project_list_partial_name) then create {TUPLE [BOOLEAN_REF, INTEGER_REF, INTEGER_REF]}Result elseif a_name.is_equal (project_get_name) then create {TUPLE [INTEGER_REF]}Result elseif a_name.is_equal (project_retrieve_statistics_name) then create {TUPLE}Result end end feature -- Initialisation self_register is -- Register all actions for this service do register_with_help (agent list, project_list_name, "List all available projects.") register_with_help (agent list_partial, project_list_partial_name, "List partial projects.") register_with_help (agent retrieve, project_get_name, "Retrieve a project.") register_with_help (agent retrieve_statistics, project_retrieve_statistics_name, "Retrieve statistics about projects in Origo.") end feature {NONE} -- Implementation project_list_name: STRING is "list" project_list_partial_name: STRING is "list_partial" project_get_name: STRING is "retrieve" project_retrieve_statistics_name: STRING is "retrieve_statistics" end