indexing
description: "Wiki render html use case."
author: "Dennis Rietmann"
date: "$Date$"
revision: "$Revision$"
class
WIKI_RENDER_HTML
inherit
AUTH_USE_CASE
O_WIKI_CONSTANTS
create
make
feature -- Access
namespace: STRING is
-- Namespace of this use case.
once
Result := wiki_namespace
end
type: STRING is
-- Message type of this use case.
once
Result := wiki_render_html_type
end
feature -- Basic operation
start (a_msg: O_MESSAGE) is
-- Start the use case by a_msg.
local
l_msg: O_WIKI_RENDER_HTML_MESSAGE
do
l_msg ?= a_msg
check
valid_message: l_msg /= Void
end
-- check if the user is authorized and act accordingly
-- only members of the project can render wiki pages for it
is_authorized_for_project (l_msg, "wiki_render_html", l_msg.project_id, auth_node)
end
feature {NONE} -- Implementation
handle_auth_success (a_msg: O_MESSAGE) is
-- a_msg has been authorized, execute it.
local
l_msg: O_WIKI_RENDER_HTML_MESSAGE
l_storage_msg: O_PROJECT_MESSAGE
do
l_msg ?= a_msg
check
valid_message: l_msg /= Void
end
-- send message to storage node to retrieve project name
create l_storage_msg.make (l_msg.session, l_msg.project_id)
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_project_reply: O_PROJECT_REPLY_MESSAGE
l_wiki_render_msg: O_WIKI_RENDER_HTML_MESSAGE
l_wiki_render_reply: O_GENERAL_STRING_MESSAGE
l_status_reply: O_GENERAL_STATUS_MESSAGE
l_frontend_interactor: O_FRONTEND_INTERACTOR
l_xrpc_args: DS_ARRAYED_LIST[ANY]
l_rendered_wiki_text: STRING
do
l_wiki_render_msg ?= a_orig_msg
check
valid_message: l_wiki_render_msg /= Void
end
l_project_reply ?= a_msg
if l_project_reply /= Void then
-- call frontend to render the wiki text
create l_xrpc_args.make (1)
l_xrpc_args.put_last (l_wiki_render_msg.wiki_text)
create l_frontend_interactor.make (l_project_reply.name)
l_frontend_interactor.invoke ("formats.render_default", l_xrpc_args)
if l_frontend_interactor.invocation_ok then
l_rendered_wiki_text ?= l_frontend_interactor.last_result
check
valid_result: l_rendered_wiki_text /= Void
end
create l_wiki_render_reply.make (l_rendered_wiki_text)
node.send_message_reply (l_wiki_render_reply, a_orig_msg)
else
-- an error occurred (e.g. frontend not reachable)
create l_status_reply.make (false, "Failed to render wiki text. Please contact Origo support (project: "
+ l_project_reply.name + ", error: " + l_frontend_interactor.last_error + ")")
node.send_message_reply (l_status_reply, a_orig_msg)
end
else
-- send status from storage back to API (e.g. in case of invalid project id)
l_status_reply ?= a_msg
node.send_message_reply (l_status_reply, a_orig_msg)
end
end
end