indexing description: "API interface to workitem services." author: "Peter Wyss " date: "$Date$" revision: "$Revision$" class WORKITEM_SERVICE inherit API_SERVICE O_PROJECT_CONSTANTS create make feature -- Basic operations workitem_list (a_session: STRING; a_limit: INTEGER_REF; a_unread_only: BOOLEAN_REF): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List max a_limit (unread) workitems for session user local l_msg: O_WORKITEM_LIST_MESSAGE l_workitem_list_reply_msg: O_WORKITEM_LIST_REPLY_MESSAGE l_wlist: DS_HASH_TABLE [TUPLE [workitem_id: INTEGER; type: INTEGER; creation_time: INTEGER; project_id: INTEGER; project: STRING; user: STRING; data: DS_HASH_TABLE [ANY, STRING]; is_read: BOOLEAN], INTEGER] l_workitem: DS_HASH_TABLE [ANY, STRING] l_workitem_tuple: TUPLE [workitem_id: INTEGER; type: INTEGER; creation_time: INTEGER; project_id: INTEGER; project: STRING; user: STRING; data: DS_HASH_TABLE [ANY, STRING]; is_read: BOOLEAN] l_workitem_data: DS_HASH_TABLE [ANY, STRING] i: INTEGER l_wi_id_ref: INTEGER_REF l_type_ref: INTEGER_REF l_creation_time_ref: INTEGER_REF l_pid_ref: INTEGER_REF l_read_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_limit <= 0 then last_fault := err_invalid_limit else create l_msg.make (a_session, a_limit, a_unread_only) send_and_wait_for_reply (l_msg) if is_ok then l_workitem_list_reply_msg ?= last_reply check workitem_list_reply_message: l_workitem_list_reply_msg /= Void end l_wlist := l_workitem_list_reply_msg.workitem_list create Result.make (0, l_wlist.count-1) from i := 0 until i >= l_wlist.count loop l_workitem_tuple := l_wlist.item (i + 1) create l_workitem.make (6) create l_wi_id_ref l_wi_id_ref.set_item (l_workitem_tuple.workitem_id) l_workitem.force (l_wi_id_ref, "workitem_id") create l_type_ref l_type_ref.set_item (l_workitem_tuple.type) l_workitem.force (l_type_ref, "type") create l_creation_time_ref l_creation_time_ref.set_item (l_workitem_tuple.creation_time) l_workitem.force (l_creation_time_ref, "creation_time") create l_pid_ref l_pid_ref.set_item (l_workitem_tuple.project_id) l_workitem.force (l_pid_ref, "project_id") l_workitem.force (l_workitem_tuple.project, "project") l_workitem.force (l_workitem_tuple.user, "user") l_workitem_data ?= l_workitem_tuple.data check l_workitem_data_valid: l_workitem_data /= Void end from l_workitem_data.start until l_workitem_data.after loop l_workitem.force (l_workitem_data.item_for_iteration, l_workitem_data.key_for_iteration) l_workitem_data.forth end create l_read_ref l_read_ref.set_item (l_workitem_tuple.is_read) l_workitem.force (l_read_ref, "is_read") Result.force (l_workitem, i) i := i + 1 end end end end workitem_list_projects (a_session: STRING; a_limit: INTEGER_REF; a_unread_only: BOOLEAN_REF): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List `a_limit' workitems for each project for session user local l_msg: O_WORKITEM_LIST_PROJECTS_MESSAGE l_workitem_list_reply_msg: O_WORKITEM_LIST_REPLY_MESSAGE l_wlist: DS_HASH_TABLE [TUPLE [workitem_id: INTEGER; type: INTEGER; creation_time: INTEGER; project_id: INTEGER; project: STRING; user: STRING; data: DS_HASH_TABLE [ANY, STRING]; is_read: BOOLEAN], INTEGER] do -- argument validiation if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_limit <= 0 then last_fault := err_invalid_limit else create l_msg.make (a_session, a_limit, a_unread_only) send_and_wait_for_reply (l_msg) if is_ok then l_workitem_list_reply_msg ?= last_reply check workitem_list_reply_message: l_workitem_list_reply_msg /= Void end l_wlist := l_workitem_list_reply_msg.workitem_list Result := convert_workitems(l_wlist) end end end workitem_list_project (a_session: STRING; a_project_id: INTEGER_REF; a_limit: INTEGER_REF; a_unread_only: BOOLEAN_REF): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- List `a_limit' workitems for the project `project_name' for session use local l_msg: O_WORKITEM_LIST_PROJECT_MESSAGE l_workitem_list_reply_msg: O_WORKITEM_LIST_REPLY_MESSAGE l_wlist: DS_HASH_TABLE [TUPLE [workitem_id: INTEGER; type: INTEGER; creation_time: INTEGER; project_id: INTEGER; project: STRING; user: STRING; data: DS_HASH_TABLE [ANY, STRING]; is_read: BOOLEAN], INTEGER] do -- argument validiation if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_limit <= 0 then last_fault := err_invalid_limit elseif a_project_id <= 0 then last_fault := err_invalid_project else create l_msg.make (a_session, a_project_id, a_limit, a_unread_only) send_and_wait_for_reply (l_msg) if is_ok then l_workitem_list_reply_msg ?= last_reply check workitem_list_reply_message: l_workitem_list_reply_msg /= Void end l_wlist := l_workitem_list_reply_msg.workitem_list Result := convert_workitems(l_wlist) end end end workitem_retrieve (a_session: STRING; a_workitem_id: INTEGER_REF): DS_HASH_TABLE [ANY, STRING] is -- Retrieve workitem local l_msg: O_WORKITEM_RETRIEVE_MESSAGE l_workitem_reply_msg: O_WORKITEM_RETRIEVE_REPLY_MESSAGE l_workitem_data: DS_HASH_TABLE [ANY, STRING] l_wi_id_ref: INTEGER_REF l_type_ref: INTEGER_REF l_creation_time_ref: INTEGER_REF l_pid_ref: INTEGER_REF do -- argument validiation if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_workitem_id <= 0 then last_fault := err_invalid_workitem else create l_msg.make (a_session, a_workitem_id) send_and_wait_for_reply (l_msg) if is_ok then l_workitem_reply_msg ?= last_reply check workitem_reply_message: l_workitem_reply_msg /= Void end create Result.make (6) create l_wi_id_ref l_wi_id_ref.set_item (a_workitem_id) Result.force (l_wi_id_ref, "workitem_id") create l_type_ref l_type_ref.set_item (l_workitem_reply_msg.workitem_type) Result.force (l_type_ref, "type") create l_creation_time_ref l_creation_time_ref.set_item (l_workitem_reply_msg.creation_time) Result.force (l_creation_time_ref, "creation_time") create l_pid_ref l_pid_ref.set_item (l_workitem_reply_msg.project_id) Result.force (l_pid_ref, "project_id") Result.force (l_workitem_reply_msg.project, "project") Result.force (l_workitem_reply_msg.user, "user") l_workitem_data ?= l_workitem_reply_msg.data check l_workitem_data_valid: l_workitem_data /= Void end from l_workitem_data.start until l_workitem_data.after loop Result.force (l_workitem_data.item_for_iteration, l_workitem_data.key_for_iteration) l_workitem_data.forth end end end end workitem_set_read_status (a_session: STRING; a_workitem: INTEGER_REF; a_read_status: BOOLEAN_REF): BOOLEAN_REF is -- Set workitem read status to a_read_status local l_msg: O_WORKITEM_SET_READ_STATUS_MESSAGE do -- argument validiation if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_workitem <= 0 then last_fault := err_invalid_workitem else -- generate and send message create l_msg.make (a_session, a_workitem, a_read_status) send_and_wait_for_reply (l_msg) if is_ok then create Result Result.set_item (True) end end end workitem_set_read_status_project (a_session: STRING; a_project: INTEGER_REF; a_read_status: BOOLEAN_REF): BOOLEAN_REF is -- Set workitem read status for a_project to a_read_status local l_msg: O_WORKITEM_SET_READ_STATUS_PROJECT_MESSAGE do -- argument validiation if not is_valid_session (a_session) then last_fault := err_invalid_session elseif a_project <= 0 then last_fault := err_invalid_project else -- generate and send message create l_msg.make (a_session, a_project, a_read_status) 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 (workitem_list_name) then create {TUPLE [STRING, INTEGER_REF, BOOLEAN_REF]}Result elseif a_name.is_equal (workitem_list_projects_name) then create {TUPLE [STRING, INTEGER_REF, BOOLEAN_REF]}Result elseif a_name.is_equal (workitem_list_project_name) then create {TUPLE [STRING, INTEGER_REF, INTEGER_REF, BOOLEAN_REF]}Result elseif a_name.is_equal (workitem_retrieve_name) then create {TUPLE [STRING, INTEGER_REF]}Result elseif a_name.is_equal (workitem_set_read_status_name) then create {TUPLE [STRING, INTEGER_REF, BOOLEAN_REF]}Result elseif a_name.is_equal (workitem_set_read_status_project_name) then create {TUPLE [STRING, INTEGER_REF, BOOLEAN_REF]}Result end end feature -- Initialisation self_register is -- Register all actions for this service do register_with_help (agent workitem_list, workitem_list_name, "Get up to limit (unread) workitems.") register_with_help (agent workitem_list_projects, workitem_list_projects_name, "Get up to limit (unread) workitems for each project.") register_with_help (agent workitem_list_project, workitem_list_project_name, "Get up to limit (unread) workitems for a project.") register_with_help (agent workitem_retrieve, workitem_retrieve_name, "Retrieve workitem with workitem_id.") register_with_help (agent workitem_set_read_status, workitem_set_read_status_name, "Mark workitem with workitem_id as read or unread according to read_status.") register_with_help (agent workitem_set_read_status_project, workitem_set_read_status_project_name, "Mark workitems in project with project_id as read or unread according to read_status.") end feature {NONE} -- Conversion convert_workitems (w_list: DS_HASH_TABLE [TUPLE [workitem_id: INTEGER; type: INTEGER; creation_time: INTEGER; project_id: INTEGER; project: STRING; user: STRING; data: DS_HASH_TABLE [ANY, STRING]; is_read: BOOLEAN], INTEGER]): ARRAY [DS_HASH_TABLE [ANY, STRING]] is -- Converts the workitems into a format suitable for xml rpc (ARRAY [DS_HASH_TABLE [...]] is mapped to an array of structs) require list_valid: w_list /= Void local l_workitem: DS_HASH_TABLE [ANY, STRING] l_workitem_tuple: TUPLE [workitem_id: INTEGER; type: INTEGER; creation_time: INTEGER; project_id: INTEGER; project: STRING; user: STRING; data: DS_HASH_TABLE [ANY, STRING]; is_read: BOOLEAN] l_workitem_data: DS_HASH_TABLE [ANY, STRING] i: INTEGER l_wi_id_ref: INTEGER_REF l_type_ref: INTEGER_REF l_creation_time_ref: INTEGER_REF l_pid_ref: INTEGER_REF l_read_ref: BOOLEAN_REF do create Result.make (0, w_list.count-1) from i := 0 until i >= w_list.count loop l_workitem_tuple := w_list.item (i + 1) create l_workitem.make (6) create l_wi_id_ref l_wi_id_ref.set_item (l_workitem_tuple.workitem_id) l_workitem.force (l_wi_id_ref, "workitem_id") create l_type_ref l_type_ref.set_item (l_workitem_tuple.type) l_workitem.force (l_type_ref, "type") create l_creation_time_ref l_creation_time_ref.set_item (l_workitem_tuple.creation_time) l_workitem.force (l_creation_time_ref, "creation_time") create l_pid_ref l_pid_ref.set_item (l_workitem_tuple.project_id) l_workitem.force (l_pid_ref, "project_id") l_workitem.force (l_workitem_tuple.project, "project") l_workitem.force (l_workitem_tuple.user, "user") l_workitem_data ?= l_workitem_tuple.data check l_workitem_data_valid: l_workitem_data /= Void end from l_workitem_data.start until l_workitem_data.after loop l_workitem.force (l_workitem_data.item_for_iteration, l_workitem_data.key_for_iteration) l_workitem_data.forth end create l_read_ref l_read_ref.set_item (l_workitem_tuple.is_read) l_workitem.force (l_read_ref, "is_read") Result.force (l_workitem, i) i := i + 1 end ensure valid_result: Result /= Void end feature {NONE} -- Implementation workitem_list_name: STRING is "list" workitem_list_projects_name: STRING is "list_projects" workitem_list_project_name: STRING is "list_project" workitem_retrieve_name: STRING is "retrieve" workitem_set_read_status_name: STRING is "set_read_status" workitem_set_read_status_project_name: STRING is "set_read_status_project" end