Redesign part of CMS_MODULE, and implementation.

Prepare the module before creating the service.
Remove the possibility to add module after the creation of the service.
Renamed CMS_MODULE_CONFIGURATOR as CMS_MODULE_COLLECTION.
This commit is contained in:
2014-10-08 17:04:34 +02:00
parent 965b0e9f7d
commit 51e1058409
12 changed files with 245 additions and 220 deletions

View File

@@ -12,14 +12,21 @@ inherit
REFACTORING_HELPER REFACTORING_HELPER
create create
make make
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_layout: CMS_LAYOUT) make (a_layout: CMS_LAYOUT)
do do
layout := a_layout layout := a_layout
create configuration.make (layout) create configuration.make (layout)
initialize
end
initialize
do
configure configure
build_api_service
build_mailer
end end
configure configure
@@ -36,14 +43,6 @@ feature {NONE} -- Initialization
compute_theme_location compute_theme_location
compute_theme_resource_location compute_theme_resource_location
initialize
end
initialize
do
build_api_service
build_mailer
end end
feature -- Access feature -- Access
@@ -86,4 +85,18 @@ feature -- Access
to_implement ("Not implemented mailer") to_implement ("Not implemented mailer")
end end
feature -- Compute location
compute_theme_location
do
theme_location := themes_location.extended (theme_name)
end
compute_theme_resource_location
-- assets (js, css, images, etc)
-- Not used at the moment.
do
theme_resource_location := theme_location
end
end end

View File

@@ -9,21 +9,21 @@ deferred class
feature -- Access feature -- Access
configuration: CMS_CONFIGURATION configuration: CMS_CONFIGURATION
-- cms configuration. -- cms configuration.
layout: CMS_LAYOUT layout: CMS_LAYOUT
-- CMS layout. -- CMS layout.
api_service: CMS_API_SERVICE api_service: CMS_API_SERVICE
-- cms api service. -- cms api service.
is_html: BOOLEAN is_html: BOOLEAN
-- api with progresive enhacements css and js, server side rendering. -- api with progressive enhancements css and js, server side rendering.
deferred deferred
end end
is_web: BOOLEAN is_web: BOOLEAN
-- web: Web Site with progresive enhacements css and js and Ajax calls. -- web: Web Site with progressive enhancements css and js and Ajax calls.
deferred deferred
end end
@@ -43,14 +43,14 @@ feature -- Access: Site
files_location: PATH files_location: PATH
feature -- Access:Theme feature -- Access: Theme
themes_location: PATH themes_location: PATH
theme_location: PATH theme_location: PATH
theme_resource_location: PATH theme_resource_location: PATH
-- --
theme_information_location: PATH theme_information_location: PATH
-- theme informations. -- theme informations.
@@ -59,20 +59,6 @@ feature -- Access:Theme
end end
theme_name: READABLE_STRING_32 theme_name: READABLE_STRING_32
-- theme name -- theme name
feature -- Compute location
compute_theme_location
do
theme_location := themes_location.extended (theme_name)
end
compute_theme_resource_location
-- assets (js, css, images, etc)
-- Not used at the moment.
do
theme_resource_location := theme_location
end
end end

View File

