indexing 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 is -- Create a new release and release workitem. local l_msg: O_RELEASE_ADD_MESSAGE l_files: ARRAYED_LIST [TUPLE [name: STRING; platform: STRING]] l_tuple: TUPLE [name: STRING; platform: STRING] 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 <= 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 create l_tuple l_tuple.name := l_name l_tuple.platform := l_platform l_files.force (l_tuple) end end i := i + 1 end end if last_fault = Void then create l_msg.make (a_session, a_project, a_name, a_description, a_version, 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]] is -- List releases for a_project local l_msg: O_RELEASE_LIST_MESSAGE l_release_list_reply_msg: O_RELEASE_LIST_REPLY_MESSAGE l_rlist: DS_HASH_TABLE [TUPLE [project: INTEGER; creation_time: INTEGER; name: STRING; description: STRING; version: STRING; files: ARRAYED_LIST [TUPLE [name: STRING; platform: STRING]]], INTEGER] l_release: DS_HASH_TABLE [ANY, STRING] l_release_files: ARRAYED_LIST [TUPLE [name: STRING; platform: STRING]] l_release_file: TUPLE [name: STRING; platform: STRING] 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 (a_session, a_project) 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_rlist := l_release_list_reply_msg.release_list create Result.make (0, l_rlist.count-1) from l_rlist.start i := 0 until l_rlist.after loop create l_release.make (7) create l_rid_ref l_rid_ref.set_item (l_rlist.key_for_iteration) l_release.force (l_rid_ref, "release_id") create l_pid_ref l_pid_ref.set_item (l_rlist.item_for_iteration.project) l_release.force (l_pid_ref, "project_id") create l_creation_time_ref l_creation_time_ref.set_item (l_rlist.item_for_iteration.creation_time) l_release.force (l_creation_time_ref, "creation_time") l_release.force (l_rlist.item_for_iteration.name, "name") l_release.force (l_rlist.item_for_iteration.description, "description") l_release.force (l_rlist.item_for_iteration.version, "version") l_release_files ?= l_rlist.item_for_iteration.files 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) l_release.force (l_files_count_ref, "file_count") from l_release_files.start j := 1 until l_release_files.after loop l_release_file ?= l_release_files.item l_release.force (l_release_file.name, "file_name_" + j.out) l_release.force (l_release_file.platform, "file_platform_" + j.out) l_release_files.forth j := j + 1 end Result.force (l_release, i) i := i + 1 l_rlist.forth end end end end release_retrieve (a_session: STRING; a_release_id: INTEGER_REF): DS_HASH_TABLE [ANY, STRING] is -- Retrieve release local l_msg: O_RELEASE_RETRIEVE_MESSAGE l_release_reply_msg: O_RELEASE_RETRIEVE_REPLY_MESSAGE l_release_files: ARRAYED_LIST [TUPLE [name: STRING; platform: STRING]] l_release_file: TUPLE [name: STRING; platform: STRING] 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 (a_session, a_release_id) 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) Result.force (l_pid_ref, "project_id") create l_creation_time_ref l_creation_time_ref.set_item (l_release_reply_msg.creation_time) Result.force (l_creation_time_ref, "creation_time") Result.force (l_release_reply_msg.name, "name") Result.force (l_release_reply_msg.description, "description") Result.force (l_release_reply_msg.version, "version") l_release_files ?= l_release_reply_msg.files 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 Result.force (l_release_file.name, "file_name_" + i.out) Result.force (l_release_file.platform, "file_platform_" + i.out) 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 is -- 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 (a_session, a_project_id, a_release_id) 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 (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 is -- 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 is "add" release_list_name: STRING is "list" release_retrieve_name: STRING is "retrieve" release_delete_name: STRING is "delete" end