indexing description: "User process friendship request use case." author: "Marco Zietzling " date: "$Date$" revision: "$Revision$" class USER_PROCESS_FRIENDSHIP_REQUEST 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_process_friendship_request_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_add_friendship", 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_PROCESS_FRIENDSHIP_REQUEST_MESSAGE l_storage_message: O_USER_PROCESS_FRIENDSHIP_REQUEST_MESSAGE do l_user_message ?= a_msg check valid_message: l_user_message /= Void end -- send message to storage node to update DB and retrieve reply with more information create l_storage_message.make (l_user_message.session, l_user_message.requester, l_user_message.accept) 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. require a_msg_not_void: a_msg /= Void an_orig_msg_not_void: an_orig_msg /= Void local l_user_message: O_USER_PROCESS_FRIENDSHIP_REQUEST_MESSAGE l_storage_reply_message: O_USER_PROCESS_FRIENDSHIP_REQUEST_REPLY_MESSAGE l_mail_message: O_MAIL_MESSAGE l_status_message: O_GENERAL_STATUS_MESSAGE l_requestee_name: STRING l_recipient: 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_CONFIRM_FRIENDSHIP_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 if l_storage_reply_message.requestee_name.is_empty then l_requestee_name := l_storage_reply_message.requestee_username else l_requestee_name := l_storage_reply_message.requestee_name + " (" + l_storage_reply_message.requestee_username + ")" end l_recipient := l_storage_reply_message.requester_mail_address if l_user_message.accept then l_subject := "[Origo] Friendship Request Confirmed" l_text := "User " + l_requestee_name + " has confirmed your request. You are now friends." else l_subject := "[Origo] Friendship Request Rejected" l_text := "User " + l_requestee_name + " has rejected your request." end -- generate and send message to mail node to send mail to requestee create l_mail_message.make (l_recipient, l_storage_reply_message.requestee_username, 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