@@ -9,6 +9,9 @@ class
inherit inherit
CMS_MODULE CMS_MODULE
redefine
filters
end
create create
make make
@@ -22,39 +25,34 @@ feature {NONE} -- Initialization
description := "Service to manage basic authentication" description := "Service to manage basic authentication"
package := "core" package := "core"
config := a_config config := a_config
setup_router
setup_filter
enable
end end
feature -- Access
router: WSF_ROUTER
-- Node router.
config: CMS_SETUP config: CMS_SETUP
-- Node configuration. -- Node configuration.
feature -- Implementation feature -- Access: router
setup_router router: WSF_ROUTER
-- Setup `router'. -- Node router.
do do
create router.make (2) create Result.make (2)
configure_api_login configure_api_login (Result)
configure_api_logoff configure_api_logoff (Result)
end end
setup_filter feature -- Access: filter
-- Setup `filter'.
filters: detachable LIST [WSF_FILTER]
-- Possibly list of Filter's module.
do do
add_filter (create {CORS_FILTER}) create {ARRAYED_LIST [WSF_FILTER]} Result.make (2)
add_filter (create {BASIC_AUTH_FILTER}.make (config)) Result.extend (create {CORS_FILTER})
Result.extend (create {BASIC_AUTH_FILTER}.make (config))
end end
feature -- Configure Node Resources Routes feature {NONE} -- Implementation: routes
configure_api_login configure_api_login (a_router: WSF_ROUTER)
local local
l_bal_handler: BASIC_AUTH_LOGIN_HANDLER l_bal_handler: BASIC_AUTH_LOGIN_HANDLER
l_methods: WSF_REQUEST_METHODS l_methods: WSF_REQUEST_METHODS
@@ -62,10 +60,10 @@ feature -- Configure Node Resources Routes
create l_bal_handler.make (config) create l_bal_handler.make (config)
create l_methods create l_methods
l_methods.enable_get l_methods.enable_get
router.handle_with_request_methods ("/basic_auth_login", l_bal_handler, l_methods) a_router.handle_with_request_methods ("/basic_auth_login", l_bal_handler, l_methods)
end end
configure_api_logoff configure_api_logoff (a_router: WSF_ROUTER)
local local
l_bal_handler: BASIC_AUTH_LOGOFF_HANDLER l_bal_handler: BASIC_AUTH_LOGOFF_HANDLER
l_methods: WSF_REQUEST_METHODS l_methods: WSF_REQUEST_METHODS
@@ -73,7 +71,7 @@ feature -- Configure Node Resources Routes
create l_bal_handler.make (config) create l_bal_handler.make (config)
create l_methods create l_methods
l_methods.enable_get l_methods.enable_get
router.handle_with_request_methods ("/basic_auth_logoff", l_bal_handler, l_methods) a_router.handle_with_request_methods ("/basic_auth_logoff", l_bal_handler, l_methods)
end end
end end

View File

@@ -31,7 +31,7 @@ feature -- Basic operations
-- A valid user -- A valid user
if (attached l_auth.type as l_auth_type and then l_auth_type.is_case_insensitive_equal_general ("basic")) and then if (attached l_auth.type as l_auth_type and then l_auth_type.is_case_insensitive_equal_general ("basic")) and then
attached l_auth.login as l_auth_login and then attached l_auth.password as l_auth_password then attached l_auth.login as l_auth_login and then attached l_auth.password as l_auth_password then
if api_service.login_valid (l_auth_login, l_auth_password) then if api_service.is_valid_credential (l_auth_login, l_auth_password) then
if attached api_service.user_by_name (l_auth_login) as l_user then if attached api_service.user_by_name (l_auth_login) as l_user then
req.set_execution_variable ("user", l_user) req.set_execution_variable ("user", l_user)
execute_next (req, res) execute_next (req, res)

View File

@@ -22,27 +22,18 @@ feature -- Router
router: WSF_ROUTER router: WSF_ROUTER
-- Router configuration. -- Router configuration.
require
is_enabled: is_enabled
deferred deferred
end end
feature -- Filter feature -- Filter
filters: detachable LIST [WSF_FILTER] filters: detachable LIST [WSF_FILTER]
-- Possibly list of Filter's module. -- Optional list of filter for Current module.
require
feature -- Element Change: Filter is_enabled: is_enabled
add_filter (a_filter: WSF_FILTER)
-- Add a filter `a_filter' to the list of module filters `filters'.
local
l_filters: like filters
do do
l_filters := filters
if l_filters = Void then
create {ARRAYED_LIST [WSF_FILTER]} l_filters.make (1)
filters := l_filters
end
l_filters.force (a_filter)
end end
feature -- Settings feature -- Settings

View File

