indexing description: "Release add use case." author: "$Author$" date: "$Date$" revision: "$Revision$" class RELEASE_ADD inherit AUTH_USE_CASE O_RELEASE_CONSTANTS O_CONFIG_CONSTANTS create make feature -- Access namespace: STRING is -- Namespace of this use case. once Result := release_namespace end type: STRING is -- Message type of this use case. once Result := release_add_type end feature -- Basic operation start (a_msg: O_MESSAGE) is -- Start the use case by `a_msg'. local l_msg: O_RELEASE_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, "release_add", l_msg.project_id, auth_node) end feature {NONE} -- Callbacks handle_auth_success (a_msg: O_MESSAGE) is -- `a_msg' has been authorized, execute it. local l_release_add: O_RELEASE_ADD_MESSAGE l_storage_msg: O_RELEASE_ADD_MESSAGE do l_release_add ?= a_msg check valid_message: l_release_add /= Void end -- store release data in db (and create workitems) create l_storage_msg.make (l_release_add.session, l_release_add.project_id, l_release_add.name, l_release_add.description, l_release_add.version, l_release_add.files) l_storage_msg.set_reply_handler (agent process_storage_workitem_reply (?, a_msg)) node.send_message_node (l_storage_msg, "storage1") end process_storage_workitem_reply (a_msg, a_orig_msg: O_MESSAGE) is -- Process reply from storage node, send 'move files' message to config node and 'send workitem mails' to mail node require a_msg_not_void: a_msg /= Void a_orig_msg_not_void: a_orig_msg /= Void local -- incoming messages l_workitem_add_reply: O_GENERIC_MESSAGE l_release_add: O_RELEASE_ADD_MESSAGE l_status_reply: O_GENERAL_STATUS_MESSAGE -- outgoing messages l_conf: O_GENERIC_MESSAGE l_mail_addresses_msg: O_WORKITEM_MAIL_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_release_id: STRING -- the id of the new release do l_release_add ?= a_orig_msg check valid_message: l_release_add /= Void end -- send file move order to config node l_release_id := a_msg.arguments.item ("release_id") create l_conf.make (config_namespace, config_release_move_file_type) from l_release_add.files.start until l_release_add.files.after loop l_conf.add_argument (l_release_add.files.item.name.out, "/usr/local/lib/origo/origo-release-move.sh " + a_msg.arguments.item ("user_name").out + " " + a_msg.arguments.item ("project_name").out + " %"" + l_release_add.files.item.name.out + "%" " + l_release_id) l_release_add.files.forth end node.send_message_node (l_conf, "config1") -- if workitem creation failed a {O_GENERAL_STATUS_MESSAGE} l_status_reply ?= a_msg if l_status_reply = Void then create l_status.make (True, Void) node.send_message_reply (l_status, a_orig_msg) -- send mails to users l_workitem_add_reply ?= a_msg if l_workitem_add_reply /= Void then create l_mail_addresses_msg.make (l_workitem_add_reply.arguments.item ("workitem_id").to_integer) l_mail_addresses_msg.set_reply_handler (agent process_mail_reply (?, a_msg)) node.send_message_node (l_mail_addresses_msg, "storage1") end else -- 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 end