Update API to use CMS_STORAGE
This commit is contained in:
@@ -34,7 +34,7 @@ feature -- Factory
|
|||||||
|
|
||||||
if attached (create {JSON_CONFIGURATION}).new_database_configuration (l_layout.application_config_path) as l_database_config then
|
if attached (create {JSON_CONFIGURATION}).new_database_configuration (l_layout.application_config_path) as l_database_config then
|
||||||
create {DATABASE_CONNECTION_MYSQL} l_database.login_with_connection_string (l_database_config.connection_string)
|
create {DATABASE_CONNECTION_MYSQL} l_database.login_with_connection_string (l_database_config.connection_string)
|
||||||
create l_api_service.make_with_database (l_database)
|
create l_api_service.make (create {CMS_STORAGE_MYSQL}.make (l_database))
|
||||||
create Result.make (l_database, l_api_service, l_email_service, l_layout)
|
create Result.make (l_database, l_api_service, l_email_service, l_layout)
|
||||||
if (create {ROC_JSON_CONFIGURATION}).is_web_mode(l_layout.application_config_path) then
|
if (create {ROC_JSON_CONFIGURATION}).is_web_mode(l_layout.application_config_path) then
|
||||||
Result.mark_web
|
Result.mark_web
|
||||||
@@ -44,7 +44,7 @@ feature -- Factory
|
|||||||
set_successful
|
set_successful
|
||||||
else
|
else
|
||||||
create {DATABASE_CONNECTION_NULL} l_database.make_common
|
create {DATABASE_CONNECTION_NULL} l_database.make_common
|
||||||
create l_api_service.make_with_database (l_database)
|
create l_api_service.make (create {CMS_STORAGE_NULL})
|
||||||
create Result.make (l_database, l_api_service, l_email_service, l_layout)
|
create Result.make (l_database, l_api_service, l_email_service, l_layout)
|
||||||
set_last_error ("Database Connections", generator + ".roc_config")
|
set_last_error ("Database Connections", generator + ".roc_config")
|
||||||
log.write_error (generator + ".roc_config Error database connection" )
|
log.write_error (generator + ".roc_config Error database connection" )
|
||||||
@@ -58,7 +58,7 @@ feature -- Factory
|
|||||||
create l_email_service.make ((create {JSON_CONFIGURATION}).new_smtp_configuration(l_layout.application_config_path))
|
create l_email_service.make ((create {JSON_CONFIGURATION}).new_smtp_configuration(l_layout.application_config_path))
|
||||||
|
|
||||||
create {DATABASE_CONNECTION_NULL} l_database.make_common
|
create {DATABASE_CONNECTION_NULL} l_database.make_common
|
||||||
create l_api_service.make_with_database (l_database)
|
create l_api_service.make (create {CMS_STORAGE_NULL})
|
||||||
create Result.make (l_database, l_api_service, l_email_service, l_layout)
|
create Result.make (l_database, l_api_service, l_email_service, l_layout)
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
|
|||||||
@@ -158,12 +158,6 @@ feature -- Filters
|
|||||||
fh.custom_header.put_header ("X-ROCServer: " + version)
|
fh.custom_header.put_header ("X-ROCServer: " + version)
|
||||||
l_filter := fh
|
l_filter := fh
|
||||||
|
|
||||||
-- Cors
|
|
||||||
create {WSF_CORS_FILTER}f
|
|
||||||
f.set_next (l_filter)
|
|
||||||
l_filter := f
|
|
||||||
|
|
||||||
|
|
||||||
-- Maintenance
|
-- Maintenance
|
||||||
create {WSF_MAINTENANCE_FILTER} f
|
create {WSF_MAINTENANCE_FILTER} f
|
||||||
f.set_next (l_filter)
|
f.set_next (l_filter)
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ feature -- HTTP Methods
|
|||||||
do
|
do
|
||||||
|
|
||||||
create l_page.make (req, "layout2.tpl")
|
create l_page.make (req, "layout2.tpl")
|
||||||
l_page.set_value (api_service.recent_nodes (5), "nodes")
|
l_page.set_value (api_service.recent_nodes (0,5), "nodes")
|
||||||
l_page.set_value (is_web, "web")
|
l_page.set_value (is_web, "web")
|
||||||
l_page.set_value (roc_config.is_html, "html")
|
l_page.set_value (roc_config.is_html, "html")
|
||||||
l_page.send_to (res)
|
l_page.send_to (res)
|
||||||
|
|||||||
@@ -9,23 +9,21 @@ class
|
|||||||
inherit
|
inherit
|
||||||
|
|
||||||
SHARED_ERROR
|
SHARED_ERROR
|
||||||
|
REFACTORING_HELPER
|
||||||
|
|
||||||
|
|
||||||
create make_with_database
|
create make
|
||||||
|
|
||||||
|
|
||||||
feature -- Initialize
|
feature -- Initialize
|
||||||
|
|
||||||
make_with_database (a_connection: DATABASE_CONNECTION)
|
make (a_storage: CMS_STORAGE)
|
||||||
-- Create the API service
|
-- Create the API service with an storege `a_storage'.
|
||||||
require
|
|
||||||
is_connected: a_connection.is_connected
|
|
||||||
do
|
do
|
||||||
log.write_information (generator+".make_with_database is database connected? "+ a_connection.is_connected.out )
|
storage := a_storage
|
||||||
create node_provider.make (a_connection)
|
set_successful
|
||||||
create user_provider.make (a_connection)
|
ensure
|
||||||
post_node_provider_execution
|
storage_set: storage = a_storage
|
||||||
post_user_provider_execution
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
@@ -34,49 +32,27 @@ feature -- Access
|
|||||||
local
|
local
|
||||||
l_security: SECURITY_PROVIDER
|
l_security: SECURITY_PROVIDER
|
||||||
do
|
do
|
||||||
if attached user_provider.user_salt (l_auth_login) as l_hash then
|
Result := storage.is_valid_credential (l_auth_login, l_auth_password)
|
||||||
if attached user_provider.user_by_name (l_auth_login) as l_user then
|
|
||||||
create l_security
|
|
||||||
if
|
|
||||||
attached l_user.password as l_password and then
|
|
||||||
l_security.password_hash (l_auth_password, l_hash).is_case_insensitive_equal (l_password)
|
|
||||||
then
|
|
||||||
Result := True
|
|
||||||
else
|
|
||||||
log.write_information (generator + ".login_valid User: wrong username or password" )
|
|
||||||
end
|
|
||||||
else
|
|
||||||
log.write_information (generator + ".login_valid User:" + l_auth_login + "does not exist" )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
post_user_provider_execution
|
|
||||||
end
|
end
|
||||||
|
|
||||||
nodes: LIST[CMS_NODE]
|
nodes: LIST[CMS_NODE]
|
||||||
-- List of nodes.
|
-- List of nodes.
|
||||||
do
|
do
|
||||||
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
|
fixme ("Implementation")
|
||||||
across node_provider.nodes as c loop
|
Result := storage.recent_nodes (0, 10)
|
||||||
Result.force (c.item)
|
|
||||||
end
|
|
||||||
post_node_provider_execution
|
|
||||||
end
|
end
|
||||||
|
|
||||||
recent_nodes (a_rows: INTEGER): LIST[CMS_NODE]
|
recent_nodes (a_offset, a_rows: INTEGER): LIST[CMS_NODE]
|
||||||
-- List of the `a_rows' most recent nodes.
|
-- List of the `a_rows' most recent nodes starting from `a_offset'.
|
||||||
do
|
do
|
||||||
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
|
Result := storage.recent_nodes (a_offset, a_rows)
|
||||||
across node_provider.recent_nodes (0,a_rows) as c loop
|
|
||||||
Result.force (c.item)
|
|
||||||
end
|
|
||||||
post_node_provider_execution
|
|
||||||
end
|
end
|
||||||
|
|
||||||
node (a_id: INTEGER_64): detachable CMS_NODE
|
node (a_id: INTEGER_64): detachable CMS_NODE
|
||||||
--
|
-- Node by ID.
|
||||||
do
|
do
|
||||||
Result := node_provider.node (a_id)
|
fixme ("Check preconditions")
|
||||||
post_node_provider_execution
|
Result := storage.node (a_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -85,38 +61,35 @@ feature -- Node
|
|||||||
new_node (a_node: CMS_NODE)
|
new_node (a_node: CMS_NODE)
|
||||||
-- Add a new node
|
-- Add a new node
|
||||||
do
|
do
|
||||||
node_provider.new_node (a_node)
|
storage.save_node (a_node)
|
||||||
post_node_provider_execution
|
|
||||||
end
|
end
|
||||||
|
|
||||||
delete_node (a_id: INTEGER_64)
|
delete_node (a_id: INTEGER_64)
|
||||||
do
|
do
|
||||||
node_provider.delete_node (a_id)
|
storage.delete_node (a_id)
|
||||||
post_node_provider_execution
|
|
||||||
end
|
end
|
||||||
|
|
||||||
update_node (a_node: CMS_NODE)
|
update_node (a_node: CMS_NODE)
|
||||||
do
|
do
|
||||||
node_provider.update_node (a_node)
|
storage.update_node (a_node)
|
||||||
post_node_provider_execution
|
|
||||||
end
|
end
|
||||||
|
|
||||||
update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32)
|
update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32)
|
||||||
do
|
do
|
||||||
node_provider.update_node_title (a_id, a_title)
|
fixme ("Check preconditions")
|
||||||
post_node_provider_execution
|
storage.update_node_title (a_id, a_title)
|
||||||
end
|
end
|
||||||
|
|
||||||
update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32)
|
update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32)
|
||||||
do
|
do
|
||||||
node_provider.update_node_summary (a_id, a_summary)
|
fixme ("Check preconditions")
|
||||||
post_node_provider_execution
|
storage.update_node_summary (a_id, a_summary)
|
||||||
end
|
end
|
||||||
|
|
||||||
update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32)
|
update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32)
|
||||||
do
|
do
|
||||||
node_provider.update_node_content (a_id, a_content)
|
fixme ("Check preconditions")
|
||||||
post_node_provider_execution
|
storage.update_node_content (a_id, a_content)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -129,40 +102,17 @@ feature -- User
|
|||||||
attached a_user.password as l_password and then
|
attached a_user.password as l_password and then
|
||||||
attached a_user.email as l_email
|
attached a_user.email as l_email
|
||||||
then
|
then
|
||||||
user_provider.new_user (a_user.name, l_password, l_email)
|
storage.save_user (a_user)
|
||||||
else
|
else
|
||||||
-- set error
|
fixme ("Add error")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Post process
|
|
||||||
|
|
||||||
post_node_provider_execution
|
feature {NONE} -- Implemenataion
|
||||||
do
|
|
||||||
if node_provider.successful then
|
|
||||||
set_successful
|
|
||||||
else
|
|
||||||
if attached node_provider.last_error then
|
|
||||||
set_last_error_from_handler (node_provider.last_error)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
post_user_provider_execution
|
|
||||||
do
|
|
||||||
if user_provider.successful then
|
|
||||||
set_successful
|
|
||||||
else
|
|
||||||
if attached user_provider.last_error then
|
|
||||||
set_last_error_from_handler (user_provider.last_error)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
node_provider: NODE_DATA_PROVIDER
|
storage: CMS_STORAGE
|
||||||
-- Node Data provider.
|
-- Persistence storage
|
||||||
|
|
||||||
user_provider: USER_DATA_PROVIDER
|
|
||||||
-- User Data provider.
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
105
persistence/implementation/common/cms_storage_null.e
Normal file
105
persistence/implementation/common/cms_storage_null.e
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
note
|
||||||
|
description: "Summary description for {CMS_STORAGE_NULL}."
|
||||||
|
date: "$Date$"
|
||||||
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
class
|
||||||
|
CMS_STORAGE_NULL
|
||||||
|
|
||||||
|
inherit
|
||||||
|
|
||||||
|
CMS_STORAGE
|
||||||
|
REFACTORING_HELPER
|
||||||
|
|
||||||
|
|
||||||
|
feature -- Access: user
|
||||||
|
|
||||||
|
has_user: BOOLEAN
|
||||||
|
-- Has any user?
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
all_users: LIST [CMS_USER]
|
||||||
|
do
|
||||||
|
create {ARRAYED_LIST[CMS_USER]} Result.make (0)
|
||||||
|
end
|
||||||
|
|
||||||
|
user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
is_valid_credential (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Change: user
|
||||||
|
|
||||||
|
save_user (a_user: CMS_USER)
|
||||||
|
-- Add a new user `a_user'.
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Access: node
|
||||||
|
|
||||||
|
nodes: LIST[CMS_NODE]
|
||||||
|
-- List of nodes.
|
||||||
|
do
|
||||||
|
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
|
||||||
|
end
|
||||||
|
|
||||||
|
recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
|
||||||
|
-- List of the `a_count' most recent nodes, starting from `a_lower'.
|
||||||
|
do
|
||||||
|
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
|
||||||
|
end
|
||||||
|
|
||||||
|
node (a_id: INTEGER_64): detachable CMS_NODE
|
||||||
|
--
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
feature -- Node
|
||||||
|
|
||||||
|
save_node (a_node: CMS_NODE)
|
||||||
|
-- Add a new node
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
delete_node (a_id: INTEGER_64)
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
update_node (a_node: CMS_NODE)
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32)
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32)
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32)
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- User
|
||||||
|
|
||||||
|
new_user (a_user: CMS_USER)
|
||||||
|
-- Add a new user `a_user'.
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user