@@ -0,0 +1,64 @@
note
description: "Summary description for {CMS_MODULE_COLLECTION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_MODULE_COLLECTION
inherit
ITERABLE [CMS_MODULE]
create
make
feature {NONE} -- Initialization
make (nb: INTEGER)
do
create modules.make (nb)
end
feature -- Access
new_cursor: INDEXABLE_ITERATION_CURSOR [CMS_MODULE]
-- <Precursor>
do
Result := modules.new_cursor
end
feature -- Status report
has (a_module: CMS_MODULE): BOOLEAN
-- Has `a_module'?
do
Result := modules.has (a_module)
end
count: INTEGER
-- Number of modules.
do
Result := modules.count
end
feature -- Element change
extend (a_module: CMS_MODULE)
-- Add module
do
modules.force (a_module)
end
remove (a_module: CMS_MODULE)
-- Remove module
do
modules.prune_all (a_module)
end
feature {NONE} -- Implementation
modules: ARRAYED_LIST [CMS_MODULE]
-- List of available modules.
end

View File

@@ -1,30 +0,0 @@
note
description: "Summary description for {CMS_MODULE_CONFIGURATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_MODULE_CONFIGURATOR
feature -- Access
modules: LIST[CMS_MODULE]
-- Possible list of modules.
deferred
end
feature -- Add Module
add_module (a_module: CMS_MODULE)
-- Add module
do
modules.force (a_module)
end
remove_module (a_module: CMS_MODULE)
-- Remove module
do
modules.prune (a_module)
end
end

View File

@@ -1,15 +1,17 @@
note note
description: "Summary description for {CMS_DEFAULT_MODULE_CONFIGURATOR}." description: "Summary description for {CMS_DEFAULT_MODULE_COLLECTION}."
author: "" author: ""
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class class
CMS_DEFAULT_MODULE_CONFIGURATOR CMS_DEFAULT_MODULE_COLLECTION
inherit inherit
CMS_MODULE_COLLECTION
CMS_MODULE_CONFIGURATOR rename
make as make_with_capacity
end
create create
make make
@@ -18,15 +20,10 @@ feature {NONE} -- Initialization
make (a_setup: CMS_SETUP) make (a_setup: CMS_SETUP)
do do
make_with_capacity (3)
build_modules (a_setup) build_modules (a_setup)
end end
feature -- Access
modules: ARRAYED_LIST [CMS_MODULE]
-- List of possible modules
feature -- Configuration feature -- Configuration
build_modules (a_setup: CMS_SETUP) build_modules (a_setup: CMS_SETUP)
@@ -35,19 +32,23 @@ feature -- Configuration
local local
m: CMS_MODULE m: CMS_MODULE
do do
create modules.make (3)
-- -- Core -- -- Core
-- create {USER_MODULE} m.make (a_setup) -- create {USER_MODULE} m.make (a_setup)
-- m.enable -- m.enable
-- modules.extend (m) -- extend (m)
-- create {ADMIN_MODULE} m.make (a_setup) -- create {ADMIN_MODULE} m.make (a_setup)
-- m.enable -- m.enable
-- modules.extend (m) -- extend (m)
create {BASIC_AUTH_MODULE} m.make (a_setup)
m.enable
extend (m)
create {NODE_MODULE} m.make (a_setup) create {NODE_MODULE} m.make (a_setup)
m.enable m.enable
modules.extend (m) extend (m)
end end
end end

View File

@@ -16,40 +16,34 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_config: CMS_SETUP) make (a_config: CMS_SETUP)
-- Create Current module, disabled by default.
do do
name := "node" name := "node"
version := "1.0" version := "1.0"
description := "Service to manage content based on 'node'" description := "Service to manage content based on 'node'"
package := "core" package := "core"
config := a_config config := a_config
setup_router
enable
end end
feature -- Access
router: WSF_ROUTER
-- Node router.
config: CMS_SETUP config: CMS_SETUP
-- Node configuration. -- Node configuration.
feature -- Implementation feature -- Access: router
setup_router router: WSF_ROUTER
-- Setup `router'. -- Node router.
do do
create router.make (5) create Result.make (5)
configure_api_node configure_api_node (Result)
configure_api_nodes configure_api_nodes (Result)
configure_api_node_title configure_api_node_title (Result)
configure_api_node_summary configure_api_node_summary (Result)
configure_api_node_content configure_api_node_content (Result)
end end
feature -- Configure Node Resources Routes feature {NONE} -- Implementation: routes
configure_api_node configure_api_node (a_router: WSF_ROUTER)
local local
l_node_handler: NODE_HANDLER l_node_handler: NODE_HANDLER
l_methods: WSF_REQUEST_METHODS l_methods: WSF_REQUEST_METHODS
@@ -59,7 +53,7 @@ feature -- Configure Node Resources Routes
l_methods.enable_get l_methods.enable_get
l_methods.enable_post l_methods.enable_post
l_methods.enable_put l_methods.enable_put
router.handle_with_request_methods ("/node", l_node_handler, l_methods) a_router.handle_with_request_methods ("/node", l_node_handler, l_methods)
create l_node_handler.make (config) create l_node_handler.make (config)
create l_methods create l_methods
@@ -67,11 +61,10 @@ feature -- Configure Node Resources Routes
l_methods.enable_post l_methods.enable_post
l_methods.enable_put l_methods.enable_put
l_methods.enable_delete l_methods.enable_delete
router.handle_with_request_methods ("/node/{id}", l_node_handler, l_methods) a_router.handle_with_request_methods ("/node/{id}", l_node_handler, l_methods)
end end
configure_api_nodes (a_router: WSF_ROUTER)
configure_api_nodes
local local
l_nodes_handler: NODES_HANDLER l_nodes_handler: NODES_HANDLER
l_methods: WSF_REQUEST_METHODS l_methods: WSF_REQUEST_METHODS
@@ -79,11 +72,10 @@ feature -- Configure Node Resources Routes
create l_nodes_handler.make (config) create l_nodes_handler.make (config)
create l_methods create l_methods
l_methods.enable_get l_methods.enable_get
router.handle_with_request_methods ("/nodes", l_nodes_handler, l_methods) a_router.handle_with_request_methods ("/nodes", l_nodes_handler, l_methods)
end end
configure_api_node_summary (a_router: WSF_ROUTER)
configure_api_node_summary
local local
l_report_handler: NODE_SUMMARY_HANDLER l_report_handler: NODE_SUMMARY_HANDLER
l_methods: WSF_REQUEST_METHODS l_methods: WSF_REQUEST_METHODS
@@ -93,11 +85,11 @@ feature -- Configure Node Resources Routes
l_methods.enable_get l_methods.enable_get
l_methods.enable_post l_methods.enable_post
l_methods.enable_put l_methods.enable_put
router.handle_with_request_methods ("/node/{id}/summary", l_report_handler, l_methods) a_router.handle_with_request_methods ("/node/{id}/summary", l_report_handler, l_methods)
end end
configure_api_node_title configure_api_node_title (a_router: WSF_ROUTER)
local local
l_report_handler: NODE_TITLE_HANDLER l_report_handler: NODE_TITLE_HANDLER
l_methods: WSF_REQUEST_METHODS l_methods: WSF_REQUEST_METHODS
@@ -107,11 +99,10 @@ feature -- Configure Node Resources Routes
l_methods.enable_get l_methods.enable_get
l_methods.enable_post l_methods.enable_post
l_methods.enable_put l_methods.enable_put
router.handle_with_request_methods ("/node/{id}/title", l_report_handler, l_methods) a_router.handle_with_request_methods ("/node/{id}/title", l_report_handler, l_methods)
end end
configure_api_node_content (a_router: WSF_ROUTER)
configure_api_node_content
local local
l_report_handler: NODE_CONTENT_HANDLER l_report_handler: NODE_CONTENT_HANDLER
l_methods: WSF_REQUEST_METHODS l_methods: WSF_REQUEST_METHODS
@@ -121,7 +112,7 @@ feature -- Configure Node Resources Routes
l_methods.enable_get l_methods.enable_get
l_methods.enable_post l_methods.enable_post
l_methods.enable_put l_methods.enable_put
router.handle_with_request_methods ("/node/{id}/content", l_report_handler, l_methods) a_router.handle_with_request_methods ("/node/{id}/content", l_report_handler, l_methods)
end end
end end

