note description: "API interface to release services." author: "Peter Wyss " date: "$Date$" revision: "$Revision$" class RELEASE_SERVICE inherit API_SERVICE create make feature -- Basic operations release_add (a_session: STRING; a_project: INTEGER_REF; a_name:STRING; a_description: STRING; a_version: STRING; a_files: ARRAY [ANY]): BOOLEAN_REF -- Create a new release and release workitem. local l_msg: O_RELEASE_ADD_MESSAGE l_files: DS_ARRAYED_LIST[O_RELEASE_ADD_FILE_MESSAGE] i: INTEGER l_name: STRING l_platform: STRING l_file: DS_HASH_TABLE [ANY, STRING] do -- argument validiation check_anonymous_session (a_session) if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_project.item <= 0 then last_fault := err_invalid_project elseif a_name = Void or else a_name.is_empty then last_fault := err_invalid_name elseif a_description = Void or else a_description.is_empty then last_fault := err_invalid_description elseif a_version = Void or else a_version.is_empty then last_fault := err_invalid_version elseif a_files = Void or else a_files.is_empty then last_fault := err_invalid_files else -- FIXME struct should be validated -- generate and send message from i := 1 create l_files.make (a_files.count) until i > a_files.count loop l_file ?= a_files.item (i) if l_file = Void then last_fault := err_invalid_files else l_name ?= l_file.item ("name") if l_name = Void or else not is_valid_file_name (l_name) then last_fault := err_invalid_files else l_platform ?= l_file.item ("platform") if l_name = Void then last_fault := err_invalid_filename elseif l_platform = Void then last_fault := err_invalid_platform else l_files.force ( create {O_RELEASE_ADD_FILE_MESSAGE}.make ( create {A_STRING_VALUE}.make (l_name), create {A_STRING_VALUE}.make (l_platform) ), i) end end i := i + 1 end end if last_fault = Void then create l_msg.make ( create {A_STRING_VALUE}.make (a_session), create {A_INTEGER_VALUE}.make (a_project.item), create {A_STRING_VALUE}.make (a_name), create {A_STRING_VALUE}.make (a_description), create {A_STRING_VALUE}.make (a_version), create {A_SEQUENCE_VALUE[O_RELEASE_ADD_FILE_MESSAGE]}.make_from_linear (l_files)) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end end release_list (a_session: STRING; a_project: INTEGER_REF): ARRAY [DS_HASH_TABLE [ANY, STRING]] -- List releases for a_project local l_msg: O_RELEASE_LIST_MESSAGE l_release_list_reply_msg: O_RELEASE_LIST_REPLY_MESSAGE l_release_list: DS_HASH_TABLE[O_RELEASE_RELEASE_MESSAGE, A_STRING_VALUE] l_release_message: O_RELEASE_RELEASE_MESSAGE l_release: DS_HASH_TABLE [ANY, STRING] l_release_files_list: DS_ARRAYED_LIST[O_RELEASE_LIST_FILE_MESSAGE] l_release_file: O_RELEASE_LIST_FILE_MESSAGE i, j: INTEGER l_rid_ref: INTEGER_REF l_pid_ref: INTEGER_REF l_creation_time_ref: INTEGER_REF l_files_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 elseif a_project <= 0 then last_fault := err_invalid_project else create l_msg.make (create {A_STRING_VALUE}.make (a_session), create {A_INTEGER_VALUE}.make (a_project.item)) send_and_wait_for_reply (l_msg) if is_ok then l_release_list_reply_msg ?= last_reply check release_list_reply_message: l_release_list_reply_msg /= Void end l_release_list := l_release_list_reply_msg.release_list.map create Result.make (0, l_release_list.count-1) from l_release_list.start i := 0 until l_release_list.after loop l_release_message := l_release_list.item_for_iteration create l_release.make (7) create l_rid_ref l_rid_ref.set_item (l_release_list.key_for_iteration.value.to_integer_32) l_release.force (l_rid_ref, "release_id") create l_pid_ref l_pid_ref.set_item (l_release_message.project.value.to_integer_32) l_release.force (l_pid_ref, "project_id") create l_creation_time_ref l_creation_time_ref.set_item (l_release_message.creation_time.value.to_integer_32) l_release.force (l_creation_time_ref, "creation_time") l_release.force (l_release_message.name.value, "name") l_release.force (l_release_message.description.value, "description") l_release.force (l_release_message.version.value, "version") l_release_files_list := l_release_message.files.sequence check l_release_files_valid: l_release_files_list /= Void end create l_files_count_ref l_files_count_ref.set_item (l_release_files_list.count) l_release.force (l_files_count_ref, "file_count") from l_release_files_list.start j := 1 until l_release_files_list.after loop l_release_file := l_release_files_list.item_for_iteration l_release.force (l_release_file.name.value, "file_name_" + j.out) l_release.force (l_release_file.platform.value, "file_platform_" + j.out) -- Increment l_release_files_list.forth j := j + 1 end Result.force (l_release, i) i := i + 1 l_release_list.forth end end end end release_retrieve (a_session: STRING; a_release_id: INTEGER_REF): DS_HASH_TABLE [ANY, STRING] -- Retrieve release local l_msg: O_RELEASE_RETRIEVE_MESSAGE l_release_reply_msg: O_RELEASE_RETRIEVE_REPLY_MESSAGE l_release_files: DS_ARRAYED_LIST[O_RELEASE_RETRIEVE_FILE_MESSAGE] l_release_file: O_RELEASE_RETRIEVE_FILE_MESSAGE i: INTEGER l_rid_ref: INTEGER_REF l_pid_ref: INTEGER_REF l_creation_time_ref: INTEGER_REF l_files_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 elseif a_release_id <= 0 then last_fault := err_invalid_release else create l_msg.make (create {A_STRING_VALUE}.make (a_session), create {A_INTEGER_VALUE}.make (a_release_id.item)) send_and_wait_for_reply (l_msg) if is_ok then l_release_reply_msg ?= last_reply check release_reply_message: l_release_reply_msg /= Void end create Result.make (7) create l_rid_ref l_rid_ref.set_item (a_release_id) Result.force (l_rid_ref, "release_id") create l_pid_ref l_pid_ref.set_item (l_release_reply_msg.project.value.to_integer_32) Result.force (l_pid_ref, "project_id") create l_creation_time_ref l_creation_time_ref.set_item (l_release_reply_msg.creation_time.value.to_integer_32) Result.force (l_creation_time_ref, "creation_time") Result.force (l_release_reply_msg.name.value, "name") Result.force (l_release_reply_msg.description.value, "description") Result.force (l_release_reply_msg.version.value, "version") l_release_files := l_release_reply_msg.files.sequence check l_release_files_valid: l_release_files /= Void end create l_files_count_ref l_files_count_ref.set_item (l_release_files.count) Result.force (l_files_count_ref, "file_count") from l_release_files.start i := 1 until l_release_files.after loop l_release_file := l_release_files.item_for_iteration Result.force (l_release_file.name.value, "file_name_" + i.out) Result.force (l_release_file.platform.value, "file_platform_" + i.out) -- Increment l_release_files.forth i := i + 1 end end end end release_delete (a_session: STRING; a_project_id: INTEGER_REF; a_release_id: INTEGER_REF): BOOLEAN_REF -- Delete release. local l_msg: O_RELEASE_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_project_id <= 0 then last_fault := err_invalid_project elseif a_release_id <= 0 then last_fault := err_invalid_release else -- generate and send message create l_msg.make (create {A_STRING_VALUE}.make (a_session), create {A_INTEGER_VALUE}.make (a_project_id.item), create {A_INTEGER_VALUE}.make (a_release_id.item)) 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 -- Tuple of default-valued arguments to pass to call `a_name'. do if a_name.is_equal (release_add_name) then create {TUPLE [STRING, INTEGER_REF, STRING, STRING, STRING, ARRAY [ANY]]}Result elseif a_name.is_equal (release_list_name) then create {TUPLE [STRING, INTEGER_REF]}Result elseif a_name.is_equal (release_retrieve_name) then create {TUPLE [STRING, INTEGER_REF]}Result elseif a_name.is_equal (release_delete_name) then create {TUPLE [STRING, INTEGER_REF, INTEGER_REF]}Result end end feature -- Initialisation self_register -- Register all actions for this service do register_with_help (agent release_add, release_add_name, "Create a new release.") register_with_help (agent release_list, release_list_name, "List releases.") register_with_help (agent release_retrieve, release_retrieve_name, "Retrieve releases.") register_with_help (agent release_delete, release_delete_name, "Delete release.") end feature {NONE} -- Implementation release_add_name: STRING = "add" release_list_name: STRING = "list" release_retrieve_name: STRING = "retrieve" release_delete_name: STRING = "delete" end