indexing description: "Issue add use case." author: "Peter Wyss " date: "$Date$" revision: "$Revision$" class ISSUE_ADD inherit AUTH_USE_CASE O_ISSUE_CONSTANTS create make feature -- Access namespace: STRING is -- Namespace of this use case. once Result := issue_namespace end type: STRING is -- Message type of this use case. once Result := issue_add_type end feature -- Basic operation start (a_msg: O_MESSAGE) is -- Start the use case by a_msg. local l_msg: O_ISSUE_ADD_MESSAGE do l_msg ?= a_msg check valid_message: l_msg /= Void end -- check if the user is authorized and act accordingly is_authorized_for_project (l_msg, "issue_add", l_msg.project, auth_node) end feature {NONE} -- Callbacks handle_auth_success (a_msg: O_MESSAGE) is -- a_msg has been authorized, execute it. local l_msg: O_ISSUE_ADD_MESSAGE l_storage_msg: O_ISSUE_ADD_MESSAGE do l_msg ?= a_msg check valid_message: l_msg /= Void end -- send message to storage node create l_storage_msg.make (l_msg.session, l_msg.project, l_msg.title, l_msg.description, l_msg.tags, l_msg.is_private, l_msg.is_internal) l_storage_msg.set_reply_handler (agent process_storage_reply (?, a_msg)) node.send_message_node (l_storage_msg, "storage1") end process_storage_reply (a_msg, a_orig_msg: O_MESSAGE) is -- Process reply from storage node. require a_msg_not_void: a_msg /= Void a_orig_msg_not_void: a_orig_msg /= Void local l_workitem_add_reply: O_GENERIC_MESSAGE l_issue_add_msg: O_ISSUE_ADD_MESSAGE l_status_reply: O_GENERAL_STATUS_MESSAGE l_mail_addressses_msg: O_WORKITEM_MAIL_MESSAGE l_issue_add_reply: O_GENERIC_MESSAGE l_frontend_update_error_msg: STRING do l_issue_add_msg ?= a_orig_msg check valid_message: l_issue_add_msg /= Void end l_workitem_add_reply ?= a_msg if l_workitem_add_reply /= Void then -- update frontend database l_frontend_update_error_msg := update_frontend(l_issue_add_msg, l_workitem_add_reply) if l_frontend_update_error_msg = Void then -- return project issue id to API create l_issue_add_reply.make (issue_namespace, issue_id_type) l_issue_add_reply.add_argument ("project_issue_id", l_workitem_add_reply.arguments.item ("project_issue_id")) node.send_message_reply (l_issue_add_reply, a_orig_msg) -- send mails to users create l_mail_addressses_msg.make (l_workitem_add_reply.arguments.item ("workitem_id").to_integer) l_mail_addressses_msg.set_reply_handler (agent process_mail_reply (?, a_msg)) node.send_message_node (l_mail_addressses_msg, "storage1") else -- frontend update failed create l_status_reply.make (false, l_frontend_update_error_msg) node.send_message_reply (l_status_reply, a_orig_msg) end else l_status_reply ?= a_msg -- send status from storage back to API node.send_message_reply (l_status_reply, a_orig_msg) end end process_mail_reply (a_msg, a_orig_msg: O_MESSAGE) is -- Process reply from storage node for mail addresses. local l_mail_msg: O_MAIL_MESSAGE l_workitem_mail_reply: O_WORKITEM_MAIL_REPLY_MESSAGE do l_workitem_mail_reply ?= a_msg check valid_message: l_workitem_mail_reply /= Void end from l_workitem_mail_reply.addresses.start until l_workitem_mail_reply.addresses.after loop create l_mail_msg.make (l_workitem_mail_reply.addresses.item, l_workitem_mail_reply.sender, l_workitem_mail_reply.subject, l_workitem_mail_reply.body) node.send_message_node (l_mail_msg, "mail1") l_workitem_mail_reply.addresses.forth end end feature -- Frontend synchronization update_frontend(a_issue_add_msg: O_ISSUE_ADD_MESSAGE; workitem_add_reply: O_GENERIC_MESSAGE) : STRING is -- Adds the issue in the frontend -- If an error occurred the error message is returned, 'Void' otherwise local l_frontend_interactor: O_FRONTEND_INTERACTOR l_xrpc_args: DS_ARRAYED_LIST[ANY] l_is_private: BOOLEAN_REF l_project_issue_id: INTEGER l_project_name: STRING l_call_ok: BOOLEAN_REF do -- Only update the frontend if necessary if not node.standalone_mode and not a_issue_add_msg.is_internal then l_project_issue_id := workitem_add_reply.arguments.item ("project_issue_id").to_integer l_project_name := workitem_add_reply.arguments.item ("project_name") create l_xrpc_args.make(6) l_xrpc_args.put_last (l_project_issue_id) l_xrpc_args.put_last (workitem_add_reply.arguments.item ("user")) l_xrpc_args.put_last (a_issue_add_msg.title) l_xrpc_args.put_last (a_issue_add_msg.description) l_xrpc_args.put_last (a_issue_add_msg.tags) create l_is_private l_is_private.set_item (a_issue_add_msg.is_private) l_xrpc_args.put_last (l_is_private) create l_frontend_interactor.make (l_project_name) l_frontend_interactor.invoke ("issue.add", l_xrpc_args) if l_frontend_interactor.invocation_ok then -- check if the call succeeded l_call_ok ?= l_frontend_interactor.last_result check valid_result: l_call_ok /= Void end if not l_call_ok.item then -- call failed (internal error) Result := "Failed to insert issue in the web frontend. Please contact Origo support (project: " + l_project_name + ", issue id: " + l_project_issue_id.out + ")" end else -- drupal xrpc invocation failed (e.g. connection problems) Result := "Failed to insert issue in the web frontend. Please contact Origo support (project: " + l_project_name + ", issue id: " + l_project_issue_id.out + ", error: " + l_frontend_interactor.last_error + ")" end end end end