indexing description: "User send message use case." author: "Marco Zietzling " date: "$Date$" revision: "$Revision$" class USER_SEND_MESSAGE inherit AUTH_USE_CASE O_USER_CONSTANTS O_ERRORS create make feature -- Access namespace: STRING is -- Namespace of this use case. once Result := user_namespace end type: STRING is -- Message type of this use case. once Result := user_send_message_type end feature -- Basic operation start (a_msg: O_MESSAGE) is -- Start the use case by a_msg. local l_msg: O_SESSION_MESSAGE do l_msg ?= a_msg check session_message: l_msg /= Void end -- check if the user is authorized and act accordingly is_authorized_for_project (l_msg, "user_send_message", 0, auth_node) end feature {NONE} -- Callbacks handle_auth_success (a_msg: O_MESSAGE) is -- a_msg has been authorized, execute it. local l_user_message: O_USER_SEND_MESSAGE_MESSAGE l_storage_message: O_USER_SEND_MESSAGE_MESSAGE do l_user_message ?= a_msg check valid_message: l_user_message /= Void end -- send message to storage node to retrieve target email address and names create l_storage_message.make (l_user_message.session, l_user_message.username, "-", "-") l_storage_message.set_reply_handler (agent process_storage_reply (?, a_msg)) node.send_message_node (l_storage_message, "storage1") end process_storage_reply (a_msg, an_orig_msg: O_MESSAGE) is -- Process reply from storage node. Reply includes email address and names. require a_msg_not_void: a_msg /= Void an_orig_msg_not_void: an_orig_msg /= Void local l_user_message: O_USER_SEND_MESSAGE_MESSAGE l_storage_reply_message: O_USER_SEND_MESSAGE_REPLY_MESSAGE l_mail_message: O_MAIL_MESSAGE l_status_message: O_GENERAL_STATUS_MESSAGE l_sender_name: STRING l_recipient_name: STRING l_recipient_address: STRING l_subject: STRING l_text: STRING do l_user_message ?= an_orig_msg check valid_message: l_user_message /= Void end -- storage replies with O_USER_SEND_MESSAGE_REPLY_MESSAGE if everything was ok -- or with a O_GENERAL_STATUS_MESSAGE if there was an error l_storage_reply_message ?= a_msg l_status_message ?= a_msg if l_storage_reply_message /= Void then -- correct reply received, continue l_sender_name := l_storage_reply_message.sender_name l_recipient_name := l_storage_reply_message.recipient_name l_recipient_address := l_storage_reply_message.recipient_email_address l_subject := "[Origo] Message from " + l_sender_name + ": " + l_user_message.subject l_text := "Hi " + l_recipient_name + ",%N" + l_sender_name + " sent you the following message:%N%N" + l_user_message.message -- generate and send message to mail node to send mail to recipient create l_mail_message.make (l_recipient_address, l_sender_name, l_subject, l_text) node.send_message_node (l_mail_message, "mail1") -- send reply to api create l_status_message.make (True, Void) node.send_message_reply (l_status_message, an_orig_msg) elseif l_status_message /= Void then -- redirect storage reply to api node.send_message_reply (l_status_message, an_orig_msg) else -- something went completely wrong -> create own status and sent it to api create l_status_message.make (False, err_database_error) node.send_message_reply (l_status_message, an_orig_msg) end end end