View File

@@ -12,8 +12,8 @@ inherit
REFACTORING_HELPER REFACTORING_HELPER
create make create
make
feature -- Initialize feature -- Initialize
@@ -28,7 +28,7 @@ feature -- Initialize
feature -- Access feature -- Access
login_valid (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN is_valid_credential (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN
local local
l_security: SECURITY_PROVIDER l_security: SECURITY_PROVIDER
do do
@@ -57,7 +57,6 @@ feature -- Access: Node
Result := storage.node (a_id) Result := storage.node (a_id)
end end
feature -- Change: Node feature -- Change: Node
new_node (a_node: CMS_NODE) new_node (a_node: CMS_NODE)

View File

@@ -37,79 +37,88 @@ inherit
SHARED_LOGGER SHARED_LOGGER
create create
make, make
make_with_module_configurator
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_setup: CMS_SETUP) make (a_setup: CMS_SETUP; a_modules: CMS_MODULE_COLLECTION)
-- Build a a default service with a CMS_DEFAULT_MODULE_CONFIGURATOR -- Build a a default service with a custom list of modules `a_modules'
do do
setup := a_setup setup := a_setup
configuration := a_setup.configuration configuration := a_setup.configuration
create {CMS_DEFAULT_MODULE_CONFIGURATOR} modules.make (a_setup) modules := a_modules
create {ARRAYED_LIST[WSF_FILTER]} filters.make (0)
initialize initialize
end end
make_with_module_configurator (a_setup: CMS_SETUP; a_module_configurator: CMS_MODULE_CONFIGURATOR)
-- Build a a default service with a custom CMS_MODULE_CONFIGURATOR
do
setup := a_setup
configuration := a_setup.configuration
modules := a_module_configurator
create {ARRAYED_LIST[WSF_FILTER]} filters.make (0)
initialize
end
initialize initialize
-- Initialize various parts of the CMS service.
do do
initialize_modules
initialize_users initialize_users
initialize_auth_engine initialize_auth_engine
initialize_mailer initialize_mailer
initialize_router initialize_router
initialize_modules
initialize_filter initialize_filter
end end
initialize_modules
-- Intialize modules and keep only enabled modules.
local
l_module: CMS_MODULE
coll: CMS_MODULE_COLLECTION
do
log.write_debug (generator + ".initialize_modules")
create coll.make (modules.count)
across
modules as ic
loop
l_module := ic.item
if l_module.is_enabled then
coll.extend (l_module)
end
end
modules := coll
ensure
only_enabled_modules: across modules as ic all ic.item.is_enabled end
end
initialize_users initialize_users
-- Initialize users.
do do
end end
initialize_mailer initialize_mailer
-- Initialize mailer engine.
do do
to_implement ("To Implement mailer") to_implement ("To Implement mailer")
end end
setup_router
do
configure_api_root
end
initialize_modules
-- Intialize modules, import router definitions
-- from enabled modules.
do
log.write_debug (generator + ".initialize_modules")
across
modules.modules as m
loop
if m.item.is_enabled then
router.import (m.item.router)
end
if attached m.item.filters as l_m_filters then
filters.append (l_m_filters)
end
end
configure_api_file_handler
end
initialize_auth_engine initialize_auth_engine
do do
to_implement ("To Implement authentication engine") to_implement ("To Implement authentication engine")
end end
feature -- Settings: router
setup_router
-- <Precursor>
local
l_module: CMS_MODULE
do
log.write_debug (generator + ".setup_router")
-- Configure root of api handler.
configure_api_root
-- Include routes from modules.
across
modules as ic
loop
l_module := ic.item
router.import (l_module.router)
end
-- Configure files handler.
configure_api_file_handler
end
configure_api_root configure_api_root
local local
@@ -143,7 +152,6 @@ feature -- Execute Filter
execute_filter (req: WSF_REQUEST; res: WSF_RESPONSE) execute_filter (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute the filter. -- Execute the filter.
do do
res.put_header_line ("Date: " + (create {HTTP_DATE}.make_now_utc).string) res.put_header_line ("Date: " + (create {HTTP_DATE}.make_now_utc).string)
execute_service (req, res) execute_service (req, res)
end end
@@ -154,17 +162,29 @@ feature -- Filters
-- Create `filter'. -- Create `filter'.
local local
f, l_filter: detachable WSF_FILTER f, l_filter: detachable WSF_FILTER
l_module: CMS_MODULE
do do
log.write_debug (generator + ".create_filter")
l_filter := Void l_filter := Void
-- Maintenance -- Maintenance
create {WSF_MAINTENANCE_FILTER} f create {WSF_MAINTENANCE_FILTER} f
f.set_next (l_filter) f.set_next (l_filter)
l_filter := f l_filter := f
if attached filters as l_filters then -- Include filters from modules
across l_filters as c loop across
c.item.set_next (l_filter) modules as ic
l_filter := c.item loop
l_module := ic.item
if
l_module.is_enabled and then
attached l_module.filters as l_m_filters
then
across l_m_filters as f_ic loop
f := f_ic.item
f.set_next (l_filter)
l_filter := f
end
end end
end end
@@ -176,6 +196,8 @@ feature -- Filters
local local
f: WSF_FILTER f: WSF_FILTER
do do
log.write_debug (generator + ".setup_filter")
from from
f := filter f := filter
until until
@@ -190,36 +212,23 @@ feature -- Filters
feature -- Access feature -- Access
setup: CMS_SETUP setup: CMS_SETUP
-- CMS setup. -- CMS setup.
configuration: CMS_CONFIGURATION configuration: CMS_CONFIGURATION
-- CMS configuration. -- CMS configuration.
-- | Maybe we can compute it (using `setup') instead of using memory. --| Maybe we can compute it (using `setup') instead of using memory.
modules: CMS_MODULE_CONFIGURATOR modules: CMS_MODULE_COLLECTION
-- Configurator of possible modules. -- Configurator of possible modules.
filters: LIST[WSF_FILTER]
-- List of possible filters.
feature -- Element Change: Modules
add_module (a_module: CMS_MODULE)
-- Add a module `a_module' to the module configurator `a_module'.
do
modules.add_module (a_module)
end
feature -- Execution feature -- Execution
execute_default (req: WSF_REQUEST; res: WSF_RESPONSE) execute_default (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Default request handler if no other are relevant -- Default request handler if no other are relevant
local
do do
fixme ("To Implement") fixme ("To Implement")
end end
note note
copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others" copyright: "2011-2014, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -117,24 +117,27 @@ feature -- CMS Initialization
initialize_cms (a_setup: CMS_SETUP) initialize_cms (a_setup: CMS_SETUP)
local local
cms: CMS_SERVICE cms: CMS_SERVICE
l_modules: CMS_MODULE_COLLECTION
do do
log.write_debug (generator + ".initialize_cms") log.write_debug (generator + ".initialize_cms")
create cms.make (a_setup)
setup_modules (cms) create {CMS_DEFAULT_MODULE_COLLECTION} l_modules.make (a_setup)
setup_modules (l_modules, a_setup)
create cms.make (a_setup, l_modules)
cms_service := cms cms_service := cms
end end
feature -- CMS setup feature -- CMS setup
setup_modules (a_service: CMS_SERVICE) setup_modules (a_modules: CMS_MODULE_COLLECTION; a_setup: CMS_SETUP)
-- Setup modules to be added to the CMS ecosystem. -- Setup modules to be added to the available modules.
local local
m: CMS_MODULE m: CMS_MODULE
do do
create {NODE_MODULE} m.make (a_setup)
create {NODE_MODULE} m.make (a_service.setup)
m.enable m.enable
a_service.add_module (m) a_modules.extend (m)
end end
setup_storage (a_setup: CMS_SETUP) setup_storage (a_setup: CMS_SETUP)