note description: "Provide an interface to workitem data." author: "$Author$" date: "$Date$" revision: "$Revision$" class WORKITEM_INTERFACE inherit BASE_INTERFACE O_WORKITEM_CONSTANTS create make feature -- Interface workitem_count (a_msg: A_MESSAGE) -- Returns the number of workitems for a given user. require a_msg_ok: a_msg /= Void local l_msg: O_WORKITEM_COUNT_MESSAGE l_reply: O_WORKITEM_COUNT_REPLY_MESSAGE l_status: A_GENERAL_STATUS_MESSAGE do l_msg ?= a_msg check workitem_list_message: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session.value) if user_access.is_found then workitem_access.count ( user_access.last_user.user_id, l_msg.project_id_list.sequence, l_msg.filter_type, l_msg.unread_only) create l_reply.make (workitem_access.last_workitem_count) node.send_message_reply (l_reply, a_msg) else create l_status.make (False, err_session_timeout) node.send_message_reply (l_status, a_msg) end end workitem_list (a_msg: A_MESSAGE) -- List workitems. require a_msg_ok: a_msg /= Void local l_msg: O_WORKITEM_LIST_MESSAGE l_reply: O_WORKITEM_LIST_REPLY_MESSAGE l_workitems: DS_ARRAYED_LIST [WI_WORKITEM] l_reply_list: DS_ARRAYED_LIST [O_WORKITEM_WORKITEM_MESSAGE] l_status: A_GENERAL_STATUS_MESSAGE do l_msg ?= a_msg check workitem_list_message: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session.value) if user_access.is_found then -- retrieve workitems from DB workitem_access.list_workitems ( user_access.last_user.user_id, l_msg.project_id_list.sequence, l_msg.filter_type, l_msg.unread_only, l_msg.start, l_msg.limit, l_msg.sort_column, l_msg.sort_order) l_workitems := workitem_access.last_workitem_list from l_workitems.start create l_reply_list.make (l_workitems.count) until l_workitems.after loop l_reply_list.force_last (l_workitems.item_for_iteration.as_workitem) -- Increment l_workitems.forth end create l_reply.make (l_reply_list) node.send_message_reply (l_reply, a_msg) else create l_status.make (False, err_session_timeout) node.send_message_reply (l_status, a_msg) end end new_activity (a_msg: A_MESSAGE) -- Retrieves a list of projects where there are new work items for the user. require a_msg_ok: a_msg /= Void local l_msg: O_WORKITEM_NEW_ACTIVITY_MESSAGE l_reply_list: DS_ARRAYED_LIST [A_INTEGER_VALUE] l_reply: O_WORKITEM_NEW_ACTIVITY_REPLY_MESSAGE l_status: A_GENERAL_STATUS_MESSAGE do l_msg ?= a_msg check workitem_message: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session.value) if user_access.is_found then workitem_access.new_for_project (user_access.last_user.user_id) create l_reply_list.make (workitem_access.last_project_id_list.count) from workitem_access.last_project_id_list.start until workitem_access.last_project_id_list.after loop l_reply_list.force_last (workitem_access.last_project_id_list.item_for_iteration) -- Increment workitem_access.last_project_id_list.forth end create l_reply.make (l_reply_list) node.send_message_reply (l_reply, a_msg) else create l_status.make (False, err_session_timeout) node.send_message_reply (l_status, a_msg) end end workitem_retrieve (a_msg: A_MESSAGE) -- Retrieve workitem. require a_msg_ok: a_msg /= Void local l_msg: O_WORKITEM_RETRIEVE_MESSAGE l_workitems: DS_ARRAYED_LIST [WI_FULL_WORKITEM] l_reply_list: DS_ARRAYED_LIST [O_WORKITEM_FULL_WORKITEM_MESSAGE] l_reply: O_WORKITEM_RETRIEVE_REPLY_MESSAGE l_status: A_GENERAL_STATUS_MESSAGE do l_msg ?= a_msg check workitem_message: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session.value) if user_access.is_found then -- retrieve workitems from DB workitem_access.retrieve_workitems (user_access.last_user.user_id, l_msg.workitem_id_list.sequence) l_workitems := workitem_access.last_full_workitem_list from l_workitems.start create l_reply_list.make (l_workitems.count) until l_workitems.after loop l_reply_list.force_last (l_workitems.item_for_iteration.as_full_workitem_message) -- inc l_workitems.forth end create l_reply.make (l_reply_list) node.send_message_reply (l_reply, a_msg) else create l_status.make (False, err_session_timeout) node.send_message_reply (l_status, a_msg) end end workitem_set_read_status (a_msg: A_MESSAGE) -- Mark workitem as read or unread corresponding to read_status require a_msg_ok: a_msg /= Void local l_msg: O_WORKITEM_SET_READ_STATUS_MESSAGE l_status: A_GENERAL_STATUS_MESSAGE l_session: SESSION do l_msg ?= a_msg check valid_msg: l_msg /= Void end -- session valid? user_access.retrieve_session_by_id (l_msg.session.value) if user_access.is_found then l_session := user_access.last_session user_access.retrieve_user_by_id (l_session.user_id) if user_access.is_found then if workitem_access.workitem_exists (l_msg.workitem_id) then if l_msg.read_status.value then workitem_access.insert_read_workitem (l_session.user_id, l_msg.workitem_id) else workitem_access.delete_read_workitem (l_session.user_id, l_msg.workitem_id) end create l_status.make (True, Void) else create l_status.make (False, err_invalid_workitem) end else create l_status.make (False, err_invalid_user) end else create l_status.make (False, err_session_timeout) end -- send status node.send_message_reply (l_status, a_msg) end workitem_set_read_status_project (a_msg: A_MESSAGE) -- Mark all workitems in project as read or unread corresponding to read_status require a_msg_ok: a_msg /= Void local l_msg: O_WORKITEM_SET_READ_STATUS_PROJECT_MESSAGE l_status: A_GENERAL_STATUS_MESSAGE l_session: SESSION l_workitems: ARRAYED_LIST [INTEGER] do l_msg ?= a_msg check valid_msg: l_msg /= Void end -- session valid? user_access.retrieve_session_by_id (l_msg.session.value) if user_access.is_found then l_session := user_access.last_session user_access.retrieve_user_by_id (l_session.user_id) if user_access.is_found then project_access.retrieve_project_by_id (l_msg.project_id.value.to_integer) if project_access.is_found then l_workitems := workitem_access.retrieve_workitem_ids_project (project_access.last_project.project_id) if l_msg.read_status.value then from l_workitems.start until l_workitems.after loop workitem_access.insert_read_workitem (l_session.user_id, l_workitems.item.to_integer) l_workitems.forth end else from l_workitems.start until l_workitems.after loop workitem_access.delete_read_workitem (l_session.user_id, l_workitems.item.to_integer) l_workitems.forth end end create l_status.make (True, "") else create l_status.make (False, err_invalid_project) end else create l_status.make (False, err_invalid_user) end else create l_status.make (False, err_session_timeout) end -- send status node.send_message_reply (l_status, a_msg) end workitem_mail (a_msg: A_MESSAGE) -- Get mail content and addresses of users who are to be informed about a workitem. require a_msg_ok: a_msg /= Void local l_addresses_reply_msg: O_WORKITEM_MAIL_REPLY_MESSAGE l_msg: O_WORKITEM_MAIL_MESSAGE l_addresses: ARRAY [STRING] l_address_list: DS_ARRAYED_LIST [A_STRING_VALUE] l_sender: STRING l_subject: STRING l_body: STRING l_wi: WI_FULL_WORKITEM i: INTEGER do l_msg ?= a_msg check valid_message: l_msg /= Void end workitem_access.retrieve_workitems ( 0, create {DS_ARRAYED_LIST [A_INTEGER_VALUE]}.make_from_array ( << l_msg.workitem_id >>)) if workitem_access.is_found then l_wi := workitem_access.last_full_workitem_list.first if l_wi /= Void then -- get mail content l_sender := l_wi.user_name l_subject := l_wi.get_notification_title l_body := l_wi.get_notification_details -- add disclaimer l_body.append("%N%N%N-- %NThis is an Origo work item mail for which you subscribed. %NYou can edit your work item subscriptions at http://" + config_parser.get ("origo_domain") + "/origo_home/settings/subscriptions") -- get affected users l_wi.retrieve_affected_users (workitem_access) l_addresses := l_wi.last_affected_users.to_array else -- Workitem not found. -- Raise error? bherlig, 2010-03-08 end else l_sender := "noreply@origo.ethz.ch" l_subject := "" l_body := "" create l_addresses.make_from_array (<<>>) end -- convert the address set to an address list create l_address_list.make (l_addresses.count) from i := l_addresses.lower until i > l_addresses.upper loop l_address_list.force_last (l_addresses[i].twin) -- Increment i := i + 1 end create l_addresses_reply_msg.make ( l_subject, l_body, l_sender, -- Sender create {A_SEQUENCE_VALUE [A_STRING_VALUE]}.make (l_address_list)) node.send_message_reply (l_addresses_reply_msg, a_msg) end end