diff --git a/cms-safe.ecf b/cms-safe.ecf index 03e697d..0c11bd8 100644 --- a/cms-safe.ecf +++ b/cms-safe.ecf @@ -15,7 +15,6 @@ - diff --git a/examples/demo/demo-safe.ecf b/examples/demo/demo-safe.ecf index e09123b..b0b7ae1 100644 --- a/examples/demo/demo-safe.ecf +++ b/examples/demo/demo-safe.ecf @@ -9,10 +9,13 @@ + + + @@ -26,6 +29,7 @@ + diff --git a/examples/demo/site/config/cms.ini b/examples/demo/site/config/cms.ini index 05a3774..5879f35 100644 --- a/examples/demo/site/config/cms.ini +++ b/examples/demo/site/config/cms.ini @@ -1,6 +1,11 @@ -engine=smarty -site.name=EWF Web CMS -site.email=your@email.com -var-dir=var -files-dir=files +[layout] +root-dir=site/www +themes-dir=site/www/themes + +[site] +name=Eiffel CMS +email=your@email.com theme=bootstrap + +[misc] +smtp=localhost diff --git a/examples/demo/src/ewf_roc_server.e b/examples/demo/src/ewf_roc_server.e index 3fb8aca..a1bd205 100644 --- a/examples/demo/src/ewf_roc_server.e +++ b/examples/demo/src/ewf_roc_server.e @@ -2,8 +2,8 @@ note description: "[ application service ]" - date: "$Date: 2014-11-20 15:03:29 +0100 (jeu., 20 nov. 2014) $" - revision: "$Revision: 96138 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class EWF_ROC_SERVER @@ -147,6 +147,9 @@ feature -- CMS setup debug ("refactor_fixme") to_implement ("To implement custom storage") end + a_setup.storage_drivers.force (create {CMS_STORAGE_MYSQL_BUILDER}.make, "mysql") + a_setup.storage_drivers.force (create {CMS_STORAGE_SQLITE_BUILDER}.make, "sqlite") end + end diff --git a/library/layout/src/configuration/application_json_configuration_helper.e b/library/layout/src/configuration/application_json_configuration_helper.e index 992e4bf..2f2077a 100644 --- a/library/layout/src/configuration/application_json_configuration_helper.e +++ b/library/layout/src/configuration/application_json_configuration_helper.e @@ -1,7 +1,7 @@ note description: "Provide access to json configuration" - date: "$Date: 2015-01-14 16:13:47 +0100 (mer., 14 janv. 2015) $" - revision: "$Revision: 96454 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class APPLICATION_JSON_CONFIGURATION_HELPER @@ -47,7 +47,7 @@ feature -- Application Configuration attached {JSON_OBJECT} l_environments.item (l_envrionment.item) as l_environment_selected and then attached {JSON_STRING} l_environment_selected.item ("connection_string") as l_connection_string then - create Result.make (l_driver.item, l_connection_string.unescaped_string_8) + create Result.make (l_driver.item, l_connection_string.unescaped_string_32) end end end diff --git a/library/layout/src/configuration/database_configuration.e b/library/layout/src/configuration/database_configuration.e index 028a5dd..4d7de25 100644 --- a/library/layout/src/configuration/database_configuration.e +++ b/library/layout/src/configuration/database_configuration.e @@ -1,7 +1,7 @@ note description: "Object that represent Database configuration settings" - date: "$Date: 2015-01-14 16:13:47 +0100 (mer., 14 janv. 2015) $" - revision: "$Revision: 96454 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class DATABASE_CONFIGURATION @@ -33,10 +33,65 @@ feature -- Access connection_string: READABLE_STRING_32 -- Connection string do - Result := "Driver={"+driver+"};" + database_string; + Result := "Driver={" + driver + "};" + database_string end + item (a_param: READABLE_STRING_GENERAL): detachable READABLE_STRING_32 + local + s: READABLE_STRING_32 + lower_s: READABLE_STRING_32 + i,j: INTEGER + k: STRING_32 + do + create k.make_from_string_general (a_param) + k.to_lower + + s := database_string + lower_s := s.as_lower + i := lower_s.substring_index (k + {STRING_32} "=", 1) + if i > 0 then + if i = 1 or else s[i-1] = ';' then + j := s.index_of (';', i + k.count + 1) + if j = 0 then + j := s.count + 1 + end + Result := s.substring (i + k.count + 1, j - 1) + end + end + end + + server_name: detachable READABLE_STRING_32 + do + Result := item ("Server") + end + + port: INTEGER + do + if + attached item ("Port") as l_port and then + l_port.is_integer + then + Result := l_port.to_integer + end + end + + database_name: detachable READABLE_STRING_32 + do + Result := item ("Database") + end + + user_id: detachable READABLE_STRING_32 + do + Result := item ("Uid") + end + + user_password: detachable READABLE_STRING_32 + do + Result := item ("Pwd") + end + + note - copyright: "2011-2014, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" + copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" end diff --git a/library/layout/src/logger/shared_logger.e b/library/layout/src/logger/shared_logger.e index 9f6996f..35c4917 100644 --- a/library/layout/src/logger/shared_logger.e +++ b/library/layout/src/logger/shared_logger.e @@ -1,7 +1,7 @@ note description: "Provides logger information" - date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $" - revision: "$Revision: 95678 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class SHARED_LOGGER @@ -29,7 +29,7 @@ feature -- Logger create l_environment if attached separate_character_option_value ('d') as l_dir then l_path := create {PATH}.make_from_string (l_dir) - create l_log_writer.make_at_location (l_path.extended ("..").appended ("\api.log")) + create l_log_writer.make_at_location (l_path.extended ("logs").appended ("\api.log")) else l_path := create {PATH}.make_current create l_log_writer.make_at_location (l_path.extended("api.log")) @@ -82,23 +82,26 @@ feature {NONE} -- JSON do create Result if attached json_file_from (a_path) as json_file then - l_parser := new_json_parser (json_file) - if attached {JSON_OBJECT} l_parser.parse as jv and then l_parser.is_parsed and then - attached {JSON_OBJECT} jv.item ("logger") as l_logger and then - attached {JSON_STRING} l_logger.item ("backup_count") as l_count and then - attached {JSON_STRING} l_logger.item ("level") as l_level then - Result.set_level (l_level.item) - if l_count.item.is_natural then - Result.set_backup_count (l_count.item.to_natural) - end - end + l_parser := new_json_parser (json_file) + if attached {JSON_OBJECT} l_parser.parse as jv and then l_parser.is_parsed and then + attached {JSON_OBJECT} jv.item ("logger") as l_logger and then + attached {JSON_STRING} l_logger.item ("backup_count") as l_count and then + attached {JSON_STRING} l_logger.item ("level") as l_level then + Result.set_level (l_level.item) + if l_count.item.is_natural then + Result.set_backup_count (l_count.item.to_natural) + end + end end end - json_file_from (a_fn: PATH): detachable STRING + local + ut: FILE_UTILITIES do - Result := (create {JSON_FILE_READER}).read_json_from (a_fn.name.out) + if ut.file_path_exists (a_fn) then + Result := (create {JSON_FILE_READER}).read_json_from (a_fn.name) + end end new_json_parser (a_string: STRING): JSON_PARSER @@ -107,6 +110,6 @@ feature {NONE} -- JSON end note - copyright: "2011-2014, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" + copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" end diff --git a/library/model/src/content/cms_node.e b/library/model/src/content/cms_node.e index 13010bd..8735e72 100644 --- a/library/model/src/content/cms_node.e +++ b/library/model/src/content/cms_node.e @@ -3,8 +3,8 @@ note CMS abstraction for CMS content entity, named "node". ]" status: "draft" - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class CMS_NODE @@ -83,8 +83,8 @@ feature -- Access author: detachable CMS_USER -- Author of current node. - collaborators: detachable LIST[CMS_USER] - -- Users contributed to current Node. +-- collaborators: detachable LIST[CMS_USER] +-- -- Users contributed to current Node. feature -- status report @@ -177,18 +177,18 @@ feature -- Element change auther_set: author = u end - add_collaborator (a_user: CMS_USER) - -- Add collaborator `a_user' to the collaborators list. - local - lst: like collaborators - do - lst := collaborators - if lst = Void then - create {ARRAYED_SET [CMS_USER]} lst.make (1) - collaborators := lst - end - lst.force (a_user) - end +-- add_collaborator (a_user: CMS_USER) +-- -- Add collaborator `a_user' to the collaborators list. +-- local +-- lst: like collaborators +-- do +-- lst := collaborators +-- if lst = Void then +-- create {ARRAYED_SET [CMS_USER]} lst.make (1) +-- collaborators := lst +-- end +-- lst.force (a_user) +-- end note copyright: "2011-2014, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" diff --git a/library/model/src/user/cms_user.e b/library/model/src/user/cms_user.e index b50de8a..6491893 100644 --- a/library/model/src/user/cms_user.e +++ b/library/model/src/user/cms_user.e @@ -2,8 +2,8 @@ note description: "[ Interface representing a USER in the CMS system. ]" - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class CMS_USER @@ -13,19 +13,38 @@ inherit DEBUG_OUTPUT create - make + make, + make_with_id -- MAYBE: export to CMS_STORAGE feature {NONE} -- Initialization make (a_name: READABLE_STRING_32) -- Create an object with name `a_name'. + require + a_name_not_empty: not a_name.is_whitespace do name := a_name - create creation_date.make_now_utc + initialize ensure name_set: name = a_name end + make_with_id (a_id: INTEGER_64) + require + a_id_valid: a_id > 0 + do + id := a_id + name := {STRING_32} "" + initialize + ensure + id_set: id = a_id + end + + initialize + do + create creation_date.make_now_utc + end + feature -- Access id: INTEGER_64 @@ -35,7 +54,10 @@ feature -- Access -- User name. password: detachable READABLE_STRING_32 - -- User password. + -- User password (plain text password). + + hashed_password: detachable READABLE_STRING_8 + -- Hashed user password. email: detachable READABLE_STRING_32 -- User email. @@ -113,8 +135,20 @@ feature -- Change element -- Set `password' with `a_password'. do password := a_password + hashed_password := Void ensure password_set: password = a_password + hashed_password_void: hashed_password = Void + end + + set_hashed_password (a_hashed_password: like hashed_password) + -- Set `hashed_password' with `a_hashed_password'. + do + hashed_password := a_hashed_password + password := Void + ensure + password_void: password = Void + hashed_password_set: hashed_password = a_hashed_password end set_email (a_email: like email) @@ -178,6 +212,10 @@ feature -- Change element: data end end +invariant + + id_or_name_set: id > 0 or else not name.is_whitespace + note copyright: "2011-2014, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" diff --git a/library/persistence/implementation/common/cms_storage_store_sql.e b/library/persistence/implementation/common/cms_storage_store_sql.e new file mode 100644 index 0000000..bd41408 --- /dev/null +++ b/library/persistence/implementation/common/cms_storage_store_sql.e @@ -0,0 +1,111 @@ +note + description: "Summary description for {CMS_STORAGE_STORE_SQL}." + author: "" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_STORAGE_STORE_SQL + +inherit + CMS_STORAGE + + CMS_STORAGE_SQL + +feature {NONE} -- Initialization + + make (a_connection: DATABASE_CONNECTION) + -- + require + is_connected: a_connection.is_connected + do + connection := a_connection + log.write_information (generator + ".make - is database connected? "+ a_connection.is_connected.out ) + + create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection) + + create error_handler.make +-- error_handler.add_synchronization (db_handler.database_error_handler) + end + +feature {NONE} -- Implementation + + db_handler: DATABASE_HANDLER + + connection: DATABASE_CONNECTION + -- Current database connection. + +feature -- Query + + sql_post_execution + -- Post database execution. + do + error_handler.append (db_handler.database_error_handler) + if error_handler.has_error then + log.write_critical (generator + ".post_execution " + error_handler.as_string_representation) + end + end + + sql_begin_transaction + do + connection.begin_transaction + end + + sql_rollback_transaction + do + connection.rollback + end + + sql_commit_transaction + do + connection.commit + end + + sql_query (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY]) + do + check_sql_query_validity (a_sql_statement, a_params) + db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params)) + db_handler.execute_query + end + + sql_change (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY]) + do + check_sql_query_validity (a_sql_statement, a_params) + db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params)) + db_handler.execute_change + end + + sql_rows_count: INTEGER + -- Number of rows for last sql execution. + do + Result := db_handler.count + end + + sql_start + -- Set the cursor on first element. + do + db_handler.start + end + + sql_after: BOOLEAN + -- Are there no more items to iterate over? + do + Result := db_handler.after + end + + sql_forth + -- Fetch next row from last sql execution, if any. + do + db_handler.forth + end + + sql_item (a_index: INTEGER): detachable ANY + do + if attached {DB_TUPLE} db_handler.item as l_item and then l_item.count >= a_index then + Result := l_item.item (a_index) + else + check has_item_at_index: False end + end + end + +end diff --git a/library/persistence/implementation/common/database/database_handler.e b/library/persistence/implementation/common/database/database_handler.e index 3517ff3..ee33311 100644 --- a/library/persistence/implementation/common/database/database_handler.e +++ b/library/persistence/implementation/common/database/database_handler.e @@ -1,7 +1,7 @@ note description: "Abstract Database Handler" - date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $" - revision: "$Revision: 95678 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" deferred class DATABASE_HANDLER @@ -45,14 +45,14 @@ feature -- Functionality Store Procedures execute_store_reader -- Execute a `store' to read data. require - store_not_void: store /= void + store_not_void: store /= Void deferred end execute_store_writer -- Execute a `store' to write data. require - store_not_void: store /= void + store_not_void: store /= Void deferred end @@ -61,14 +61,14 @@ feature -- SQL Queries execute_query -- Execute sql query, the read data from the database. require - query_not_void: query /= void + query_not_void: query /= Void deferred end execute_change -- Execute sql query that update/add data. require - query_not_void: query /= void + query_not_void: query /= Void deferred end @@ -153,22 +153,22 @@ feature -- Status Report end connection: DATABASE_CONNECTION - -- Database connection. + -- Database connection. db_control: DB_CONTROL - -- Database control. + -- Database control. do Result := connection.db_control end db_result: detachable DB_RESULT - -- Database query result. + -- Database query result. db_selection: detachable DB_SELECTION - -- Database selection. + -- Database selection. db_change: detachable DB_CHANGE - -- Database modification. + -- Database modification. feature -- Error handling diff --git a/library/persistence/implementation/common/database/database_query.e b/library/persistence/implementation/common/database/database_query.e index 25088b3..9c91238 100644 --- a/library/persistence/implementation/common/database/database_query.e +++ b/library/persistence/implementation/common/database/database_query.e @@ -1,13 +1,12 @@ note description: "Abstract Database Query" - date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $" - revision: "$Revision: 95678 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class DATABASE_QUERY inherit - REFACTORING_HELPER SHARED_LOGGER @@ -17,7 +16,7 @@ create feature {NONE} -- Intialization - data_reader (a_query: STRING; a_parameters: STRING_TABLE [detachable ANY]) + data_reader (a_query: STRING; a_parameters: like parameters) -- SQL data reader for the query `a_query' with arguments `a_parameters' do log.write_information (generator + ".data_reader" + " execute query: " + a_query) @@ -65,7 +64,7 @@ feature -- Access query: STRING -- SQL query to execute. - parameters: STRING_TABLE [detachable ANY] + parameters: detachable STRING_TABLE [detachable ANY] -- query parameters. feature {NONE} -- Implementation @@ -73,26 +72,24 @@ feature {NONE} -- Implementation set_map_name (a_base_selection: DB_EXPRESSION) -- Store parameters `item' and their `key'. do - from - parameters.start - until - parameters.after - loop - a_base_selection.set_map_name (parameters.item_for_iteration, parameters.key_for_iteration) - parameters.forth + if attached parameters as l_parameters then + across + l_parameters as ic + loop + a_base_selection.set_map_name (ic.item, ic.key) + end end end unset_map_name (a_base_selection: DB_EXPRESSION) -- Remove parameters item associated with key `key'. do - from - parameters.start - until - parameters.after - loop - a_base_selection.unset_map_name (parameters.key_for_iteration) - parameters.forth + if attached parameters as l_parameters then + across + l_parameters as ic + loop + a_base_selection.unset_map_name (ic.key) + end end end @@ -101,26 +98,25 @@ feature {NONE} -- Implementation -- exclude sensitive information. do create Result.make_empty - from - a_parameters.start - until - a_parameters.after - loop - Result.append ("name:") - Result.append (a_parameters.key_for_iteration.as_string_32) - Result.append (", value:") - if - a_parameters.key_for_iteration.has_substring ("Password") or else - a_parameters.key_for_iteration.has_substring ("password") - then - -- Data to exclude - else - if attached a_parameters.item_for_iteration as l_item then - Result.append (l_item.out) + if a_parameters /= Void then + across + a_parameters as ic + loop + Result.append ("name:") + Result.append (ic.key.as_string_32) + Result.append (", value:") + if + ic.key.has_substring ("Password") or else + ic.key.has_substring ("password") + then + -- Data to exclude + else + if attached ic.item as l_item then + Result.append (l_item.out) + end end + Result.append ("%N") end - Result.append ("%N") - a_parameters.forth end end diff --git a/library/persistence/implementation/common/database/database_sql_server_encoder.e b/library/persistence/implementation/common/database/database_sql_server_encoder.e index c576ef9..d33c057 100644 --- a/library/persistence/implementation/common/database/database_sql_server_encoder.e +++ b/library/persistence/implementation/common/database/database_sql_server_encoder.e @@ -1,8 +1,9 @@ note description: "Help to encode sql queries, to prevent sql injections." - date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $" - revision: "$Revision: 95678 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" EIS: "SQL server injection", "src=http://blogs.msdn.com/b/raulga/archive/2007/01/04/dynamic-sql-sql-injection.aspx", "protocol=url" + expanded class DATABASE_SQL_SERVER_ENCODER @@ -12,7 +13,7 @@ inherit feature -- Escape SQL input - encode (a_string:READABLE_STRING_32): READABLE_STRING_32 + encode (a_string: READABLE_STRING_32): READABLE_STRING_32 -- Escape single quote (') and braces ([,]). local l_string: STRING diff --git a/library/persistence/implementation/common/database/error/database_error.e b/library/persistence/implementation/common/database/error/database_error.e index 2dcd646..3f67be1 100644 --- a/library/persistence/implementation/common/database/error/database_error.e +++ b/library/persistence/implementation/common/database/error/database_error.e @@ -1,7 +1,7 @@ note description: "Error from database" - date: "$Date: 2013-08-08 16:39:49 -0300 (ju. 08 de ago. de 2013) $" - revision: "$Revision: 195 $" + date: "$Date: 2014-11-13 16:23:47 +0100 (jeu., 13 nov. 2014) $" + revision: "$Revision: 96085 $" class DATABASE_ERROR diff --git a/library/persistence/implementation/common/database/error/database_error_handler.e b/library/persistence/implementation/common/database/error/database_error_handler.e index 5af3545..ae49e6e 100644 --- a/library/persistence/implementation/common/database/error/database_error_handler.e +++ b/library/persistence/implementation/common/database/error/database_error_handler.e @@ -1,7 +1,7 @@ note description: "Database error handler" - date: "$Date: 2013-08-08 16:39:49 -0300 (ju. 08 de ago. de 2013) $" - revision: "$Revision: 195 $" + date: "$Date: 2014-11-13 16:23:47 +0100 (jeu., 13 nov. 2014) $" + revision: "$Revision: 96085 $" class DATABASE_ERROR_HANDLER diff --git a/library/persistence/implementation/common/database/error/database_no_change_error.e b/library/persistence/implementation/common/database/error/database_no_change_error.e index 6855279..4fcc211 100644 --- a/library/persistence/implementation/common/database/error/database_no_change_error.e +++ b/library/persistence/implementation/common/database/error/database_no_change_error.e @@ -1,8 +1,8 @@ note description: "Summary description for {DATABASE_NO_CHANGE_ERROR}." author: "" - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2014-11-13 16:23:47 +0100 (jeu., 13 nov. 2014) $" + revision: "$Revision: 96085 $" class DATABASE_NO_CHANGE_ERROR diff --git a/library/persistence/implementation/common/string_helper.e b/library/persistence/implementation/common/string_helper.e deleted file mode 100644 index f280e82..0000000 --- a/library/persistence/implementation/common/string_helper.e +++ /dev/null @@ -1,53 +0,0 @@ -note - description: "Summary description for {STRING_HELPER}." - date: "$Date: 2014-08-08 16:02:11 -0300 (vi., 08 ago. 2014) $" - revision: "$Revision: 95593 $" - -class - STRING_HELPER - -feature -- Access - - is_blank (s: detachable READABLE_STRING_32): BOOLEAN - local - i,n: INTEGER - do - Result := True - if s /= Void then - from - i := 1 - n := s.count - until - i > n or not Result - loop - Result := s[i].is_space - i := i + 1 - end - end - end - - indented_text (pre: READABLE_STRING_8; t: READABLE_STRING_8): READABLE_STRING_8 - -- Indendted text. - local - s8: STRING_8 - do - s8 := t.string - s8.prepend (pre) - s8.replace_substring_all ("%N", "%N" + pre) - Result := s8 - end - - - json_encode (a_string: STRING): STRING - -- json encode `a_string'. - local - encode: SHARED_JSON_ENCODER - do - create encode - Result := encode.json_encoder.encoded_string (a_string) - debug - print ("%NResult" + Result) - end - end - -end diff --git a/library/persistence/implementation/mysql/persistence_mysql-safe.ecf b/library/persistence/implementation/mysql/persistence_mysql-safe.ecf index 218e80c..c60339d 100644 --- a/library/persistence/implementation/mysql/persistence_mysql-safe.ecf +++ b/library/persistence/implementation/mysql/persistence_mysql-safe.ecf @@ -7,6 +7,7 @@ + @@ -23,7 +24,6 @@ /database/database_connection_odbc.e - /EIFGENs$ diff --git a/library/persistence/implementation/mysql/persistence_mysql.ecf b/library/persistence/implementation/mysql/persistence_mysql.ecf index ad05e10..99e8faf 100644 --- a/library/persistence/implementation/mysql/persistence_mysql.ecf +++ b/library/persistence/implementation/mysql/persistence_mysql.ecf @@ -7,6 +7,7 @@ + @@ -23,7 +24,6 @@ /database/database_connection_odbc.e - /EIFGENs$ diff --git a/library/persistence/implementation/mysql/src/cms_node_storage_mysql.e b/library/persistence/implementation/mysql/src/cms_node_storage_mysql.e new file mode 100644 index 0000000..b125f0d --- /dev/null +++ b/library/persistence/implementation/mysql/src/cms_node_storage_mysql.e @@ -0,0 +1,75 @@ +note + description: "Summary description for {CMS_NODE_STORAGE_MYSQL}." + author: "" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_NODE_STORAGE_MYSQL + +inherit + CMS_NODE_STORAGE_SQL + redefine + nodes, recent_nodes + end + +feature {NONE} -- Implementation + + db_handler: DATABASE_HANDLER + deferred + end + +feature -- Access + + nodes: LIST [CMS_NODE] + -- List of nodes. + do + create {ARRAYED_LIST [CMS_NODE]} Result.make (0) + across nodes_iterator as ic loop + Result.force (ic.item) + end + end + + recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE] + -- List of recent `a_count' nodes with an offset of `lower'. + do + create {ARRAYED_LIST [CMS_NODE]} Result.make (a_count) + across recent_nodes_iterator (a_lower, a_count) as c loop + Result.force (c.item) + end + end + +feature -- Access: iterator + + nodes_iterator: DATABASE_ITERATION_CURSOR [CMS_NODE] + -- List of nodes. + local + l_parameters: STRING_TABLE [ANY] + do + error_handler.reset + log.write_information (generator + ".nodes_iterator") + create l_parameters.make (0) + sql_query (select_nodes, l_parameters) + create Result.make (db_handler, agent fetch_node) + sql_post_execution + end + + recent_nodes_iterator (a_lower, a_rows: INTEGER): DATABASE_ITERATION_CURSOR [CMS_NODE] + -- The most recent `a_rows'. + local + l_parameters: STRING_TABLE [ANY] + l_query: STRING + do + -- FIXME: check implementation... + error_handler.reset + log.write_information (generator + ".recent_nodes_iterator") + create l_parameters.make (2) + l_parameters.put (a_rows, "rows") + l_parameters.put (a_lower, "offset") + create l_query.make_from_string (select_recent_nodes) + sql_query (l_query, l_parameters) + create Result.make (db_handler, agent fetch_node) + sql_post_execution + end + +end diff --git a/library/persistence/implementation/mysql/src/cms_storage_mysql.e b/library/persistence/implementation/mysql/src/cms_storage_mysql.e index cc81d6c..7fdfd7f 100644 --- a/library/persistence/implementation/mysql/src/cms_storage_mysql.e +++ b/library/persistence/implementation/mysql/src/cms_storage_mysql.e @@ -1,270 +1,112 @@ note description: "Summary description for {CMS_STORAGE_MYSQL}." - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class CMS_STORAGE_MYSQL inherit - CMS_STORAGE + + CMS_STORAGE_STORE_SQL + + CMS_USER_STORAGE_MYSQL + + CMS_NODE_STORAGE_MYSQL + REFACTORING_HELPER create make -feature {NONE} -- Initialization +--feature {NONE} -- Initialization - make (a_connection: DATABASE_CONNECTION) - -- - require - is_connected: a_connection.is_connected - do - connection := a_connection - log.write_information (generator+".make_with_database is database connected? "+ a_connection.is_connected.out ) - create node_provider.make (a_connection) - create user_provider.make (a_connection) - create error_handler.make - end +-- make (a_connection: DATABASE_CONNECTION) +-- -- +-- require +-- is_connected: a_connection.is_connected +-- do +-- connection := a_connection +-- log.write_information (generator + ".make - is database connected? "+ a_connection.is_connected.out ) +-- create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection) -feature -- Access: user +-- create error_handler.make +---- error_handler.add_synchronization (db_handler.database_error_handler) +-- end - has_user: BOOLEAN - -- Has any user? - do - Result := user_provider.has_user - end +-- db_handler: DATABASE_HANDLER - all_users: LIST [CMS_USER] - do - to_implement (generator + ".all_users") - create {ARRAYED_LIST[CMS_USER]} Result.make (0) - end +-- connection: DATABASE_CONNECTION +-- -- Current database connection. - user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER - do - Result := user_provider.user (a_id) +--feature -- Query - end +-- sql_post_execution +-- -- Post database execution. +-- do +-- error_handler.append (db_handler.database_error_handler) +-- if error_handler.has_error then +-- log.write_critical (generator + ".post_execution " + error_handler.as_string_representation) +-- end +-- end - user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER - do - Result := user_provider.user_by_name (a_name) +-- sql_begin_transaction +-- do +-- connection.begin_transaction +-- end - end +-- sql_commit_transaction +-- do +-- connection.commit +-- end - user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER - do - Result := user_provider.user_by_email (a_email) +-- sql_query (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY]) +-- do +-- check_sql_query_validity (a_sql_statement, a_params) +-- db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params)) +-- db_handler.execute_query +-- end - end +-- sql_change (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY]) +-- do +-- check_sql_query_validity (a_sql_statement, a_params) +-- db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params)) +-- db_handler.execute_change +-- end - is_valid_credential (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN - local - l_security: SECURITY_PROVIDER - do - if attached user_provider.user_salt (l_auth_login) as l_hash then - 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 +-- sql_rows_count: INTEGER +-- -- Number of rows for last sql execution. +-- do +-- Result := db_handler.count +-- end - end +-- sql_start +-- -- Set the cursor on first element. +-- do +-- db_handler.start +-- end -feature -- User Nodes +-- sql_after: BOOLEAN +-- -- Are there no more items to iterate over? +-- do +-- Result := db_handler.after +-- end - user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE] - -- Possible list of nodes where the user identified by `a_id', is a collaborator. - do - to_implement (generator + ".user_collaborator_nodes") - create {ARRAYED_LIST[CMS_NODE]} Result.make (0) - end +-- sql_forth +-- -- Fetch next row from last sql execution, if any. +-- do +-- db_handler.forth +-- end - user_author_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE] - -- Possible list of nodes where the user identified by `a_id', is the author. - do - to_implement (generator + ".user_author_nodes") - create {ARRAYED_LIST[CMS_NODE]} Result.make (0) - end +-- sql_item (a_index: INTEGER): detachable ANY +-- do +-- if attached {DB_TUPLE} db_handler.item as l_item and then l_item.count >= a_index then +-- Result := l_item.item (a_index) +-- else +-- check has_item_at_index: False end +-- end +-- end -feature -- Access: roles and permissions - - user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE - do - to_implement (generator + ".user_role_by_id") - end - - user_roles: LIST [CMS_USER_ROLE] - do - to_implement (generator + ".user_roles") - create {ARRAYED_LIST[CMS_USER_ROLE]} Result.make (0) - end - -feature -- Change: roles and permissions - - save_user_role (a_user_role: CMS_USER_ROLE) - do - to_implement (generator + ".save_user_role") - end - -feature -- Change: user - - save_user (a_user: CMS_USER) - -- Add a new user `a_user'. - do - - if - attached a_user.password as l_password and then - attached a_user.email as l_email - then - connection.begin_transaction - user_provider.new_user (a_user.name, l_password, l_email) - connection.commit - else - debug ("refactor_fixme") - fixme ("maybe we should not always carry password, in this case, to implement the else part..") - end - end - end - -feature -- Access: node - - nodes: LIST[CMS_NODE] - -- List of nodes. - do - create {ARRAYED_LIST[CMS_NODE]} Result.make (0) - across node_provider.nodes as c loop - Result.force (c.item) - end - - 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) - across node_provider.recent_nodes (a_lower,a_count) as c loop - Result.force (c.item) - end - - end - - node (a_id: INTEGER_64): detachable CMS_NODE - -- - do - Result := node_provider.node (a_id) - - end - - node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER - -- - do - Result := node_provider.node_author (a_id) - - end - - node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER] - -- Possible list of node's collaborator. - do - create {ARRAYED_LIST[CMS_USER]} Result.make (0) - across node_provider.node_collaborators (a_id) as c loop Result.force (c.item) end - end - -feature -- Node - - save_node (a_node: CMS_NODE) - -- - do - node_provider.new_node (a_node) - - end - - delete_node (a_id: INTEGER_64) - do - node_provider.delete_from_user_nodes(a_id) - node_provider.delete_node (a_id) - - end - - update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE) - -- - do - node_provider.update_node (a_id, a_node) - - end - - update_node_title (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32) - -- - do - node_provider.update_node_title (a_node_id, a_title) - internal_node_update (a_id, a_node_id) - - end - - update_node_summary (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32) - -- - do - node_provider.update_node_summary (a_node_id, a_summary) - internal_node_update (a_id, a_node_id) - - end - - update_node_content (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32) - -- - do - node_provider.update_node_content (a_node_id, a_content) - internal_node_update (a_id, a_node_id) - - end - -feature {NONE} -- NODE Implemenation - - internal_node_update (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id) - -- Update node editor or add collaborator. - do - if not node_provider.is_collaborator (a_id, a_node_id) then - node_provider.add_collaborator (a_id, a_node_id) - else - node_provider.update_node_last_editor (a_id, a_node_id) - end - end - -feature -- User - - new_user (a_user: CMS_USER) - -- Add a new user `a_user'. - do - if - attached a_user.password as l_password and then - attached a_user.email as l_email - then - user_provider.new_user (a_user.name, l_password, l_email) - else - -- set error - end - end - -feature {NONE} -- Post process - - - node_provider: NODE_DATA_PROVIDER - -- Node Data provider. - - user_provider: USER_DATA_PROVIDER - -- User Data provider. - - connection: DATABASE_CONNECTION - -- Current database connection. end diff --git a/library/persistence/implementation/mysql/src/cms_storage_mysql_builder.e b/library/persistence/implementation/mysql/src/cms_storage_mysql_builder.e new file mode 100644 index 0000000..585fc81 --- /dev/null +++ b/library/persistence/implementation/mysql/src/cms_storage_mysql_builder.e @@ -0,0 +1,40 @@ +note + description: "[ + Objects that ... + ]" + author: "$Author: jfiat $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +class + CMS_STORAGE_MYSQL_BUILDER + +inherit + CMS_STORAGE_BUILDER + +create + make + +feature {NONE} -- Initialization + + make + -- Initialize `Current'. + do + end + +feature -- Factory + + storage (a_setup: CMS_SETUP): detachable CMS_STORAGE_MYSQL + local + conn: DATABASE_CONNECTION + do + if attached (create {APPLICATION_JSON_CONFIGURATION_HELPER}).new_database_configuration (a_setup.layout.application_config_path) as l_database_config then + create {DATABASE_CONNECTION_MYSQL} conn.login_with_connection_string (l_database_config.connection_string) + if conn.is_connected then + create Result.make (conn) + end + end + end + + +end diff --git a/library/persistence/implementation/mysql/src/cms_user_storage_mysql.e b/library/persistence/implementation/mysql/src/cms_user_storage_mysql.e new file mode 100644 index 0000000..9f8bfc2 --- /dev/null +++ b/library/persistence/implementation/mysql/src/cms_user_storage_mysql.e @@ -0,0 +1,14 @@ +note + description: "Summary description for {CMS_USER_STORAGE_MYSQL}." + author: "" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_USER_STORAGE_MYSQL + +inherit + CMS_USER_STORAGE_SQL + + +end diff --git a/library/persistence/implementation/mysql/src/provider/node_data_provider.e b/library/persistence/implementation/mysql/src/provider/node_data_provider.e deleted file mode 100644 index 5951cc5..0000000 --- a/library/persistence/implementation/mysql/src/provider/node_data_provider.e +++ /dev/null @@ -1,511 +0,0 @@ -note - description: "Database access for node uses cases." - date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $" - revision: "$Revision: 95678 $" - -class - NODE_DATA_PROVIDER - -inherit - - PARAMETER_NAME_HELPER - - REFACTORING_HELPER - - SHARED_LOGGER - -create - make - -feature -- Initialization - - make (a_connection: DATABASE_CONNECTION) - -- Create a data provider. - do - create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection) - create error_handler.make - post_execution - end - - db_handler: DATABASE_HANDLER - -- Db handler. - -feature -- Status Report - - is_successful: BOOLEAN - -- Is the last execution sucessful? - do - Result := not error_handler.has_error - end - -feature -- Error Handler - - error_handler: ERROR_HANDLER - -feature -- Access - - nodes: DATABASE_ITERATION_CURSOR [CMS_NODE] - -- List of nodes. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".nodes") - create l_parameters.make (0) - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_nodes, l_parameters)) - db_handler.execute_query - create Result.make (db_handler, agent fetch_node) - post_execution - end - - recent_nodes (a_lower, a_rows: INTEGER): DATABASE_ITERATION_CURSOR [CMS_NODE] - -- The most recent `a_rows'. - local - l_parameters: STRING_TABLE [ANY] - l_query: STRING - do - error_handler.reset - log.write_information (generator + ".recent_nodes") - create l_parameters.make (2) - l_parameters.put (a_rows, "rows") - create l_query.make_from_string (select_recent_nodes) - l_query.replace_substring_all ("$offset", a_lower.out) - db_handler.set_query (create {DATABASE_QUERY}.data_reader (l_query, l_parameters)) - db_handler.execute_query - create Result.make (db_handler, agent fetch_node) - post_execution - end - - node (a_id: INTEGER_64): detachable CMS_NODE - -- Node for the given id `a_id', if any. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".node") - create l_parameters.make (1) - l_parameters.put (a_id,"id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_node_by_id, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := fetch_node - end - post_execution - end - - count: INTEGER - -- Number of items nodes. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".count") - create l_parameters.make (0) - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_count, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := db_handler.read_integer_32 (1) - end - post_execution - end - - - last_inserted_node_id: INTEGER - -- Last insert node id. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".last_inserted_node_id") - create l_parameters.make (0) - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Sql_last_insert_node_id, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := db_handler.read_integer_32 (1) - end - post_execution - end - -feature -- Basic operations - - new_node (a_node: CMS_NODE) - -- Create a new node. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".new_node") - create l_parameters.make (7) - l_parameters.put (a_node.title, "title") - l_parameters.put (a_node.summary, "summary") - l_parameters.put (a_node.content, "content") - l_parameters.put (a_node.publication_date, "publication_date") - l_parameters.put (a_node.creation_date, "creation_date") - l_parameters.put (a_node.modification_date, "modification_date") - if - attached a_node.author as l_author and then - l_author.id > 0 - then - l_parameters.put (l_author.id, "author_id") - end - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_insert_node, l_parameters)) - db_handler.execute_change - - a_node.set_id (last_inserted_node_id) - post_execution - end - - update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32) - -- Update node title for the corresponding the report with id `a_id'. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".update_node_title") - create l_parameters.make (3) - l_parameters.put (a_title, "title") - l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date") - l_parameters.put (a_id, "id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node_title, l_parameters)) - db_handler.execute_change - post_execution - end - - update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32) - -- Update node summary for the corresponding the report with id `a_id'. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".update_node_summary") - create l_parameters.make (3) - l_parameters.put (a_summary, "summary") - l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date") - l_parameters.put (a_id, "id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node_summary, l_parameters)) - db_handler.execute_change - post_execution - end - - update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32) - -- Update node content for the corresponding the report with id `a_id'. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".update_node_content") - create l_parameters.make (3) - l_parameters.put (a_content, "content") - l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date") - l_parameters.put (a_id, "id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node_content, l_parameters)) - db_handler.execute_change - post_execution - end - - update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE) - -- Update node. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".update_node") - create l_parameters.make (7) - l_parameters.put (a_node.title, "title") - l_parameters.put (a_node.summary, "summary") - l_parameters.put (a_node.content, "content") - l_parameters.put (a_node.publication_date, "publication_date") - l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date") - l_parameters.put (a_node.id, "id") - l_parameters.put (a_id, "editor") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node, l_parameters)) - db_handler.execute_change - post_execution - end - - delete_node (a_id: INTEGER_64;) - -- Delete node with id `a_id'. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".delete_node") - create l_parameters.make (1) - l_parameters.put (a_id, "id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_delete_node, l_parameters)) - db_handler.execute_change - post_execution - end - - delete_from_user_nodes (a_id: INTEGER_64) - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".delete_from_user_nodes") - create l_parameters.make (1) - l_parameters.put (a_id, "id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_delete_from_user_node, l_parameters)) - db_handler.execute_change - post_execution - end - -feature -- Basic Operations: User_Nodes - - add_author (a_user_id: INTEGER_64; a_node_id: INTEGER_64) - -- Add author `a_user_id' to node `a_node_id' - local - l_parameters: STRING_TABLE [detachable ANY] - do - error_handler.reset - log.write_information (generator + ".add_author") - create l_parameters.make (2) - l_parameters.put (a_user_id,"user_id") - l_parameters.put (a_node_id,"id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Sql_update_node_author, l_parameters)) - db_handler.execute_change - post_execution - end - - add_collaborator (a_user_id: INTEGER_64; a_node_id: INTEGER_64) - -- Add collaborator `a_user_id' to node `a_node_id' - local - l_parameters: STRING_TABLE [detachable ANY] - do - error_handler.reset - log.write_information (generator + ".add_collaborator") - create l_parameters.make (2) - l_parameters.put (a_user_id,"users_id") - l_parameters.put (a_node_id,"nodes_id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Sql_insert_users_nodes, l_parameters)) - db_handler.execute_change - post_execution - end - - update_node_last_editor (a_user_id: INTEGER_64; a_node_id: INTEGER_64) - -- Update node last editor. - local - l_parameters: STRING_TABLE [detachable ANY] - do - error_handler.reset - log.write_information (generator + ".add_collaborator") - create l_parameters.make (2) - l_parameters.put (a_user_id,"users_id") - l_parameters.put (a_node_id,"nodes_id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Slq_update_editor, l_parameters)) - db_handler.execute_change - post_execution - end - - - author_nodes (a_id:INTEGER_64): DATABASE_ITERATION_CURSOR [CMS_NODE] - -- List of Nodes for the given user `a_id'. (the user is the author of the node) - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".author_nodes") - create l_parameters.make (1) - l_parameters.put (a_id, "user_id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_user_author, l_parameters)) - db_handler.execute_query - create Result.make (db_handler, agent fetch_node) - post_execution - end - - collaborator_nodes (a_id:INTEGER_64): DATABASE_ITERATION_CURSOR [CMS_NODE] - -- List of Nodes for the given user `a_id' as collaborator. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".collaborator_nodes") - create l_parameters.make (1) - l_parameters.put (a_id, "user_id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_user_collaborator, l_parameters)) - db_handler.execute_query - create Result.make (db_handler, agent fetch_node) - post_execution - end - - - node_author (a_id: INTEGER_64): detachable CMS_USER - -- Node's author for the given node id. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".node_author") - create l_parameters.make (1) - l_parameters.put (a_id, "node_id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_node_author, l_parameters)) - db_handler.execute_query - if not db_handler.after then - Result := fetch_user - end - post_execution - end - - node_collaborators (a_id: INTEGER_64): DATABASE_ITERATION_CURSOR [CMS_USER] - -- List of possible node's collaborator. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".node_collaborators") - create l_parameters.make (1) - l_parameters.put (a_id, "node_id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_node_collaborators, l_parameters)) - db_handler.execute_query - create Result.make (db_handler, agent fetch_user) - post_execution - end - - is_collaborator (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id): BOOLEAN - -- Is the user `a_user_id' a collaborator of node `a_node_id' - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".node_collaborators") - create l_parameters.make (2) - l_parameters.put (a_user_id, "user_id") - l_parameters.put (a_node_id, "node_id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_exist_user_node, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := db_handler.read_integer_32 (1) = 1 - end - post_execution - end - -feature -- Connection - - connect - -- Connect to the database. - do - if not db_handler.is_connected then - db_handler.connect - end - end - - disconnect - -- Disconnect to the database. - do - if db_handler.is_connected then - db_handler.disconnect - end - end - -feature {NONE} -- Queries - - Select_count: STRING = "select count(*) from Nodes;" - - Select_nodes: STRING = "select * from Nodes;" - -- SQL Query to retrieve all nodes. - - Select_node_by_id: STRING = "select * from Nodes where id =:id order by id desc, publication_date desc;" - - Select_recent_nodes: STRING = "select * from Nodes order by id desc, publication_date desc Limit $offset , :rows " - - SQL_Insert_node: STRING = "insert into nodes (title, summary, content, publication_date, creation_date, modification_date, author_id) values (:title, :summary, :content, :publication_date, :creation_date, :modification_date, :author_id);" - -- SQL Insert to add a new node. - - SQL_Update_node_title: STRING ="update nodes SET title=:title, modification_date=:modification_date, version = version + 1 where id=:id;" - -- SQL update node title. - - SQL_Update_node_summary: STRING ="update nodes SET summary=:summary, modification_date=:modification_date, version = version + 1 where id=:id;" - -- SQL update node summary. - - SQL_Update_node_content: STRING ="update nodes SET content=:content, modification_date=:modification_date, version = version + 1 where id=:id;" - -- SQL node content. - - Slq_update_editor: STRING ="update nodes SET editor_id=:users_id where id=:nodes_id;" - -- SQL node content. - - SQL_Update_node : STRING = "update nodes SET title=:title, summary=:summary, content=:content, publication_date=:publication_date, modification_date=:modification_date, version = version + 1, editor_id=:editor where id=:id;" - -- SQL node. - - SQL_Delete_node: STRING = "delete from nodes where id=:id;" - - Sql_update_node_author: STRING = "update nodes SET author_id=:user_id where id=:id;" - - Sql_last_insert_node_id: STRING = "SELECT MAX(id) from nodes;" - -feature {NONE} -- Sql Queries: USER_ROLES collaborators, author - - Sql_insert_users_nodes: STRING = "insert into users_nodes (users_id, nodes_id) values (:users_id, :nodes_id);" - - select_node_collaborators: STRING = "SELECT * FROM Users INNER JOIN users_nodes ON users.id=users_nodes.users_id and users_nodes.nodes_id = :node_id;" - - Select_user_author: STRING = "SELECT * FROM Nodes INNER JOIN users ON nodes.author_id=users.id and users.id = :user_id;" - - Select_node_author: STRING = "SELECT * FROM Users INNER JOIN nodes ON nodes.author_id=users.id and nodes.id =:node_id;" - - Select_user_collaborator: STRING = "SELECT * FROM Nodes INNER JOIN users_nodes ON users_nodes.nodes_id = nodes.id and users_nodes.users_id = :user_id;" - - Select_exist_user_node: STRING= "Select Count(*) from Users_nodes where users_id=:user_id and nodes_id=:node_id;" - - sql_delete_from_user_node: STRING = "delete from users_nodes where nodes_id=:id" - - -feature -- - - -feature -- New Object - - fetch_node: CMS_NODE - do - create Result.make ("", "", "") - if attached db_handler.read_integer_32 (1) as l_id then - Result.set_id (l_id) - end - if attached db_handler.read_date_time (2) as l_pd then - Result.set_publication_date (l_pd) - end - if attached db_handler.read_date_time (3) as l_cd then - Result.set_creation_date (l_cd) - end - if attached db_handler.read_date_time (4) as l_md then - Result.set_modification_date (l_md) - end - if attached db_handler.read_string (5) as l_t then - Result.set_title (l_t) - end - if attached db_handler.read_string (6) as l_s then - Result.set_summary (l_s) - end - if attached db_handler.read_string (7) as l_c then - Result.set_content (l_c) - end - end - - fetch_user: CMS_USER - do - create Result.make ("") - if attached db_handler.read_integer_32 (1) as l_id then - Result.set_id (l_id) - end - if attached db_handler.read_string (2) as l_u then - Result.set_name (l_u) - end - if attached db_handler.read_string (3) as l_p then - Result.set_password (l_p) - end - if attached db_handler.read_string (5) as l_e then - Result.set_email (l_e) - end - end - -feature {NONE} -- Implementation - - post_execution - -- Post database execution. - do - error_handler.add_synchronization (db_handler.database_error_handler) - if error_handler.has_error then - log.write_critical (generator + ".post_execution " + error_handler.as_string_representation) - end - end - -end diff --git a/library/persistence/implementation/mysql/src/provider/role_data_provider.e b/library/persistence/implementation/mysql/src/provider/role_data_provider.e deleted file mode 100644 index 8e82a64..0000000 --- a/library/persistence/implementation/mysql/src/provider/role_data_provider.e +++ /dev/null @@ -1,216 +0,0 @@ -note - description: "Summary description for {ROLE_DATA_PROVIDER}." - author: "" - date: "$Date$" - revision: "$Revision$" - -class - ROLE_DATA_PROVIDER - -inherit - - PARAMETER_NAME_HELPER - - SHARED_ERROR - - REFACTORING_HELPER - -create - make - -feature -- Initialization - - make (a_connection: DATABASE_CONNECTION) - -- Create a data provider. - do - create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection) - post_execution - end - - db_handler: DATABASE_HANDLER - -- Db handler. - -feature -- Status Report - - is_successful: BOOLEAN - -- Is the last execution sucessful? - do --- Result := db_handler.successful - end - - has_roles: BOOLEAN - -- Has any role? - do - Result := count > 0 - end - -feature -- Access - - roles: DATABASE_ITERATION_CURSOR [CMS_USER_ROLE] - -- List of roles. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".roles") - create l_parameters.make (0) - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_roles, l_parameters)) - db_handler.execute_query - create Result.make (db_handler, agent fetch_role) - post_execution - end - -feature -- Basic Operations - - new_role (a_role: READABLE_STRING_32) - -- Create a new node. - local - l_parameters: STRING_TABLE [detachable ANY] - do - log.write_information (generator + ".new_role") - create l_parameters.make (1) - l_parameters.put (a_role,"name") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_insert_role, l_parameters)) - db_handler.execute_change - post_execution - end - - role (a_id: INTEGER_64): detachable CMS_USER_ROLE - -- Role for the given id `a_id', if any. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".role") - create l_parameters.make (1) - l_parameters.put (a_id,"id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_role_by_id, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := fetch_role - end - post_execution - end - - role_by_name (a_name: READABLE_STRING_32): detachable CMS_USER_ROLE - -- Role for the given name `a_name', if any. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".role_by_name") - create l_parameters.make (1) - l_parameters.put (a_name,"name") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_role_by_name, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := fetch_role - end - post_execution - end - - count: INTEGER - -- Number of items users. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".count") - create l_parameters.make (0) - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_count, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := db_handler.read_integer_32 (1) - end - post_execution - end - - save_role_permission (a_role_id: INTEGER; a_permission: READABLE_STRING_32) - -- Add permission `a_permission' to the role id `a_role_id'. - require - valid_id: a_role_id > 0 - local - l_parameters: STRING_TABLE [detachable ANY] - do - log.write_information (generator + ".save_role_permission") - create l_parameters.make (1) - l_parameters.put (a_permission,"name") - l_parameters.put (a_role_id,"id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (SQL_Insert_permissions, l_parameters)) - db_handler.execute_change - post_execution - end - - permission_by_role (a_role_id: INTEGER_64): DATABASE_ITERATION_CURSOR [READABLE_STRING_32] - -- List of permission by role `a_role_id'. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".permission_by_role") - create l_parameters.make (1) - l_parameters.put (a_role_id, "id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_permissions, l_parameters)) - db_handler.execute_query - create Result.make (db_handler, agent fetch_permission) - post_execution - end - -feature -- New Object - - fetch_role: CMS_USER_ROLE - do - create Result.make_with_id (0,"") - if attached db_handler.read_integer_32 (1) as l_id then - Result.set_id (l_id) - end - if attached db_handler.read_string (2) as l_u then - Result.set_name (l_u) - end - end - - fetch_permission: STRING_32 - do - create Result.make_empty - if attached db_handler.read_string (1) as l_u then - Result := l_u - end - end - - -feature {NONE} -- Sql Queries: Roles - - Select_count: STRING = "select count(*) from Roles;" - -- Number of roles. - - Select_roles: STRING = "select * from Roles;" - -- roles. - - Select_role_by_id: STRING = "select * from Roles where id =:id;" - -- Retrieve role by id if exists. - - Select_role_by_name: STRING = "select * from Roles where role =:name;" - -- Retrieve user by name if exists. - - SQL_Insert_role: STRING = "insert into roles (role) values (:name);" - -- SQL Insert to add a new node. - - -feature {NONE} -- Sql Queries: Permissions - - Select_permissions_count: STRING = "select count(*) from permissions where roles_id=:id;" - -- Number of permissions for a given role. - - Select_permissions: STRING = "select * from permissions where roles_id=:id;" - -- List of permissions for a given role. - - Select_permissions_by_id: STRING = "select name from permissions where roles_id=:id and id=:permissionid;" - -- Permission for a given role and permission id - - SQL_Insert_permissions: STRING = "insert into permissions (name, roles_id) values (:name, :id);" - -- SQL Insert to add a new node. - -feature {NONE} -- Implementation - - post_execution - -- Post database execution. - do - - end - -end diff --git a/library/persistence/implementation/mysql/src/provider/user_data_provider.e b/library/persistence/implementation/mysql/src/provider/user_data_provider.e deleted file mode 100644 index 488d39a..0000000 --- a/library/persistence/implementation/mysql/src/provider/user_data_provider.e +++ /dev/null @@ -1,337 +0,0 @@ -note - description: "Summary description for {USER_DATA_PROVIDER}." - date: "$Date$" - revision: "$Revision$" - -class - USER_DATA_PROVIDER - -inherit - - PARAMETER_NAME_HELPER - - REFACTORING_HELPER - - SHARED_LOGGER - -create - make - -feature -- Initialization - - make (a_connection: DATABASE_CONNECTION) - -- Create a data provider. - do - create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection) - create error_handler.make - post_execution - end - - db_handler: DATABASE_HANDLER - -- Db handler. - -feature -- Error Handler - - error_handler: ERROR_HANDLER - - -feature -- Status Report - - is_successful: BOOLEAN - -- Is the last execution sucessful? - do - Result := not error_handler.has_error - end - - has_user: BOOLEAN - -- Has any user? - do - Result := count > 0 - end - -feature -- Basic Operations - - new_user (a_user_name: READABLE_STRING_32; a_password: READABLE_STRING_32; a_email: READABLE_STRING_32) - -- Create a new node. - local - l_parameters: STRING_TABLE [detachable ANY] - l_password_salt, l_password_hash: STRING - l_security: SECURITY_PROVIDER - do - error_handler.reset - create l_security - l_password_salt := l_security.salt - l_password_hash := l_security.password_hash (a_password, l_password_salt) - - log.write_information (generator + ".new_user") - create l_parameters.make (4) - l_parameters.put (a_user_name,"username") - l_parameters.put (l_password_hash,"password") - l_parameters.put (l_password_salt,"salt") - l_parameters.put (a_email,"email") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_insert_user, l_parameters)) - db_handler.execute_change - post_execution - end - - user (a_id: INTEGER_64): detachable CMS_USER - -- User for the given id `a_id', if any. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".user") - create l_parameters.make (1) - l_parameters.put (a_id,"id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_user_by_id, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := fetch_user - end - post_execution - end - - user_by_name (a_name: READABLE_STRING_32): detachable CMS_USER - -- User for the given name `a_name', if any. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".user_by_name") - create l_parameters.make (1) - l_parameters.put (a_name,"name") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_user_by_name, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := fetch_user - end - post_execution - end - - - user_by_email (a_email: detachable READABLE_STRING_32): detachable CMS_USER - -- User for the given email `a_email', if any. - local - l_parameters: STRING_TABLE [detachable ANY] - do - error_handler.reset - log.write_information (generator + ".user_by_email") - create l_parameters.make (1) - l_parameters.put (a_email,"email") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_user_by_email, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := fetch_user - end - post_execution - end - - user_salt (a_username: READABLE_STRING_32): detachable READABLE_STRING_32 - -- User salt for the given user `a_username', if any. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".user_salt") - create l_parameters.make (1) - l_parameters.put (a_username,"name") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_salt_by_username, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - if attached db_handler.read_string (1) as l_salt then - Result := l_salt.as_string_32 - end - end - post_execution - end - - count: INTEGER - -- Number of items users. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".count") - create l_parameters.make (0) - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_count, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := db_handler.read_integer_32 (1) - end - post_execution - end - -feature -- Basic operations: User Roles - - add_role (a_user_id: INTEGER; a_role_id: INTEGER) - -- Add Role `a_role_id' to user `a_user_id' - local - l_parameters: STRING_TABLE [detachable ANY] - do - error_handler.reset - log.write_information (generator + ".add_role") - create l_parameters.make (2) - l_parameters.put (a_user_id,"users_id") - l_parameters.put (a_role_id,"roles_id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (slq_insert_users_roles, l_parameters)) - db_handler.execute_change - post_execution - end - - user_roles (a_id:INTEGER_64): DATABASE_ITERATION_CURSOR [INTEGER] - -- List of Roles id for the given user `a_id'. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".user_roles") - create l_parameters.make (1) - l_parameters.put (a_id, "user_id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_user_roles, l_parameters)) - db_handler.execute_query - create Result.make (db_handler, agent fetch_role_id) - post_execution - end - - -feature -- Basic operations: User Profiles - - save_profile_item (a_user_id: INTEGER_64; a_key: READABLE_STRING_32; a_value: READABLE_STRING_32) - -- Save a profile item with (a_key and a_value) to the given user `user_id'. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".save_profile_item") - create l_parameters.make (3) - l_parameters.put (a_key, "key") - l_parameters.put (a_value, "value") - l_parameters.put (a_user_id, "users_id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_instert_profile_item, l_parameters)) - db_handler.execute_change - post_execution - end - - save_profile (a_user_id: INTEGER_64; a_user_profile: CMS_USER_PROFILE) - -- Save a profile item with (a_key and a_value) to the given user `user_id'. - local - l_cursor: TABLE_ITERATION_CURSOR [READABLE_STRING_8, READABLE_STRING_GENERAL] - do - error_handler.reset - log.write_information (generator + ".save_profile") - from - l_cursor := a_user_profile.new_cursor - until - l_cursor.after - loop - save_profile_item (a_user_id, l_cursor.key.as_string_32, l_cursor.item) - l_cursor.forth - end - - post_execution - end - - user_profile (a_user_id: INTEGER_64): CMS_USER_PROFILE - -- User profile for a user with id `a_user_id'. - local - l_parameters: STRING_TABLE [ANY] - do - error_handler.reset - log.write_information (generator + ".user_profile") - create l_parameters.make (1) - l_parameters.put (a_user_id, "users_id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_user_profile, l_parameters)) - db_handler.execute_query - create Result.make - if not db_handler.after then - from - db_handler.start - until - db_handler.after - loop - if - attached db_handler.read_string (1) as l_key and then - attached db_handler.read_string (2) as l_value - then - Result.force (l_value, l_key) - end - db_handler.forth - end - end - post_execution - end - - -feature -- New Object - - fetch_user: CMS_USER - do - create Result.make ("") - if attached db_handler.read_integer_32 (1) as l_id then - Result.set_id (l_id) - end - if attached db_handler.read_string (2) as l_u then - Result.set_name (l_u) - end - if attached db_handler.read_string (3) as l_p then - Result.set_password (l_p) - end - if attached db_handler.read_string (5) as l_e then - Result.set_email (l_e) - end - end - - fetch_role_id: INTEGER - do - if attached db_handler.read_integer_32 (1) as l_id then - Result := l_id - end - end - -feature {NONE} -- Sql Queries: USER - - Select_count: STRING = "select count(*) from Users;" - -- Number of users. - - Select_user_by_id: STRING = "select * from Users where id =:id;" - -- Retrieve user by id if exists. - - Select_user_by_name: STRING = "select * from Users where username =:name;" - -- Retrieve user by name if exists. - - Select_user_by_email: STRING = "select * from Users where email =:email;" - -- Retrieve user by email if exists. - - Select_salt_by_username: STRING = "select salt from Users where username =:name;" - -- Retrieve salt by username if exists. - - SQL_Insert_user: STRING = "insert into users (username, password, salt, email) values (:username, :password, :salt, :email);" - -- SQL Insert to add a new node. - - -feature {NONE} -- Sql Queries: USER_ROLES - - Slq_insert_users_roles: STRING = "insert into users_roles (users_id, roles_id) values (:users_id, :roles_id);" - - Select_user_roles: STRING = "Select roles_id from users_roles where users_id = :user_id" - -feature {NONE} -- SQL Queries: Profile - - Select_instert_profile_item: STRING = "insert into profiles (profiles.key, value, users_id) values (:key, :value, :users_id);" - - Select_user_profile: STRING = "Select profiles.key, value from profiles where users_id = :users_id;" - - - -feature {NONE} -- Implementation - - post_execution - -- Post database execution. - do - error_handler.add_synchronization (db_handler.database_error_handler) - if error_handler.has_error then - log.write_critical (generator + ".post_execution " + error_handler.as_string_representation) - end - end - -end diff --git a/library/persistence/implementation/mysql/tests/application.e b/library/persistence/implementation/mysql/tests/application.e index 72cfa2c..14d7be1 100644 --- a/library/persistence/implementation/mysql/tests/application.e +++ b/library/persistence/implementation/mysql/tests/application.e @@ -1,7 +1,7 @@ note description : "tests application root class" - date : "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $" - revision : "$Revision: 95678 $" + date : "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision : "$Revision: 96542 $" class APPLICATION @@ -17,78 +17,25 @@ feature {NONE} -- Initialization make -- Run application. local - user: USER_DATA_PROVIDER - node: NODE_DATA_PROVIDER - l_security: SECURITY_PROVIDER - l_profile, l_db_profile: CMS_USER_PROFILE - l_cursor: TABLE_ITERATION_CURSOR [READABLE_STRING_8, READABLE_STRING_8] - l_list: LIST[CMS_NODE] storage: CMS_STORAGE l_node: CMS_NODE do create connection.login_with_schema ("cms_dev", "root", "") --- create user.make (connection) --- create node.make (connection) + (create {CLEAN_DB}).clean_db(connection) create {CMS_STORAGE_MYSQL} storage.make (connection) l_node := custom_node ("Content", "Summary", "Title") - storage.save_user (default_user) - storage.save_user (custom_user ("u2", "p2", "e2")) + storage.new_user (default_user) + storage.new_user (custom_user ("u2", "p2", "e2")) l_node.set_author (storage.user_by_email (default_user.email)) - storage.save_node (l_node) - if attached {CMS_NODE} storage.node (1) as ll_node then + storage.new_node (l_node) + if attached {CMS_NODE} storage.node_by_id (1) as ll_node then storage.update_node_title (2,ll_node.id, "New Title") check - attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary + attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary end end - --- user.new_user ("test", "test","test@admin.com") --- if attached {CMS_USER} user.user_by_name ("test") as l_user then --- create l_profile.make --- l_profile.force ("Eiffel", "language") --- l_profile.force ("Argentina", "country") --- l_profile.force ("GMT-3", "time zone") --- user.save_profile (l_user.id, l_profile) --- l_db_profile := user.user_profile (l_user.id) --- from --- l_cursor := l_db_profile.new_cursor --- until --- l_cursor.after --- loop --- print (l_cursor.item + " - " + l_cursor.key + "%N") --- l_cursor.forth --- end - --- create {ARRAYED_LIST[CMS_NODE]} l_list.make (0) --- node.new_node (default_node) --- node.new_node (custom_node ("content1", "summary1", "title1")) --- node.new_node (custom_node ("content2", "summary2", "title2")) --- node.new_node (custom_node ("content3", "summary3", "title3")) --- user.new_user ("u1", "u1", "email") --- if attached user.user_by_name ("u1") as ll_user then --- node.add_collaborator (ll_user.id, 1) --- node.add_collaborator (ll_user.id, 2) --- node.add_collaborator (ll_user.id, 3) --- node.add_collaborator (ll_user.id, 4) - --- across node.collaborator_nodes (l_user.id) as c loop --- print (c.item.title) --- end - --- end - - --- if attached user.user_by_name ("u1") as ll_user then --- node.add_author (ll_user.id, 1) --- if attached node.node_author (1) as l_author then --- print (l_author.name) --- end --- end - - --- end end diff --git a/library/persistence/implementation/mysql/tests/nodes/node_test_set.e b/library/persistence/implementation/mysql/tests/nodes/node_test_set.e index 9b3b442..bd85896 100644 --- a/library/persistence/implementation/mysql/tests/nodes/node_test_set.e +++ b/library/persistence/implementation/mysql/tests/nodes/node_test_set.e @@ -3,8 +3,8 @@ note Eiffel tests that can be executed by testing tool. ]" author: "EiffelStudio test wizard" - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" testing:"execution/isolated" class @@ -29,8 +29,8 @@ feature {NONE} -- Events on_prepare -- do - (create {CLEAN_DB}).clean_db(connection) - assert ("Empty Nodes", node_provider.nodes.after) + (create {CLEAN_DB}).clean_db (connection) + assert ("Empty Nodes", storage.nodes_count = 0) end on_clean @@ -43,14 +43,14 @@ feature -- Test routines test_new_node note testing: "execution/isolated" - do - assert ("Empty Nodes", node_provider.nodes.after) - node_provider.new_node (default_node) - assert ("Not empty Nodes after new_node", not node_provider.nodes.after) + do + assert ("Empty Nodes", storage.nodes_count = 0) + storage.new_node (default_node) + assert ("Not empty Nodes after new_node", not storage.nodes.after) -- Exist node with id 1 - assert ("Exist node with id 1", attached node_provider.node (1)) + assert ("Exist node with id 1", attached storage.node_by_id (1)) -- Not exist node with id 2 - assert ("Not exist node with id 2", node_provider.node (2) = Void) + assert ("Not exist node with id 2", storage.node_by_id (2) = Void) end @@ -60,31 +60,31 @@ feature -- Test routines local l_node: CMS_NODE do - assert ("Empty Nodes", node_provider.nodes.after) + assert ("Empty Nodes", storage.nodes.after) l_node := custom_node ("

test node udpate

", "Update node", "Test case update") - node_provider.new_node (l_node) - assert ("Not empty Nodes after new_node", not node_provider.nodes.after) + storage.new_node (l_node) + assert ("Not empty Nodes after new_node", not storage.nodes.after) -- Exist node with id 1 - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) -- Update node (content and summary) - if attached {CMS_NODE} node_provider.node (1) as l_un then + if attached {CMS_NODE} storage.node_by_id (1) as l_un then l_un.set_content ("

Updating test node udpate

") l_un.set_summary ("updating summary") - node_provider.update_node (0,l_un) - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then ll_node.title ~ l_node.title ) - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title ) + storage.update_node (l_un) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then ll_node.title ~ l_node.title ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title ) end -- Update node (content and summary and title) - if attached {CMS_NODE} node_provider.node (1) as l_un then + if attached {CMS_NODE} storage.node_by_id (1) as l_un then l_un.set_content ("

Updating test node udpate

") l_un.set_summary ("updating summary") l_un.set_title ("Updating Test case") - node_provider.update_node (0,l_un) - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then not (ll_node.title ~ l_node.title) ) - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title ) + storage.update_node (l_un) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then not (ll_node.title ~ l_node.title) ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title ) end end @@ -93,19 +93,23 @@ feature -- Test routines testing: "execution/isolated" local l_node: CMS_NODE + u: CMS_USER do - assert ("Empty Nodes", node_provider.nodes.after) + u := default_user + storage.new_user (u) + + assert ("Empty Nodes", storage.nodes.after) l_node := custom_node ("

test node udpate

", "Update node", "Test case update") - node_provider.new_node (l_node) - assert ("Not empty Nodes after new_node", not node_provider.nodes.after) + storage.new_node (l_node) + assert ("Not empty Nodes after new_node", not storage.nodes.after) -- Exist node with id 1 - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) -- Update node title - if attached {CMS_NODE} node_provider.node (1) as l_un then - node_provider.update_node_title (l_un.id, "New Title") - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then not ( ll_node.title ~ l_un.title) and then ll_node.title ~ "New Title" ) + if attached {CMS_NODE} storage.node_by_id (1) as l_un then + storage.update_node_title (u.id, l_un.id, "New Title") + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then not ( ll_node.title ~ l_un.title) and then ll_node.title ~ "New Title" ) end end @@ -114,19 +118,23 @@ feature -- Test routines testing: "execution/isolated" local l_node: CMS_NODE + u: CMS_USER do - assert ("Empty Nodes", node_provider.nodes.after) + u := default_user + storage.new_user (u) + + assert ("Empty Nodes", storage.nodes.after) l_node := custom_node ("

test node udpate

", "Update node", "Test case update") - node_provider.new_node (l_node) - assert ("Not empty Nodes after new_node", not node_provider.nodes.after) + storage.new_node (l_node) + assert ("Not empty Nodes after new_node", not storage.nodes.after) -- Exist node with id 1 - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) -- Update node summary - if attached {CMS_NODE} node_provider.node (1) as l_un then - node_provider.update_node_summary (l_un.id,"New Summary") - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then not (ll_node.summary ~ l_un.summary) and then ll_node.summary ~ "New Summary" and then ll_node.title ~ l_un.title) + if attached {CMS_NODE} storage.node_by_id (1) as l_un then + storage.update_node_summary (u.id, l_un.id, "New Summary") + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then not (ll_node.summary ~ l_un.summary) and then ll_node.summary ~ "New Summary" and then ll_node.title ~ l_un.title) end end @@ -135,22 +143,26 @@ feature -- Test routines testing: "execution/isolated" local l_node: CMS_NODE + u: CMS_USER do - assert ("Empty Nodes", node_provider.nodes.after) + u := default_user + storage.new_user (u) + + assert ("Empty Nodes", storage.nodes.after) l_node := custom_node ("

test node udpate

", "Update node", "Test case update") - connection.begin_transaction - node_provider.new_node (l_node) - assert ("Not empty Nodes after new_node", not node_provider.nodes.after) + storage.sql_begin_transaction + storage.new_node (l_node) + assert ("Not empty Nodes after new_node", not storage.nodes.after) -- Exist node with id 1 - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) -- Update node content - if attached {CMS_NODE} node_provider.node (1) as l_un then - node_provider.update_node_content (l_un.id,"New Content") - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_un.content) and then ll_node.content ~ "New Content" and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title) + if attached {CMS_NODE} storage.node_by_id (1) as l_un then + storage.update_node_content (u.id, l_un.id, "New Content") + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then not (ll_node.content ~ l_un.content) and then ll_node.content ~ "New Content" and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title) end - connection.commit + storage.sql_commit_transaction end @@ -158,17 +170,17 @@ feature -- Test routines local l_node: CMS_NODE do - assert ("Empty Nodes", node_provider.nodes.after) + assert ("Empty Nodes", storage.nodes.after) l_node := custom_node ("

test node udpate

", "Update node", "Test case update") - node_provider.new_node (l_node) - assert ("Not empty Nodes after new_node", not node_provider.nodes.after) + storage.new_node (l_node) + assert ("Not empty Nodes after new_node", not storage.nodes.after) -- Exist node with id 1 - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) -- Delte node 1 - node_provider.delete_node (1) - assert ("Node does not exist", node_provider.node (1) = Void) + storage.delete_node_by_id (1) + assert ("Node does not exist", storage.node_by_id (1) = Void) end test_recent_nodes @@ -179,142 +191,51 @@ feature -- Test routines local i : INTEGER do - assert ("Empty Nodes", node_provider.nodes.after) + assert ("Empty Nodes", storage.nodes.after) across 1 |..| 10 as c loop - node_provider.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)) + storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)) end -- Scenario (0,10) rows, recents (10 down to 1) i := 10 - across node_provider.recent_nodes (0, 10) as c loop + across storage.recent_nodes (0, 10) as c loop assert ("Same id:" + i.out, c.item.id = i) i := i - 1 end -- Scenario (5, 10) rows, recent nodes (5 down to 1) i := 5 - across node_provider.recent_nodes (5, 10) as c loop + across storage.recent_nodes (5, 10) as c loop assert ("Same id:" + i.out, c.item.id = i) i := i - 1 end -- Scenario (9,10) rows, recent node 1 i := 1 - across node_provider.recent_nodes (9, 10) as c loop + across storage.recent_nodes (9, 10) as c loop assert ("Same id:" + i.out, c.item.id = i) i := i - 1 end -- Scenrario 10..10 empty - assert ("Empty", node_provider.recent_nodes (10, 10).after) - end - - - test_new_node_without_user - do - node_provider.new_node (default_node) - user_provider.new_user ("u1", "u1", "email") - if attached user_provider.user_by_name ("u1") as l_user then - assert ("Empty nodes", node_provider.author_nodes (l_user.id).after) - end + assert ("Empty", storage.recent_nodes (10, 10).after) end test_new_node_add_author do - node_provider.new_node (default_node) - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1)) - user_provider.new_user ("u1", "u1", "email") - if attached user_provider.user_by_name ("u1") as l_user then - node_provider.add_author (l_user.id, 1) - assert ("Author not void for node 1", attached node_provider.node_author (1)) - end - end - - test_new_node_add_collaborator - do - node_provider.new_node (default_node) - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1)) - user_provider.new_user ("u1", "u1", "email") - if attached user_provider.user_by_name ("u1") as l_user then - node_provider.add_collaborator (l_user.id, 1) - assert ("Not Empty Collaborator for node 1", not node_provider.node_collaborators (1).after) - end - end - - test_multiple_nodes_add_collaborator - local - l_list: LIST[CMS_NODE] - do - create {ARRAYED_LIST[CMS_NODE]} l_list.make (0) - node_provider.new_node (default_node) - node_provider.new_node (custom_node ("content1", "summary1", "title1")) - node_provider.new_node (custom_node ("content2", "summary2", "title2")) - node_provider.new_node (custom_node ("content3", "summary3", "title3")) - user_provider.new_user ("u1", "u1", "email") - if attached user_provider.user_by_name ("u1") as l_user then - node_provider.add_collaborator (l_user.id, 1) - node_provider.add_collaborator (l_user.id, 2) - node_provider.add_collaborator (l_user.id, 3) - node_provider.add_collaborator (l_user.id, 4) - assert ("Not Empty Collaborator for node 1", not node_provider.node_collaborators (1).after) - assert ("Not Empty Collaborator for node 2", not node_provider.node_collaborators (2).after) - assert ("Not Empty Collaborator for node 3", not node_provider.node_collaborators (3).after) - assert ("Not Empty Collaborator for node 4", not node_provider.node_collaborators (4).after) - end - end - - test_nodes_collaborator - local - l_list: LIST[CMS_NODE] - do - create {ARRAYED_LIST[CMS_NODE]} l_list.make (0) - node_provider.new_node (default_node) - node_provider.new_node (custom_node ("content1", "summary1", "title1")) - node_provider.new_node (custom_node ("content2", "summary2", "title2")) - node_provider.new_node (custom_node ("content3", "summary3", "title3")) - user_provider.new_user ("u1", "u1", "email") - if attached user_provider.user_by_name ("u1") as l_user then - node_provider.add_collaborator (l_user.id, 1) - node_provider.add_collaborator (l_user.id, 2) - node_provider.add_collaborator (l_user.id, 3) - node_provider.add_collaborator (l_user.id, 4) - across node_provider.collaborator_nodes (l_user.id) as c loop - l_list.force (c.item) + storage.new_node (default_node) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1)) + storage.new_user (custom_user ("u1", "u1", "email")) + if attached storage.user_by_name ("u1") as l_user then + if attached storage.node_by_id (1) as l_node then + l_node.set_author (l_user) + storage.update_node (l_node) + assert ("Author not void for node 1", attached storage.node_author (1)) end - - assert ("User is collaborating in 4 nodes", l_list.count = 4) end end - -feature {NONE} -- Implementation - - node_provider: NODE_DATA_PROVIDER - -- node provider. - once - create Result.make (connection) - end - - user_provider: USER_DATA_PROVIDER - -- user provider. - once - create Result.make (connection) - end - - -feature {NONE} -- Implementation Fixture Factories - - default_node: CMS_NODE - do - Result := custom_node ("Default content", "default summary", "Default") - end - - custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE - do - create Result.make (a_content, a_summary, a_title) - end - end diff --git a/library/persistence/implementation/mysql/tests/roles/role_test_set.e b/library/persistence/implementation/mysql/tests/roles/role_test_set.e deleted file mode 100644 index bac254a..0000000 --- a/library/persistence/implementation/mysql/tests/roles/role_test_set.e +++ /dev/null @@ -1,100 +0,0 @@ -note - description: "Summary description for {ROLE_TEST_SET}." - author: "" - date: "$Date$" - revision: "$Revision$" - -class - ROLE_TEST_SET -inherit - EQA_TEST_SET - redefine - on_prepare, - on_clean - select - default_create - end - ABSTRACT_DB_TEST - rename - default_create as default_db_test - end - - -feature {NONE} -- Events - - on_prepare - -- - do - (create {CLEAN_DB}).clean_db(connection) - end - - on_clean - -- - do - end - -feature -- Test routines - - test_roles_empty - do - assert ("Not elements",role_provider.roles.after) - assert ("Count = 0", role_provider.count = 0) - end - - test_roles_by_id_not_exist - do - assert ("Void", role_provider.role (1) = Void) - end - - test_roles_by_name_not_exist - do - assert ("Void", role_provider.role_by_name ("admin") = Void) - end - - test_new_role - do - assert ("Count = 0", role_provider.count = 0) - role_provider.new_role ("admin") - assert ("Count = 1", role_provider.count = 1) - assert ("Expected role", attached role_provider.role (1) as l_role and then l_role.name ~ "admin") - assert ("Expected role", attached role_provider.role_by_name ("admin") as l_role and then l_role.id = 1) - end - - test_permissions_empty_not_exist_role - do - assert ("Not elements",role_provider.permission_by_role (1).after) - end - - test_permissions_empty_exist_role - do - assert ("Count = 0", role_provider.count = 0) - role_provider.new_role ("admin") - assert ("Count = 1", role_provider.count = 1) - assert ("Exist role",not role_provider.roles.after) - assert ("Not permission by role 1 elements",role_provider.permission_by_role (1).after) - end - - test_new_role_with_permissions - do - assert ("Count = 0", role_provider.count = 0) - role_provider.new_role ("admin") - role_provider.save_role_permission (1, "Create Page") - role_provider.save_role_permission (1, "Edit Page") - role_provider.save_role_permission (1, "Delete Page") - assert ("Count = 1", role_provider.count = 1) - assert ("Exist role",not role_provider.roles.after) - assert ("Exist role permissions",not role_provider.permission_by_role (1).after) - assert ("Not Exist role permissions, for id 2",role_provider.permission_by_role (2).after) - end - - - - -feature {NONE} -- Implementation - - role_provider: ROLE_DATA_PROVIDER - -- role provider. - once - create Result.make (connection) - end -end diff --git a/library/persistence/implementation/mysql/tests/storage/storage_test_set.e b/library/persistence/implementation/mysql/tests/storage/storage_test_set.e index 99779c1..d52ae8d 100644 --- a/library/persistence/implementation/mysql/tests/storage/storage_test_set.e +++ b/library/persistence/implementation/mysql/tests/storage/storage_test_set.e @@ -1,8 +1,8 @@ note description: "Summary description for {STORAGE_TEST_SET}." author: "" - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class STORAGE_TEST_SET @@ -109,15 +109,15 @@ feature -- Test routines retry end - test_save_user + test_new_user do - storage.save_user (default_user) + storage.new_user (default_user) assert ("Has user", storage.has_user) end test_user_by_id do - storage.save_user (default_user) + storage.new_user (default_user) assert ("Has user", storage.has_user) if attached {CMS_USER} storage.user_by_id (1) as l_user then assert ("Exist", True) @@ -130,7 +130,7 @@ feature -- Test routines test_user_by_name do - storage.save_user (default_user) + storage.new_user (default_user) assert ("Has user", storage.has_user) if attached {CMS_USER} storage.user_by_name ("test") as l_user then assert ("Exist", True) @@ -142,7 +142,7 @@ feature -- Test routines test_user_by_email do - storage.save_user (default_user) + storage.new_user (default_user) assert ("Has user", storage.has_user) if attached {CMS_USER} storage.user_by_email ("test@test.com") as l_user then assert ("Exist", True) @@ -154,7 +154,7 @@ feature -- Test routines test_invalid_credential do - storage.save_user (default_user) + storage.new_user (default_user) assert ("Has user test", attached storage.user_by_name ("test")) assert ("Wrong password", not storage.is_valid_credential ("test", "test")) assert ("Wrong user", not storage.is_valid_credential ("test1", "test")) @@ -162,7 +162,7 @@ feature -- Test routines test_valid_credential do - storage.save_user (default_user) + storage.new_user (default_user) assert ("Has user test", attached storage.user_by_name ("test")) assert ("Valid password", storage.is_valid_credential ("test", "password")) end @@ -177,11 +177,11 @@ feature -- Test routines l_nodes: LIST[CMS_NODE] l_node: CMS_NODE do - storage.save_user (default_user) + storage.new_user (default_user) across 1 |..| 10 as c loop l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out) l_node.set_author (storage.user_by_email (default_user.email)) - storage.save_node (l_node) + storage.new_node (l_node) end l_nodes := storage.recent_nodes (0, 10) assert ("10 recent nodes", l_nodes.count = 10) @@ -207,26 +207,26 @@ feature -- Test routines local l_node: CMS_NODE do - storage.save_user (default_user) + storage.new_user (default_user) across 1 |..| 10 as c loop l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out) l_node.set_author (storage.user_by_email (default_user.email)) - storage.save_node (l_node) + storage.new_node (l_node) end - assert ("Not exist node id: 12", storage.node (12) = Void) + assert ("Not exist node id: 12", storage.node_by_id (12) = Void) end test_node local l_node: CMS_NODE do - storage.save_user (default_user) + storage.new_user (default_user) across 1 |..| 10 as c loop l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out) l_node.set_author (storage.user_by_email (default_user.email)) - storage.save_node (l_node) + storage.new_node (l_node) end - assert ("Node id: 10", attached storage.node (10) as ll_node and then ll_node.title ~ "Title_10" ) + assert ("Node id: 10", attached storage.node_by_id (10) as ll_node and then ll_node.title ~ "Title_10" ) end test_update_node @@ -234,17 +234,18 @@ feature -- Test routines l_node: CMS_NODE do l_node := custom_node ("Content", "Summary", "Title") - storage.save_user (default_user) + storage.new_user (default_user) l_node.set_author (storage.user_by_email (default_user.email)) - storage.save_node (l_node) - if attached {CMS_NODE} storage.node (1) as ll_node then + storage.new_node (l_node) + if attached {CMS_NODE} storage.node_by_id (1) as ll_node then l_node := ll_node.twin l_node.set_content ("New Content") l_node.set_summary ("New Summary") l_node.set_title("New Title") if attached storage.user_by_email (default_user.email) as l_user then - storage.update_node (l_user.id,l_node) - assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary)) + l_node.set_author (l_user) + storage.update_node (l_node) + assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary)) end end end @@ -254,13 +255,13 @@ feature -- Test routines l_node: CMS_NODE do l_node := custom_node ("Content", "Summary", "Title") - storage.save_user (default_user) - storage.save_user (custom_user ("u2", "p2", "e2")) + storage.new_user (default_user) + storage.new_user (custom_user ("u2", "p2", "e2")) l_node.set_author (storage.user_by_email (default_user.email)) - storage.save_node (l_node) - if attached {CMS_NODE} storage.node (1) as ll_node then + storage.new_node (l_node) + if attached {CMS_NODE} storage.node_by_id (1) as ll_node then storage.update_node_title (2,ll_node.id, "New Title") - assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary) + assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary) end end @@ -269,13 +270,13 @@ feature -- Test routines l_node: CMS_NODE do l_node := custom_node ("Content", "Summary", "Title") - storage.save_user (default_user) - storage.save_user (custom_user ("u2", "p2", "e2")) + storage.new_user (default_user) + storage.new_user (custom_user ("u2", "p2", "e2")) l_node.set_author (storage.user_by_email (default_user.email)) - storage.save_node (l_node) - if attached {CMS_NODE} storage.node (1) as ll_node then + storage.new_node (l_node) + if attached {CMS_NODE} storage.node_by_id (1) as ll_node then storage.update_node_summary (2,ll_node.id, "New Summary") - assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary)) + assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary)) end end @@ -284,13 +285,13 @@ feature -- Test routines l_node: CMS_NODE do l_node := custom_node ("Content", "Summary", "Title") - storage.save_user (default_user) - storage.save_user (custom_user ("u2", "p2", "e2")) + storage.new_user (default_user) + storage.new_user (custom_user ("u2", "p2", "e2")) l_node.set_author (storage.user_by_email (default_user.email)) - storage.save_node (l_node) - if attached {CMS_NODE} storage.node (1) as ll_node then + storage.new_node (l_node) + if attached {CMS_NODE} storage.node_by_id (1) as ll_node then storage.update_node_content (2,ll_node.id, "New Content") - assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary) + assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary) end end @@ -300,12 +301,12 @@ feature -- Test routines l_node: CMS_NODE do l_node := custom_node ("Content", "Summary", "Title") - storage.save_user (default_user) + storage.new_user (default_user) l_node.set_author (storage.user_by_email (default_user.email)) - storage.save_node (l_node) - if attached {CMS_NODE} storage.node (1) as ll_node then + storage.new_node (l_node) + if attached {CMS_NODE} storage.node_by_id (1) as ll_node then storage.update_node_title (1,ll_node.id, "New Title") - assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary) + assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary) end end @@ -314,12 +315,12 @@ feature -- Test routines l_node: CMS_NODE do l_node := custom_node ("Content", "Summary", "Title") - storage.save_user (default_user) + storage.new_user (default_user) l_node.set_author (storage.user_by_email (default_user.email)) - storage.save_node (l_node) - if attached {CMS_NODE} storage.node (1) as ll_node then + storage.new_node (l_node) + if attached {CMS_NODE} storage.node_by_id (1) as ll_node then storage.update_node_summary (1,ll_node.id, "New Summary") - assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary)) + assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary)) end end @@ -328,12 +329,12 @@ feature -- Test routines l_node: CMS_NODE do l_node := custom_node ("Content", "Summary", "Title") - storage.save_user (default_user) + storage.new_user (default_user) l_node.set_author (storage.user_by_email (default_user.email)) - storage.save_node (l_node) - if attached {CMS_NODE} storage.node (1) as ll_node then + storage.new_node (l_node) + if attached {CMS_NODE} storage.node_by_id (1) as ll_node then storage.update_node_content (1,ll_node.id, "New Content") - assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary) + assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary) end end @@ -342,52 +343,16 @@ feature -- Test routines l_node: CMS_NODE l_user: like {CMS_NODE}.author do - storage.save_user (custom_user ("test_delete", "testu", "email")) + storage.new_user (custom_user ("test_delete", "testu", "email")) l_user := storage.user_by_name ("test_delete") across 1 |..| 10 as c loop l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out) l_node.set_author (l_user) - storage.save_node (l_node) + storage.new_node (l_node) end - assert ("Exist node id: 10", attached storage.node (10) as ll_node and then ll_node.title ~ "Title_10" ) - storage.delete_node (10) - assert ("Not exist node id: 10", storage.node (10) = Void) - end - - - -feature {NONE} -- Implementation - - storage: CMS_STORAGE - -- Storage - once - create {CMS_STORAGE_MYSQL}Result.make (connection) - end - -feature {NONE} -- Fixture Factory: Users - - default_user: CMS_USER - do - Result := custom_user ("test", "password", "test@test.com") - end - - custom_user (a_name, a_password, a_email: READABLE_STRING_32): CMS_USER - do - create Result.make (a_name) - Result.set_password (a_password) - Result.set_email (a_email) - end - -feature {NONE} -- Fixture Factories: Nodes - - default_node: CMS_NODE - do - Result := custom_node ("Default content", "default summary", "Default") - end - - custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE - do - create Result.make (a_content, a_summary, a_title) + assert ("Exist node id: 10", attached storage.node_by_id (10) as ll_node and then ll_node.title ~ "Title_10" ) + storage.delete_node_by_id (10) + assert ("Not exist node id: 10", storage.node_by_id (10) = Void) end end diff --git a/library/persistence/implementation/mysql/tests/tests.ecf b/library/persistence/implementation/mysql/tests/tests.ecf index c526aeb..efe3722 100644 --- a/library/persistence/implementation/mysql/tests/tests.ecf +++ b/library/persistence/implementation/mysql/tests/tests.ecf @@ -1,5 +1,5 @@ - + - + + - + /EIFGENs$ diff --git a/library/persistence/implementation/mysql/tests/transactions/transaction_test_set.e b/library/persistence/implementation/mysql/tests/transactions/transaction_test_set.e index 4abdd8c..2b73918 100644 --- a/library/persistence/implementation/mysql/tests/transactions/transaction_test_set.e +++ b/library/persistence/implementation/mysql/tests/transactions/transaction_test_set.e @@ -3,8 +3,8 @@ note Eiffel tests that can be executed by testing tool. ]" author: "EiffelStudio test wizard" - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" testing: "type/manual" class @@ -30,7 +30,7 @@ feature {NONE} -- Events on_prepare -- do - (create {CLEAN_DB}).clean_db(connection) + (create {CLEAN_DB}).clean_db (connection) end on_clean @@ -43,55 +43,45 @@ feature -- Test routines test_user_rollback note testing: "execution/isolated" + local + u: detachable CMS_USER do - connection.begin_transaction - user_provider.new_user ("test", "test","test@admin.com") - assert ("Has user:", user_provider.has_user) - connection.rollback - assert ("Not has user:", not user_provider.has_user) + u := storage.user_by_name ("test") + if u = Void then + u := custom_user ("test", "test","test@admin.com") + storage.new_user (u) + end + assert ("Has user:", storage.has_user) + u.set_email ("test@example.com") + storage.sql_begin_transaction + storage.update_user (u) + assert ("Has user:", storage.user_by_email ("test@example.com") /= Void) + storage.sql_rollback_transaction + assert ("Not has user:", storage.user_by_email ("test@example.com") = Void) end test_user_node_rollback note testing: "execution/isolated" + local + u: detachable CMS_USER do + u := storage.user_by_name ("test") + if u = Void then + u := custom_user ("test", "test","test@admin.com") + storage.new_user (u) + end + connection.begin_transaction - user_provider.new_user ("test", "test","test@admin.com") - assert ("Has user:", user_provider.has_user) - node_provider.new_node (default_node) - node_provider.add_author (1, 1) - assert ("Has one node:", node_provider.count = 1) + u.set_email ("test@example.com") + assert ("Has user:", storage.user_by_email ("test@example.com") /= Void) + storage.new_node (default_node) + assert ("Has one node:", storage.nodes_count = 1) connection.rollback - assert ("Not has user:", not user_provider.has_user) - assert ("Not has nodes:", node_provider.count = 0) + assert ("Not has user:", storage.user_by_email ("test@example.com") = Void) + assert ("Has no node:", storage.nodes_count = 0) end -feature {NONE} -- Implementation - - node_provider: NODE_DATA_PROVIDER - -- node provider. - once - create Result.make (connection) - end - - user_provider: USER_DATA_PROVIDER - -- user provider. - once - create Result.make (connection) - end - - -feature {NONE} -- Implementation Fixture Factories - - default_node: CMS_NODE - do - Result := custom_node ("Default content", "default summary", "Default") - end - - custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE - do - create Result.make (a_content, a_summary, a_title) - end end diff --git a/library/persistence/implementation/mysql/tests/users/user_test_set.e b/library/persistence/implementation/mysql/tests/users/user_test_set.e index 7768e0e..3ae13b3 100644 --- a/library/persistence/implementation/mysql/tests/users/user_test_set.e +++ b/library/persistence/implementation/mysql/tests/users/user_test_set.e @@ -3,8 +3,8 @@ note Eiffel tests that can be executed by testing tool. ]" author: "EiffelStudio test wizard" - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" testing:"execution/isolated" class @@ -30,7 +30,7 @@ feature {NONE} -- Events -- do (create {CLEAN_DB}).clean_db(connection) - user_provider.new_user ("admin", "admin","admin@admin.com") + storage.new_user (custom_user ("admin", "admin","admin@admin.com")) end on_clean @@ -44,78 +44,67 @@ feature -- Test routines test_user_exist -- User admin exist do - assert ("Not void", attached user_provider.user_by_email ("admin@admin.com")) - assert ("Not void", attached user_provider.user (1)) - assert ("Not void", attached user_provider.user_by_name ("admin")) + assert ("Not void", attached storage.user_by_email ("admin@admin.com")) + assert ("Not void", attached storage.user_by_id (1)) + assert ("Not void", attached storage.user_by_name ("admin")) end test_user_not_exist -- Uset test does not exist. do - assert ("User by email: Void", user_provider.user_by_email ("test1@test.com") = Void) - assert ("User by id: Void", user_provider.user(5) = Void ) - assert ("User by name: Void", user_provider.user_by_name ("test1") = Void) + assert ("User by email: Void", storage.user_by_email ("test1@test.com") = Void) + assert ("User by id: Void", storage.user_by_id (5) = Void ) + assert ("User by name: Void", storage.user_by_name ("test1") = Void) end test_new_user - do - user_provider.new_user ("test", "test","test@admin.com") - assert ("Not void", attached user_provider.user_by_email ("test@admin.com")) - assert ("Not void", attached user_provider.user (2)) - assert ("Not void", attached user_provider.user (2) as l_user and then l_user.id = 2 and then l_user.name ~ "test") - assert ("Not void", attached user_provider.user_by_name ("test")) - end - - test_new_user_with_roles - do - user_provider.new_user ("test", "test","test@admin.com") - role_provider.new_role ("Admin") - assert ("Empty roles for given user", user_provider.user_roles (1).after) - user_provider.add_role (1, 1) - assert ("Not empty roles for given user", not user_provider.user_roles (1).after) - end - - test_new_user_without_profile - do - user_provider.new_user ("test", "test","test@admin.com") - assert ("Empty", user_provider.user_profile (1).new_cursor.after) - end - - test_new_user_with_profile local - l_profile: CMS_USER_PROFILE - l_db_profile: CMS_USER_PROFILE + u: CMS_USER do - user_provider.new_user ("test", "test","test@admin.com") - if attached {CMS_USER} user_provider.user_by_name ("test") as l_user then - assert ("Empty", user_provider.user_profile (l_user.id).new_cursor.after) - create l_profile.make - l_profile.force ("Eiffel", "language") - l_profile.force ("Argentina", "country") - l_profile.force ("GMT-3", "time zone") - user_provider.save_profile (l_user.id, l_profile) - l_db_profile := user_provider.user_profile (l_user.id) - assert ("Not Empty", not l_db_profile.new_cursor.after) - - assert ("Expected language Eiffel", attached l_db_profile.item ("language") as l_language and then l_language ~ "Eiffel") - assert ("Expected time zone GMT-3", attached l_db_profile.item ("time zone") as l_language and then l_language ~ "GMT-3") - end + u := default_user + storage.new_user (u) + assert ("Not void", attached storage.user_by_email (u.email)) + assert ("Not void", attached storage.user_by_id (2)) + assert ("Not void", attached storage.user_by_id (2) as l_user and then l_user.id = 2 and then l_user.name ~ u.name) + assert ("Not void", attached storage.user_by_name (u.name)) end +-- test_new_user_with_roles +-- do +-- storage.new_user (default_user) +-- storage.new_role ("Admin") +-- assert ("Empty roles for given user", storage.user_roles (1).after) +-- storage.add_role (1, 1) +-- assert ("Not empty roles for given user", not storage.user_roles (1).after) +-- end -feature {NONE} -- Implementation +-- test_new_user_without_profile +-- do +-- storage.new_user ("test", "test","test@admin.com") +-- assert ("Empty", storage.user_profile (1).new_cursor.after) +-- end - user_provider: USER_DATA_PROVIDER - -- user provider. - once - create Result.make (connection) - end +-- test_new_user_with_profile +-- local +-- l_profile: CMS_USER_PROFILE +-- l_db_profile: CMS_USER_PROFILE +-- do +-- storage.new_user (default_user) +-- if attached {CMS_USER} storage.user_by_name ("test") as l_user then +-- assert ("Empty", storage.user_profile (l_user.id).new_cursor.after) +-- create l_profile.make +-- l_profile.force ("Eiffel", "language") +-- l_profile.force ("Argentina", "country") +-- l_profile.force ("GMT-3", "time zone") +-- storage.save_profile (l_user.id, l_profile) +-- l_db_profile := storage.user_profile (l_user.id) +-- assert ("Not Empty", not l_db_profile.new_cursor.after) + +-- assert ("Expected language Eiffel", attached l_db_profile.item ("language") as l_language and then l_language ~ "Eiffel") +-- assert ("Expected time zone GMT-3", attached l_db_profile.item ("time zone") as l_language and then l_language ~ "GMT-3") +-- end +-- end - role_provider: ROLE_DATA_PROVIDER - -- user provider. - once - create Result.make (connection) - end end diff --git a/library/persistence/implementation/mysql/tests/util/abstract_db_test.e b/library/persistence/implementation/mysql/tests/util/abstract_db_test.e index 0e23859..d41ffd3 100644 --- a/library/persistence/implementation/mysql/tests/util/abstract_db_test.e +++ b/library/persistence/implementation/mysql/tests/util/abstract_db_test.e @@ -1,7 +1,7 @@ note description: "Summary description for {ABSTRACT_DB_TEST}." - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class ABSTRACT_DB_TEST @@ -14,4 +14,35 @@ feature -- Database connection once create Result.login_with_schema ("cms_dev", "root", "") end + + storage: CMS_STORAGE_MYSQL + once + create Result.make (connection) + end + +feature {NONE} -- Fixture Factory: Users + + default_user: CMS_USER + do + Result := custom_user ("test", "password", "test@test.com") + end + + custom_user (a_name, a_password: READABLE_STRING_32; a_email: READABLE_STRING_8): CMS_USER + do + create Result.make (a_name) + Result.set_password (a_password) + Result.set_email (a_email) + end + +feature {NONE} -- Fixture Factories: Nodes + + default_node: CMS_NODE + do + Result := custom_node ("Default content", "default summary", "Default") + end + + custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE + do + create Result.make (a_content, a_summary, a_title) + end end diff --git a/library/persistence/implementation/sqlite/persistence_sqlite-safe.ecf b/library/persistence/implementation/sqlite/persistence_sqlite-safe.ecf index 3899c9d..abe11ca 100644 --- a/library/persistence/implementation/sqlite/persistence_sqlite-safe.ecf +++ b/library/persistence/implementation/sqlite/persistence_sqlite-safe.ecf @@ -7,6 +7,7 @@ + @@ -19,7 +20,6 @@ - /EIFGENs$ diff --git a/library/persistence/implementation/sqlite/persistence_sqlite.ecf b/library/persistence/implementation/sqlite/persistence_sqlite.ecf index d9a3df0..15c6c61 100644 --- a/library/persistence/implementation/sqlite/persistence_sqlite.ecf +++ b/library/persistence/implementation/sqlite/persistence_sqlite.ecf @@ -7,19 +7,19 @@ + + - + - - /EIFGENs$ diff --git a/library/persistence/implementation/sqlite/scripts/create_database.sql b/library/persistence/implementation/sqlite/scripts/create_database.sql deleted file mode 100644 index 4b9a157..0000000 --- a/library/persistence/implementation/sqlite/scripts/create_database.sql +++ /dev/null @@ -1,61 +0,0 @@ --- Creator: MySQL Workbench 6.1.7/ExportSQLite plugin 2009.12.02 --- Author: javier --- Caption: New Model --- Project: Name of the project --- Changed: 2014-09-16 23:12 --- Created: 2014-09-16 23:12 -PRAGMA foreign_keys = OFF; - --- Schema: cms_dev -BEGIN; -CREATE TABLE "nodes"( - "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("id">=0), - "publication_date" DATE NOT NULL, - "creation_date" DATE NOT NULL, - "modification_date" DATE NOT NULL, - "title" VARCHAR(255) NOT NULL, - "summary" TEXT NOT NULL, - "content" MEDIUMTEXT NOT NULL -); -CREATE TABLE "roles"( - "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("id">=0), - "role" VARCHAR(100) NOT NULL, - CONSTRAINT "role" - UNIQUE("role") -); -CREATE TABLE "users"( - "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("id">=0), - "username" VARCHAR(100) NOT NULL, - "password" VARCHAR(100) NOT NULL, - "salt" VARCHAR(100) NOT NULL, - "email" VARCHAR(250) NOT NULL, - CONSTRAINT "username" - UNIQUE("username") -); -CREATE TABLE "users_nodes"( - "users_id" INTEGER NOT NULL CHECK("users_id">=0), - "nodes_id" INTEGER NOT NULL CHECK("nodes_id">=0), - PRIMARY KEY("users_id","nodes_id"), - CONSTRAINT "fk_users_has_nodes_nodes1" - FOREIGN KEY("nodes_id") - REFERENCES "nodes"("id"), - CONSTRAINT "fk_users_has_nodes_users" - FOREIGN KEY("users_id") - REFERENCES "users"("id") -); -CREATE INDEX "users_nodes.fk_users_has_nodes_nodes1_idx" ON "users_nodes"("nodes_id"); -CREATE INDEX "users_nodes.fk_users_has_nodes_users_idx" ON "users_nodes"("users_id"); -CREATE TABLE "users_roles"( - "users_id" INTEGER NOT NULL CHECK("users_id">=0), - "roles_id" INTEGER NOT NULL CHECK("roles_id">=0), - PRIMARY KEY("users_id","roles_id"), - CONSTRAINT "fk_users_has_roles_roles1" - FOREIGN KEY("roles_id") - REFERENCES "roles"("id"), - CONSTRAINT "fk_users_has_roles_users1" - FOREIGN KEY("users_id") - REFERENCES "users"("id") -); -CREATE INDEX "users_roles.fk_users_has_roles_roles1_idx" ON "users_roles"("roles_id"); -CREATE INDEX "users_roles.fk_users_has_roles_users1_idx" ON "users_roles"("users_id"); -COMMIT; diff --git a/library/persistence/implementation/sqlite/scripts/schema.sql b/library/persistence/implementation/sqlite/scripts/schema.sql new file mode 100644 index 0000000..0dffacb --- /dev/null +++ b/library/persistence/implementation/sqlite/scripts/schema.sql @@ -0,0 +1,36 @@ +PRAGMA foreign_keys = OFF; + +BEGIN; +CREATE TABLE "users"( + "uid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("uid">=0), + "name" VARCHAR(100) NOT NULL, + "password" VARCHAR(100) NOT NULL, + "salt" VARCHAR(100) NOT NULL, + "email" VARCHAR(250) NOT NULL, + "status" INTEGER, + "created" DATETIME NOT NULL, + "signed" DATETIME, + CONSTRAINT "name" + UNIQUE("name") +); + +CREATE TABLE "users_roles"( + "rid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("rid">=0), + "role" VARCHAR(100) NOT NULL, + CONSTRAINT "role" + UNIQUE("role") +); + +CREATE TABLE "nodes"( + "nid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("nid">=0), + "version" INTEGER, + "type" INTEGER, + "title" VARCHAR(255) NOT NULL, + "summary" TEXT NOT NULL, + "content" MEDIUMTEXT NOT NULL, + "author" INTEGER, + "publish" DATETIME, + "created" DATETIME NOT NULL, + "changed" DATETIME NOT NULL +); +COMMIT; diff --git a/library/persistence/implementation/sqlite/scripts/tables.sql b/library/persistence/implementation/sqlite/scripts/tables.sql deleted file mode 100644 index 4b1a4ba..0000000 --- a/library/persistence/implementation/sqlite/scripts/tables.sql +++ /dev/null @@ -1,14 +0,0 @@ -DROP TABLE IF EXISTS nodes; - -CREATE TABLE nodes -( - id smallint unsigned NOT NULL auto_increment, - publication_date date NOT NULL, #When the article was published - creation_date date NOT NULL, #When the article was created - modification_date date NOT NULL, #When the article was updated - title varchar(255) NOT NULL, #Full title of the article - summary text NOT NULL, #A short summary of the articule - content mediumtext NOT NULL, #The HTML content of the article - - PRIMARY KEY (ID) -); \ No newline at end of file diff --git a/library/persistence/implementation/sqlite/src/cms_node_storage_sqlite.e b/library/persistence/implementation/sqlite/src/cms_node_storage_sqlite.e new file mode 100644 index 0000000..b8fe118 --- /dev/null +++ b/library/persistence/implementation/sqlite/src/cms_node_storage_sqlite.e @@ -0,0 +1,75 @@ +note + description: "Summary description for {CMS_NODE_STORAGE_SQLITE}." + author: "" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_NODE_STORAGE_SQLITE + +inherit + CMS_NODE_STORAGE_SQL + redefine + nodes, recent_nodes + end + +feature {NONE} -- Implementation + + db_handler: DATABASE_HANDLER + deferred + end + +feature -- Access + + nodes: LIST [CMS_NODE] + -- List of nodes. + do + create {ARRAYED_LIST [CMS_NODE]} Result.make (0) + across nodes_iterator as ic loop + Result.force (ic.item) + end + end + + recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE] + -- List of recent `a_count' nodes with an offset of `lower'. + do + create {ARRAYED_LIST [CMS_NODE]} Result.make (a_count) + across recent_nodes_iterator (a_lower, a_count) as c loop + Result.force (c.item) + end + end + +feature -- Access: iterator + + nodes_iterator: DATABASE_ITERATION_CURSOR [CMS_NODE] + -- List of nodes. + local + l_parameters: STRING_TABLE [ANY] + do + error_handler.reset + log.write_information (generator + ".nodes_iterator") + create l_parameters.make (0) + sql_query (select_nodes, l_parameters) + sql_post_execution + create Result.make (db_handler, agent fetch_node) + end + + recent_nodes_iterator (a_lower, a_rows: INTEGER): DATABASE_ITERATION_CURSOR [CMS_NODE] + -- The most recent `a_rows'. + local + l_parameters: STRING_TABLE [ANY] + l_query: STRING + do + -- FIXME: check implementation... + error_handler.reset + log.write_information (generator + ".recent_nodes_iterator") + create l_parameters.make (2) + l_parameters.put (a_rows, "rows") + l_parameters.put (a_lower, "offset") + create l_query.make_from_string (select_recent_nodes) + sql_query (l_query, l_parameters) + create Result.make (db_handler, agent fetch_node) + sql_post_execution + end + +end diff --git a/library/persistence/implementation/sqlite/src/cms_storage_sqlite.e b/library/persistence/implementation/sqlite/src/cms_storage_sqlite.e index f463110..9e91049 100644 --- a/library/persistence/implementation/sqlite/src/cms_storage_sqlite.e +++ b/library/persistence/implementation/sqlite/src/cms_storage_sqlite.e @@ -1,249 +1,112 @@ note description: "Summary description for {CMS_STORAGE_MYSQL}." - date: "$Date: 2014-11-13 12:23:47 -0300 (ju., 13 nov. 2014) $" - revision: "$Revision: 96085 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class CMS_STORAGE_SQLITE inherit - CMS_STORAGE + + CMS_STORAGE_STORE_SQL + + CMS_USER_STORAGE_SQLITE + + CMS_NODE_STORAGE_SQLITE + REFACTORING_HELPER create make -feature {NONE} -- Initialization +--feature {NONE} -- Initialization - make (a_connection: DATABASE_CONNECTION) - -- - require - is_connected: a_connection.is_connected - do - log.write_information (generator+".make_with_database is database connected? "+ a_connection.is_connected.out ) - create node_provider.make (a_connection) - create user_provider.make (a_connection) - create error_handler.make - end +-- make (a_connection: DATABASE_CONNECTION) +-- -- +-- require +-- is_connected: a_connection.is_connected +-- do +-- connection := a_connection +-- log.write_information (generator + ".make_with_database is database connected? "+ a_connection.is_connected.out ) +-- create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection) -feature -- Access: user +-- create error_handler.make +---- error_handler.add_synchronization (db_handler.database_error_handler) +-- end - has_user: BOOLEAN - -- Has any user? - do - Result := user_provider.has_user +-- db_handler: DATABASE_HANDLER - end +-- connection: DATABASE_CONNECTION +-- -- Current database connection. +--feature -- Access: user - all_users: LIST [CMS_USER] - do - to_implement("Not implemented!!!") - create {ARRAYED_LIST[CMS_USER]} Result.make (0) - end +-- sql_post_execution +-- -- Post database execution. +-- do +-- error_handler.append (db_handler.database_error_handler) +-- if error_handler.has_error then +-- log.write_critical (generator + ".post_execution " + error_handler.as_string_representation) +-- end +-- end - user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER - do - Result := user_provider.user (a_id) +-- sql_begin_transaction +-- do +-- connection.begin_transaction +-- end - end +-- sql_commit_transaction +-- do +-- connection.commit +-- end - user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER - do - Result := user_provider.user_by_name (a_name) +-- sql_query (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY]) +-- do +-- check_sql_query_validity (a_sql_statement, a_params) +-- db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params)) +-- db_handler.execute_query +-- end - end +-- sql_change (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY]) +-- do +-- check_sql_query_validity (a_sql_statement, a_params) +-- db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params)) +-- db_handler.execute_change +-- end - user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER - do - Result := user_provider.user_by_email (a_email) +-- sql_rows_count: INTEGER +-- -- Number of rows for last sql execution. +-- do +-- Result := db_handler.count +-- end - end +-- sql_start +-- -- Set the cursor on first element. +-- do +-- db_handler.start +-- end - is_valid_credential (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN - local - l_security: SECURITY_PROVIDER - do - if attached user_provider.user_salt (l_auth_login) as l_hash then - 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 +-- sql_after: BOOLEAN +-- -- Are there no more items to iterate over? +-- do +-- Result := db_handler.after +-- end - end +-- sql_forth +-- -- Fetch next row from last sql execution, if any. +-- do +-- db_handler.forth +-- end -feature -- Change: user - - save_user (a_user: CMS_USER) - -- Add a new user `a_user'. - do - if - attached a_user.password as l_password and then - attached a_user.email as l_email - then - user_provider.new_user (a_user.name, l_password, l_email) - else - -- set error - end - end - -feature -- User Nodes - - user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE] - -- Possible list of nodes where the user identified by `a_id', is a collaborator. - do - create {ARRAYED_LIST[CMS_NODE]} Result.make (0) - to_implement ("Not implemented") - end - - user_author_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE] - -- Possible list of nodes where the user identified by `a_id', is the author. - do - create {ARRAYED_LIST[CMS_NODE]} Result.make (0) - to_implement ("Not implemented") - end - -feature -- Users roles and permissions - - user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE - -- User role by id `a_id', if any. - do - to_implement ("Not implemented") - end - - user_roles: LIST [CMS_USER_ROLE] - -- Possible list of user roles. - do - create {ARRAYED_LIST[CMS_USER_ROLE]} Result.make (0) - to_implement ("Not implemented") - end - -feature -- Change: roles and permissions - - save_user_role (a_user_role: CMS_USER_ROLE) - -- Save user role `a_user_role' - do - to_implement ("Not implemented") - end - - -feature -- Access: node - - nodes: LIST[CMS_NODE] - -- List of nodes. - do - create {ARRAYED_LIST[CMS_NODE]} Result.make (0) - across node_provider.nodes as c loop - Result.force (c.item) - end - - 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) - across node_provider.recent_nodes (a_lower,a_count) as c loop - Result.force (c.item) - end - - end - - node (a_id: INTEGER_64): detachable CMS_NODE - -- - do - Result := node_provider.node (a_id) - - end - - -feature -- Node - - save_node (a_node: CMS_NODE) - -- Add a new node - do - node_provider.new_node (a_node) - - end - - delete_node (a_id: INTEGER_64) - do - node_provider.delete_node (a_id) - - end - - update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE) - do - node_provider.update_node (a_node) - - end - - update_node_title (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32) - do - node_provider.update_node_title (a_id, a_title) - - end - - update_node_summary (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32) - do - node_provider.update_node_summary (a_id, a_summary) - - end - - update_node_content (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32) - do - node_provider.update_node_content (a_id, a_content) - - end - - - node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER - -- Node's author. if any. - do - to_implement ("Not implemented") - end - - node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER] - -- Possible list of node's collaborator. - do - create {ARRAYED_LIST[CMS_USER]} Result.make (0) - to_implement ("Not implemented") - end - - -feature -- User - - new_user (a_user: CMS_USER) - -- Add a new user `a_user'. - do - if - attached a_user.password as l_password and then - attached a_user.email as l_email - then - user_provider.new_user (a_user.name, l_password, l_email) - else - -- set error - end - end - -feature {NONE} -- Implementation - - node_provider: NODE_DATA_PROVIDER - -- Node Data provider. - - user_provider: USER_DATA_PROVIDER - -- User Data provider. +-- sql_item (a_index: INTEGER): detachable ANY +-- do +-- if attached {DB_TUPLE} db_handler.item as l_item and then l_item.count >= a_index then +-- Result := l_item.item (a_index) +-- else +-- check has_item_at_index: False end +-- end +-- end end diff --git a/library/persistence/implementation/sqlite/src/cms_storage_sqlite_builder.e b/library/persistence/implementation/sqlite/src/cms_storage_sqlite_builder.e new file mode 100644 index 0000000..3dcbb30 --- /dev/null +++ b/library/persistence/implementation/sqlite/src/cms_storage_sqlite_builder.e @@ -0,0 +1,43 @@ +note + description: "[ + Objects that ... + ]" + author: "$Author: jfiat $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +class + CMS_STORAGE_SQLITE_BUILDER + +inherit + CMS_STORAGE_BUILDER + +create + make + +feature {NONE} -- Initialization + + make + -- Initialize `Current'. + do + end + +feature -- Factory + + storage (a_setup: CMS_SETUP): detachable CMS_STORAGE_SQLITE + local + s: STRING + do + if attached (create {APPLICATION_JSON_CONFIGURATION_HELPER}).new_database_configuration (a_setup.layout.application_config_path) as l_database_config then + s := "Driver=SQLite3 ODBC Driver;Database=" + if attached l_database_config.database_name as db_name then + s.append (db_name) + end + s.append (";LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;") + create Result.make (create {DATABASE_CONNECTION_ODBC}.login_with_connection_string (s)) + --create Result.make (create {DATABASE_CONNECTION_ODBC}.login_with_connection_string (l_database_config.connection_string)) + end + end + + +end diff --git a/library/persistence/implementation/sqlite/src/cms_user_storage_sqlite.e b/library/persistence/implementation/sqlite/src/cms_user_storage_sqlite.e new file mode 100644 index 0000000..68ccb3a --- /dev/null +++ b/library/persistence/implementation/sqlite/src/cms_user_storage_sqlite.e @@ -0,0 +1,14 @@ +note + description: "Summary description for {CMS_USER_STORAGE_SQLITE}." + author: "" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_USER_STORAGE_SQLITE + +inherit + CMS_USER_STORAGE_SQL + + +end diff --git a/library/persistence/implementation/sqlite/src/provider/node_data_provider.e b/library/persistence/implementation/sqlite/src/provider/node_data_provider.e deleted file mode 100644 index 25c4606..0000000 --- a/library/persistence/implementation/sqlite/src/provider/node_data_provider.e +++ /dev/null @@ -1,275 +0,0 @@ -note - description: "Database access for node uses cases." - date: "$Date: 2014-11-13 12:23:47 -0300 (ju., 13 nov. 2014) $" - revision: "$Revision: 96085 $" - -class - NODE_DATA_PROVIDER - -inherit - - PARAMETER_NAME_HELPER - - SHARED_ERROR - - REFACTORING_HELPER - -create - make - -feature -- Initialization - - make (a_connection: DATABASE_CONNECTION) - -- Create a data provider. - do - create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection) - - end - - db_handler: DATABASE_HANDLER - -- Db handler. - -feature -- Status Report - - is_successful: BOOLEAN - -- Is the last execution sucessful? - do - Result := not db_handler.has_error - end - -feature -- Access - - nodes: DATABASE_ITERATION_CURSOR [CMS_NODE] - -- List of nodes. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".nodes") - create l_parameters.make (0) - db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_nodes, l_parameters)) - db_handler.execute_query - create Result.make (db_handler, agent fetch_node) - - end - - recent_nodes (a_lower, a_rows: INTEGER): DATABASE_ITERATION_CURSOR [CMS_NODE] - -- The most recent `a_rows'. - local - l_parameters: STRING_TABLE [ANY] - l_query: STRING - do - log.write_information (generator + ".recent_nodes") - create l_parameters.make (2) - l_parameters.put (a_rows, "rows") - create l_query.make_from_string (select_recent_nodes) - l_query.replace_substring_all ("$offset", a_lower.out) - db_handler.set_query (create {DATABASE_QUERY}.data_reader (l_query, l_parameters)) - db_handler.execute_query - create Result.make (db_handler, agent fetch_node) - - end - - node (a_id: INTEGER_64): detachable CMS_NODE - -- Node for the given id `a_id', if any. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".node") - create l_parameters.make (1) - l_parameters.put (a_id,"id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_node_by_id, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := fetch_node - end - - end - - count: INTEGER - -- Number of items nodes. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".count") - create l_parameters.make (0) - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_count, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := db_handler.read_integer_32 (1) - end - - end - -feature -- Basic operations - - new_node (a_node: CMS_NODE) - -- Create a new node. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".new_node") - create l_parameters.make (6) - l_parameters.put (a_node.title, "title") - l_parameters.put (a_node.summary, "summary") - l_parameters.put (a_node.content, "content") - l_parameters.put (a_node.publication_date, "publication_date") - l_parameters.put (a_node.creation_date, "creation_date") - l_parameters.put (a_node.modification_date, "modification_date") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_insert_node, l_parameters)) - db_handler.execute_change - - end - - update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32) - -- Update node title for the corresponding the report with id `a_id'. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".update_node_title") - create l_parameters.make (3) - l_parameters.put (a_title, "title") - l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date") - l_parameters.put (a_id, "id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node_title, l_parameters)) - db_handler.execute_change - - end - - update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32) - -- Update node summary for the corresponding the report with id `a_id'. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".update_node_summary") - create l_parameters.make (3) - l_parameters.put (a_summary, "summary") - l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date") - l_parameters.put (a_id, "id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node_summary, l_parameters)) - db_handler.execute_change - - end - - update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32) - -- Update node content for the corresponding the report with id `a_id'. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".update_node_content") - create l_parameters.make (3) - l_parameters.put (a_content, "content") - l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date") - l_parameters.put (a_id, "id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node_content, l_parameters)) - db_handler.execute_change - - end - - update_node (a_node: CMS_NODE) - -- Update node. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".update_node") - create l_parameters.make (7) - l_parameters.put (a_node.title, "title") - l_parameters.put (a_node.summary, "summary") - l_parameters.put (a_node.content, "content") - l_parameters.put (a_node.publication_date, "publication_date") - l_parameters.put (a_node.creation_date, "creation_date") - l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date") - l_parameters.put (a_node.id, "id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node, l_parameters)) - db_handler.execute_change - - end - - delete_node (a_id: INTEGER_64;) - -- Delete node with id `a_id'. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".delete_node") - create l_parameters.make (1) - l_parameters.put (a_id, "id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_delete_node, l_parameters)) - db_handler.execute_change - end - -feature -- Connection - - connect - -- Connect to the database. - do - if not db_handler.is_connected then - db_handler.connect - end - end - - disconnect - -- Disconnect to the database. - do - if db_handler.is_connected then - db_handler.disconnect - end - end - -feature {NONE} -- Queries - - Select_count: STRING = "select count(*) from Nodes;" - - Select_nodes: STRING = "select * from Nodes;" - -- SQL Query to retrieve all nodes. - - Select_node_by_id: STRING = "select * from Nodes where id =:id order by id desc, publication_date desc;" - - Select_recent_nodes: STRING = "select * from Nodes order by id desc, publication_date desc Limit $offset , :rows " - - SQL_Insert_node: STRING = "insert into nodes (title, summary, content, publication_date, creation_date, modification_date) values (:title, :summary, :content, :publication_date, :creation_date, :modification_date);" - -- SQL Insert to add a new node. - - SQL_Update_node_title: STRING ="update nodes SET title=:title, modification_date=:modification_date where id=:id;" - -- SQL update node title. - - SQL_Update_node_summary: STRING ="update nodes SET summary=:summary, modification_date=:modification_date where id=:id;" - -- SQL update node summary. - - SQL_Update_node_content: STRING ="update nodes SET content=:content, modification_date=:modification_date where id=:id;" - -- SQL node content. - - SQL_Update_node : STRING = "update nodes SET title=:title, summary=:summary, content=:content, publication_date=:publication_date, creation_date=:creation_date, modification_date=:modification_date where id=:id;" - -- SQL node. - - SQL_Delete_node: STRING = "delete from nodes where id=:id;" - - -feature -- New Object - - fetch_node: CMS_NODE - do - create Result.make ("", "", "") - if attached db_handler.read_integer_32 (1) as l_id then - Result.set_id (l_id) - end - if attached db_handler.read_date_time (2) as l_pd then - Result.set_publication_date (l_pd) - end - if attached db_handler.read_date_time (3) as l_cd then - Result.set_creation_date (l_cd) - end - if attached db_handler.read_date_time (4) as l_md then - Result.set_modification_date (l_md) - end - if attached db_handler.read_string (5) as l_t then - Result.set_title (l_t) - end - if attached db_handler.read_string (6) as l_s then - Result.set_summary (l_s) - end - if attached db_handler.read_string (7) as l_c then - Result.set_content (l_c) - end - end - - -end diff --git a/library/persistence/implementation/sqlite/src/provider/user_data_provider.e b/library/persistence/implementation/sqlite/src/provider/user_data_provider.e deleted file mode 100644 index 60fd235..0000000 --- a/library/persistence/implementation/sqlite/src/provider/user_data_provider.e +++ /dev/null @@ -1,193 +0,0 @@ -note - description: "Summary description for {USER_DATA_PROVIDER}." - date: "$Date: 2014-11-13 12:23:47 -0300 (ju., 13 nov. 2014) $" - revision: "$Revision: 96085 $" - -class - USER_DATA_PROVIDER - -inherit - - PARAMETER_NAME_HELPER - - SHARED_ERROR - - REFACTORING_HELPER - -create - make - -feature -- Initialization - - make (a_connection: DATABASE_CONNECTION) - -- Create a data provider. - do - create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection) - - end - - db_handler: DATABASE_HANDLER - -- Db handler. - -feature -- Status Report - - is_successful: BOOLEAN - -- Is the last execution sucessful? - do - Result := not db_handler.has_error - end - - has_user: BOOLEAN - -- Has any user? - do - Result := count > 0 - end - -feature -- Basic Operations - - new_user (a_user_name: READABLE_STRING_32; a_password: READABLE_STRING_32; a_email: READABLE_STRING_32) - -- Create a new node. - local - l_parameters: STRING_TABLE [detachable ANY] - l_password_salt, l_password_hash: STRING - l_security: SECURITY_PROVIDER - do - create l_security - l_password_salt := l_security.salt - l_password_hash := l_security.password_hash (a_password, l_password_salt) - - log.write_information (generator + ".new_user") - create l_parameters.make (4) - l_parameters.put (a_user_name,"username") - l_parameters.put (l_password_hash,"password") - l_parameters.put (l_password_salt,"salt") - l_parameters.put (a_email,"email") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_insert_user, l_parameters)) - db_handler.execute_change - - end - - user (a_id: INTEGER_64): detachable CMS_USER - -- User for the given id `a_id', if any. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".user") - create l_parameters.make (1) - l_parameters.put (a_id,"id") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_user_by_id, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := fetch_user - end - - end - - user_by_name (a_name: READABLE_STRING_32): detachable CMS_USER - -- User for the given name `a_name', if any. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".user_by_name") - create l_parameters.make (1) - l_parameters.put (a_name,"name") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_user_by_name, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := fetch_user - end - - end - - - user_by_email (a_email: detachable READABLE_STRING_32): detachable CMS_USER - -- User for the given email `a_email', if any. - local - l_parameters: STRING_TABLE [detachable ANY] - do - log.write_information (generator + ".user_by_email") - create l_parameters.make (1) - l_parameters.put (a_email,"email") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_user_by_email, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := fetch_user - end - - end - - user_salt (a_username: READABLE_STRING_32): detachable READABLE_STRING_32 - -- User salt for the given user `a_username', if any. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".user_salt") - create l_parameters.make (1) - l_parameters.put (a_username,"name") - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_salt_by_username, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - if attached db_handler.read_string (1) as l_salt then - Result := l_salt.as_string_32 - end - end - - end - - count: INTEGER - -- Number of items users. - local - l_parameters: STRING_TABLE [ANY] - do - log.write_information (generator + ".count") - create l_parameters.make (0) - db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_count, l_parameters)) - db_handler.execute_query - if db_handler.count = 1 then - Result := db_handler.read_integer_32 (1) - end - - end - -feature -- New Object - - fetch_user: CMS_USER - do - create Result.make ("") - if attached db_handler.read_integer_32 (1) as l_id then - Result.set_id (l_id) - end - if attached db_handler.read_string (2) as l_u then - Result.set_name (l_u) - end - if attached db_handler.read_string (3) as l_p then - Result.set_password (l_p) - end - if attached db_handler.read_string (5) as l_e then - Result.set_email (l_e) - end - end - -feature -- Sql Queries - - Select_count: STRING = "select count(*) from Users;" - -- Number of users. - - Select_user_by_id: STRING = "select * from Users where id =:id;" - -- Retrieve user by id if exists. - - Select_user_by_name: STRING = "select * from Users where username =:name;" - -- Retrieve user by name if exists. - - Select_user_by_email: STRING = "select * from Users where email =:email;" - -- Retrieve user by email if exists. - - Select_salt_by_username: STRING = "select salt from Users where username =:name;" - -- Retrieve salt by username if exists. - - SQL_Insert_user: STRING = "insert into users (username, password, salt, email) values (:username, :password, :salt, :email);" - -- SQL Insert to add a new node. - - - -end diff --git a/library/persistence/implementation/sqlite/tests/application.e b/library/persistence/implementation/sqlite/tests/application.e index 82c32f0..9b3ede1 100644 --- a/library/persistence/implementation/sqlite/tests/application.e +++ b/library/persistence/implementation/sqlite/tests/application.e @@ -1,7 +1,7 @@ note description : "tests application root class" - date : "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $" - revision : "$Revision: 95678 $" + date : "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision : "$Revision: 96542 $" class APPLICATION @@ -17,14 +17,11 @@ feature {NONE} -- Initialization make -- Run application. local - user: USER_DATA_PROVIDER - node: NODE_DATA_PROVIDER - l_security: SECURITY_PROVIDER + storage: CMS_STORAGE_SQLITE do - -- Change the path. + -- Change the path. create connection.login_with_connection_string ("Driver=SQLite3 ODBC Driver;Database=./cms_lite.db;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;") - create user.make (connection) - user.new_user ("test", "test", "test") + create storage.make (connection) end connection: DATABASE_CONNECTION_ODBC diff --git a/library/persistence/implementation/sqlite/tests/nodes/node_test_set.e b/library/persistence/implementation/sqlite/tests/nodes/node_test_set.e index 3ae6665..e80f720 100644 --- a/library/persistence/implementation/sqlite/tests/nodes/node_test_set.e +++ b/library/persistence/implementation/sqlite/tests/nodes/node_test_set.e @@ -3,8 +3,8 @@ note Eiffel tests that can be executed by testing tool. ]" author: "EiffelStudio test wizard" - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" testing: "type/manual" class @@ -30,7 +30,7 @@ feature {NONE} -- Events -- do (create {CLEAN_DB}).clean_db(connection) - assert ("Empty Nodes", node_provider.nodes.after) + assert ("Empty Nodes", storage.nodes.after) end on_clean @@ -42,13 +42,13 @@ feature -- Test routines test_new_node do - assert ("Empty Nodes", node_provider.nodes.after) - node_provider.new_node (default_node) - assert ("Not empty Nodes after new_node", not node_provider.nodes.after) + assert ("Empty Nodes", storage.nodes.after) + storage.new_node (default_node) + assert ("Not empty Nodes after new_node", not storage.nodes.after) -- Exist node with id 1 - assert ("Exist node with id 1", attached node_provider.node (1)) + assert ("Exist node with id 1", attached storage.node_by_id (1)) -- Not exist node with id 2 - assert ("Not exist node with id 2", node_provider.node (2) = Void) + assert ("Not exist node with id 2", storage.node_by_id (2) = Void) end @@ -56,31 +56,31 @@ feature -- Test routines local l_node: CMS_NODE do - assert ("Empty Nodes", node_provider.nodes.after) + assert ("Empty Nodes", storage.nodes.after) l_node := custom_node ("

test node udpate

", "Update node", "Test case update") - node_provider.new_node (l_node) - assert ("Not empty Nodes after new_node", not node_provider.nodes.after) + storage.new_node (l_node) + assert ("Not empty Nodes after new_node", not storage.nodes.after) -- Exist node with id 1 - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) -- Update node (content and summary) - if attached {CMS_NODE} node_provider.node (1) as l_un then + if attached {CMS_NODE} storage.node_by_id (1) as l_un then l_un.set_content ("

Updating test node udpate

") l_un.set_summary ("updating summary") - node_provider.update_node (l_un) - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then ll_node.title ~ l_node.title ) - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title ) + storage.update_node (l_un) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then ll_node.title ~ l_node.title ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title ) end -- Update node (content and summary and title) - if attached {CMS_NODE} node_provider.node (1) as l_un then + if attached {CMS_NODE} storage.node_by_id (1) as l_un then l_un.set_content ("

Updating test node udpate

") l_un.set_summary ("updating summary") l_un.set_title ("Updating Test case") - node_provider.update_node (l_un) - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then not (ll_node.title ~ l_node.title) ) - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title ) + storage.update_node (l_un) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then not (ll_node.title ~ l_node.title) ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title ) end end @@ -88,18 +88,18 @@ feature -- Test routines local l_node: CMS_NODE do - assert ("Empty Nodes", node_provider.nodes.after) + assert ("Empty Nodes", storage.nodes.after) l_node := custom_node ("

test node udpate

", "Update node", "Test case update") - node_provider.new_node (l_node) - assert ("Not empty Nodes after new_node", not node_provider.nodes.after) + storage.new_node (l_node) + assert ("Not empty Nodes after new_node", not storage.nodes.after) -- Exist node with id 1 - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) -- Update node title - if attached {CMS_NODE} node_provider.node (1) as l_un then - node_provider.update_node_title (l_un.id, "New Title") - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then not ( ll_node.title ~ l_un.title) and then ll_node.title ~ "New Title" ) + if attached {CMS_NODE} storage.node_by_id (1) as l_un then + storage.update_node_title (1, l_un.id, "New Title") + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then not ( ll_node.title ~ l_un.title) and then ll_node.title ~ "New Title" ) end end @@ -107,18 +107,18 @@ feature -- Test routines local l_node: CMS_NODE do - assert ("Empty Nodes", node_provider.nodes.after) + assert ("Empty Nodes", storage.nodes.after) l_node := custom_node ("

test node udpate

", "Update node", "Test case update") - node_provider.new_node (l_node) - assert ("Not empty Nodes after new_node", not node_provider.nodes.after) + storage.new_node (l_node) + assert ("Not empty Nodes after new_node", not storage.nodes.after) -- Exist node with id 1 - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) -- Update node summary - if attached {CMS_NODE} node_provider.node (1) as l_un then - node_provider.update_node_summary (l_un.id,"New Summary") - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then not (ll_node.summary ~ l_un.summary) and then ll_node.summary ~ "New Summary" and then ll_node.title ~ l_un.title) + if attached {CMS_NODE} storage.node_by_id (1) as l_un then + storage.update_node_summary (1, l_un.id,"New Summary") + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then not (ll_node.summary ~ l_un.summary) and then ll_node.summary ~ "New Summary" and then ll_node.title ~ l_un.title) end end @@ -126,18 +126,18 @@ feature -- Test routines local l_node: CMS_NODE do - assert ("Empty Nodes", node_provider.nodes.after) + assert ("Empty Nodes", storage.nodes.after) l_node := custom_node ("

test node udpate

", "Update node", "Test case update") - node_provider.new_node (l_node) - assert ("Not empty Nodes after new_node", not node_provider.nodes.after) + storage.new_node (l_node) + assert ("Not empty Nodes after new_node", not storage.nodes.after) -- Exist node with id 1 - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) -- Update node content - if attached {CMS_NODE} node_provider.node (1) as l_un then - node_provider.update_node_content (l_un.id,"New Content") - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_un.content) and then ll_node.content ~ "New Content" and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title) + if attached {CMS_NODE} storage.node_by_id (1) as l_un then + storage.update_node_content (1, l_un.id, "New Content") + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then not (ll_node.content ~ l_un.content) and then ll_node.content ~ "New Content" and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title) end end @@ -146,17 +146,17 @@ feature -- Test routines local l_node: CMS_NODE do - assert ("Empty Nodes", node_provider.nodes.after) + assert ("Empty Nodes", storage.nodes.after) l_node := custom_node ("

test node udpate

", "Update node", "Test case update") - node_provider.new_node (l_node) - assert ("Not empty Nodes after new_node", not node_provider.nodes.after) + storage.new_node (l_node) + assert ("Not empty Nodes after new_node", not storage.nodes.after) -- Exist node with id 1 - assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) + assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title ) -- Delte node 1 - node_provider.delete_node (1) - assert ("Node does not exist", node_provider.node (1) = Void) + storage.delete_node_by_id (1) + assert ("Node does not exist", storage.node_by_id (1) = Void) end test_recent_nodes @@ -167,57 +167,37 @@ feature -- Test routines local i : INTEGER do - assert ("Empty Nodes", node_provider.nodes.after) + assert ("Empty Nodes", storage.nodes.after) across 1 |..| 10 as c loop - node_provider.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)) + storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)) end -- Scenario (0,10) rows, recents (10 down to 1) i := 10 - across node_provider.recent_nodes (0, 10) as c loop + across storage.recent_nodes (0, 10) as c loop assert ("Same id:" + i.out, c.item.id = i) i := i - 1 end -- Scenario (5, 10) rows, recent nodes (5 down to 1) i := 5 - across node_provider.recent_nodes (5, 10) as c loop + across storage.recent_nodes (5, 10) as c loop assert ("Same id:" + i.out, c.item.id = i) i := i - 1 end -- Scenario (9,10) rows, recent node 1 i := 1 - across node_provider.recent_nodes (9, 10) as c loop + across storage.recent_nodes (9, 10) as c loop assert ("Same id:" + i.out, c.item.id = i) i := i - 1 end -- Scenrario 10..10 empty - assert ("Empty", node_provider.recent_nodes (10, 10).after) + assert ("Empty", storage.recent_nodes (10, 10).after) end -feature {NONE} -- Implementation - - node_provider: NODE_DATA_PROVIDER - -- node provider. - once - create Result.make (connection) - end - - -feature {NONE} -- Implementation Fixture Factories - - default_node: CMS_NODE - do - Result := custom_node ("Default content", "default summary", "Default") - end - - custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE - do - create Result.make (a_content, a_summary, a_title) - end end diff --git a/library/persistence/implementation/sqlite/tests/storage/storage_test_set.e b/library/persistence/implementation/sqlite/tests/storage/storage_test_set.e index 4d893ed..d77def1 100644 --- a/library/persistence/implementation/sqlite/tests/storage/storage_test_set.e +++ b/library/persistence/implementation/sqlite/tests/storage/storage_test_set.e @@ -1,8 +1,8 @@ note description: "Summary description for {STORAGE_TEST_SET}." author: "" - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class STORAGE_TEST_SET @@ -177,7 +177,7 @@ feature -- Test routines l_nodes: LIST[CMS_NODE] do across 1 |..| 10 as c loop - storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)) + storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)) end l_nodes := storage.recent_nodes (0, 10) assert ("10 recent nodes", l_nodes.count = 10) @@ -200,124 +200,74 @@ feature -- Test routines end test_node_does_not_exist - local - l_nodes: LIST[CMS_NODE] do across 1 |..| 10 as c loop - storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)) + storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)) end - assert ("Not exist node id: 12", storage.node (12) = Void) + assert ("Not exist node id: 12", storage.node_by_id (12) = Void) end test_node - local - l_nodes: LIST[CMS_NODE] do across 1 |..| 10 as c loop - storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)) + storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)) end - assert ("Node id: 10", attached storage.node (10) as l_node and then l_node.title ~ "Title_10" ) + assert ("has nodes", storage.nodes.count > 5) + assert ("Node id: 10", attached storage.node_by_id (10) as l_node and then l_node.title ~ "Title_10" ) end test_update_node local - l_nodes: LIST[CMS_NODE] l_node: CMS_NODE do - storage.save_node (custom_node ("Content", "Summary", "Title")) - if attached {CMS_NODE} storage.node (1) as ll_node then + storage.new_node (custom_node ("Content", "Summary", "Title")) + if attached {CMS_NODE} storage.node_by_id (1) as ll_node then l_node := ll_node.twin l_node.set_content ("New Content") l_node.set_summary ("New Summary") l_node.set_title("New Title") -- storage.update_node (l_node) - assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary)) + assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary)) end end test_update_node_title - local - l_nodes: LIST[CMS_NODE] - l_node: CMS_NODE do - storage.save_node (custom_node ("Content", "Summary", "Title")) - if attached {CMS_NODE} storage.node (1) as ll_node then + storage.new_node (custom_node ("Content", "Summary", "Title")) + if attached {CMS_NODE} storage.node_by_id (1) as ll_node then -- storage.update_node_title (ll_node.id, "New Title") - assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary) + assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary) end end test_update_node_summary - local - l_nodes: LIST[CMS_NODE] - l_node: CMS_NODE do - storage.save_node (custom_node ("Content", "Summary", "Title")) - if attached {CMS_NODE} storage.node (1) as ll_node then + storage.new_node (custom_node ("Content", "Summary", "Title")) + if attached {CMS_NODE} storage.node_by_id (1) as ll_node then -- storage.update_node_summary (ll_node.id, "New Summary") - assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary)) + assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary)) end end test_update_node_content - local - l_nodes: LIST[CMS_NODE] - l_node: CMS_NODE do - storage.save_node (custom_node ("Content", "Summary", "Title")) - if attached {CMS_NODE} storage.node (1) as ll_node then + storage.new_node (custom_node ("Content", "Summary", "Title")) + if attached {CMS_NODE} storage.node_by_id (1) as ll_node then -- storage.update_node_content (ll_node.id, "New Content") - assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary) + assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary) end end test_delete_node - local - l_nodes: LIST[CMS_NODE] do across 1 |..| 10 as c loop - storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)) + storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)) end - assert ("Exist node id: 10", attached storage.node (10) as l_node and then l_node.title ~ "Title_10" ) - storage.delete_node (10) - assert ("Not exist node id: 10", storage.node (10) = Void) + assert ("Exist node id: 10", attached storage.node_by_id (10) as l_node and then l_node.title ~ "Title_10" ) + storage.delete_node_by_id (10) + assert ("Not exist node id: 10", storage.node_by_id (10) = Void) end - -feature {NONE} -- Implementation - - storage: CMS_STORAGE - -- Storage - once - create {CMS_STORAGE_SQLITE}Result.make (connection) - end - -feature {NONE} -- Fixture Factory: Users - - default_user: CMS_USER - do - Result := custom_user ("test", "password", "test@test.com") - end - - custom_user (a_name, a_password, a_email: READABLE_STRING_32): CMS_USER - do - create Result.make (a_name) - Result.set_password (a_password) - Result.set_email (a_email) - end - -feature {NONE} -- Fixture Factories: Nodes - - default_node: CMS_NODE - do - Result := custom_node ("Default content", "default summary", "Default") - end - - custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE - do - create Result.make (a_content, a_summary, a_title) - end - end diff --git a/library/persistence/implementation/sqlite/tests/tests-safe.ecf b/library/persistence/implementation/sqlite/tests/tests-safe.ecf index a905aec..e06085e 100644 --- a/library/persistence/implementation/sqlite/tests/tests-safe.ecf +++ b/library/persistence/implementation/sqlite/tests/tests-safe.ecf @@ -7,6 +7,7 @@ + diff --git a/library/persistence/implementation/sqlite/tests/users/user_test_set.e b/library/persistence/implementation/sqlite/tests/users/user_test_set.e index 6b06e9f..db5047c 100644 --- a/library/persistence/implementation/sqlite/tests/users/user_test_set.e +++ b/library/persistence/implementation/sqlite/tests/users/user_test_set.e @@ -3,8 +3,8 @@ note Eiffel tests that can be executed by testing tool. ]" author: "EiffelStudio test wizard" - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" testing: "type/manual" class @@ -30,7 +30,7 @@ feature {NONE} -- Events -- do (create {CLEAN_DB}).clean_db(connection) - user_provider.new_user ("admin", "admin","admin@admin.com") + storage.new_user (custom_user ("admin", "admin","admin@admin.com")) end on_clean @@ -43,36 +43,30 @@ feature -- Test routines test_user_exist -- User admin exist do - assert ("Not void", attached user_provider.user_by_email ("admin@admin.com")) - assert ("Not void", attached user_provider.user (1)) - assert ("Not void", attached user_provider.user_by_name ("admin")) + assert ("Not void", attached storage.user_by_email ("admin@admin.com")) + assert ("Not void", attached storage.user_by_id (1)) + assert ("Not void", attached storage.user_by_name ("admin")) end test_user_not_exist -- Uset test does not exist. do - assert ("Void", user_provider.user_by_email ("test@admin.com") = Void) - assert ("Void", user_provider.user(2) = Void ) - assert ("Void", user_provider.user_by_name ("test") = Void) + assert ("Void", storage.user_by_email ("test@admin.com") = Void) + assert ("Void", storage.user_by_id (2) = Void ) + assert ("Void", storage.user_by_name ("test") = Void) end test_new_user do - user_provider.new_user ("test", "test","test@admin.com") - assert ("Not void", attached user_provider.user_by_email ("test@admin.com")) - assert ("Not void", attached user_provider.user (2)) - assert ("Not void", attached user_provider.user (2) as l_user and then l_user.id = 2 and then l_user.name ~ "test") - assert ("Not void", attached user_provider.user_by_name ("test")) + storage.new_user (custom_user ("test", "test","test@admin.com")) + assert ("Not void", attached storage.user_by_email ("test@admin.com")) + assert ("Not void", attached storage.user_by_id (2)) + assert ("Not void", attached storage.user_by_id (2) as l_user and then l_user.id = 2 and then l_user.name ~ "test") + assert ("Not void", attached storage.user_by_name ("test")) end -feature {NONE} -- Implementation - user_provider: USER_DATA_PROVIDER - -- user provider. - once - create Result.make (connection) - end end diff --git a/library/persistence/implementation/sqlite/tests/util/abstract_db_test.e b/library/persistence/implementation/sqlite/tests/util/abstract_db_test.e index 6ba5b1b..7479959 100644 --- a/library/persistence/implementation/sqlite/tests/util/abstract_db_test.e +++ b/library/persistence/implementation/sqlite/tests/util/abstract_db_test.e @@ -1,7 +1,7 @@ note description: "Summary description for {ABSTRACT_DB_TEST}." - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class ABSTRACT_DB_TEST @@ -12,8 +12,43 @@ feature -- Database connection connection: DATABASE_CONNECTION_ODBC -- odbc database connection once --- create Result.login_with_connection_string ("Driver=SQLite3 ODBC Driver;Database=PATH/SQLITE.FILE;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;") - create Result.make_basic ("cms_dev") + create Result.login_with_connection_string ("Driver=SQLite3 ODBC Driver;Database=cms_lite.db;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;") +-- create Result.make_basic ("cms_lite.db") end +feature {NONE} -- Implementation + + storage: CMS_STORAGE + -- node provider. + once + create {CMS_STORAGE_SQLITE} Result.make (connection) + end + +feature {NONE} -- Fixture Factory: Users + + default_user: CMS_USER + do + Result := custom_user ("test", "password", "test@test.com") + end + + custom_user (a_name, a_password, a_email: READABLE_STRING_32): CMS_USER + do + create Result.make (a_name) + Result.set_password (a_password) + Result.set_email (a_email) + end + +feature {NONE} -- Fixture Factories: Nodes + + default_node: CMS_NODE + do + Result := custom_node ("Default content", "default summary", "Default") + end + + custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE + do + create Result.make (a_content, a_summary, a_title) + end + + end diff --git a/library/persistence/interface/cms_storage.e b/library/persistence/interface/cms_storage.e deleted file mode 100644 index 234613d..0000000 --- a/library/persistence/interface/cms_storage.e +++ /dev/null @@ -1,261 +0,0 @@ - -note - description : "[ - CMS interface to storage - ]" - date : "$Date$" - revision : "$Revision$" - -deferred class - CMS_STORAGE - -inherit - - SHARED_LOGGER - -feature {NONE} -- Initialization - - initialize - do - end - -feature -- Error Handling - - error_handler: ERROR_HANDLER - -- Error handler. - -feature -- Access: user - - has_user: BOOLEAN - -- Has any user? - deferred - end - - all_users: LIST [CMS_USER] - -- Possible list of users. - deferred - end - - user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER - -- User with id `a_id', if any. - require - a_id > 0 - deferred - ensure - same_id: Result /= Void implies Result.id = a_id - password: Result /= Void implies Result.password /= Void - end - - user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER - -- User with name `a_name', if any. - require - a_name /= Void and then not a_name.is_empty - deferred - ensure - same_name: Result /= Void implies a_name ~ Result.name - password: Result /= Void implies Result.password /= Void - end - - user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER - -- User with name `a_email', if any. - deferred - ensure - same_email: Result /= Void implies a_email ~ Result.email - password: Result /= Void implies Result.password /= Void - end - - is_valid_credential (a_u, a_p: READABLE_STRING_32): BOOLEAN - -- Does account with username `a_username' and password `a_password' exist? - deferred - end - -feature -- User Nodes - - user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE] - -- Possible list of nodes where the user identified by `a_id', is a collaborator. - require - a_id > 0 - deferred - end - - user_author_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE] - -- Possible list of nodes where the user identified by `a_id', is the author. - require - a_id > 0 - deferred - end - -feature -- Change: user - - save_user (a_user: CMS_USER) - -- Save user `a_user'. - deferred - end - -feature -- Access: roles and permissions - - user_has_permission (u: detachable CMS_USER; s: detachable READABLE_STRING_8): BOOLEAN - -- Anonymous or user `u' has permission for `s' ? - --| `s' could be "create page", - do --- if s = Void then --- Result := True --- elseif u = Void then ----- Result := user_role_has_permission (anonymous_user_role, s) --- else --- Result := user_role_has_permission (authenticated_user_role, s) --- if not Result and attached u.roles as l_roles then --- across --- l_roles as r --- until --- Result --- loop --- if attached user_role_by_id (r.item) as ur then --- Result := user_role_has_permission (ur, s) --- end --- end --- end --- end - end - - user_role_has_permission (a_role: CMS_USER_ROLE; s: READABLE_STRING_8): BOOLEAN - do - Result := a_role.has_permission (s) - end - - user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE - -- User role by id `a_id', if any. - deferred - end - - user_roles: LIST [CMS_USER_ROLE] - -- Possible list of user roles. - deferred - end - -feature -- Change: roles and permissions - - save_user_role (a_user_role: CMS_USER_ROLE) - -- Save user role `a_user_role' - deferred - end - -feature -- Email - --- save_email (a_email: NOTIFICATION_EMAIL) --- deferred --- end - ---feature -- Log - --- recent_logs (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_LOG] --- deferred --- end - --- log (a_id: like {CMS_LOG}.id): detachable CMS_LOG --- require --- a_id > 0 --- deferred --- end - --- save_log (a_log: CMS_LOG) --- deferred --- end - -feature -- Access: Node - - recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE] - -- List of recent `a_count' nodes with an offset of `lower'. - deferred - end - - node (a_id: INTEGER_64): detachable CMS_NODE - -- Retrieve node by id `a_id', if any. - require - a_id > 0 - deferred - end - - node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER - -- Node's author. if any. - require - valid_node: a_id >0 - deferred - end - - node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER] - -- Possible list of node's collaborator. - require - valid_node: a_id > 0 - deferred - end - -feature -- Change: Node - - save_node (a_node: CMS_NODE) - -- Save node `a_node'. - require - valid_user: attached a_node.author as l_author and then l_author.id > 0 - deferred - end - - delete_node (a_id: INTEGER_64) - -- Remove node by id `a_id'. - require - valid_node_id: a_id > 0 - deferred - end - - update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE) - -- Update node content `a_node'. - -- The user `a_id' is an existing or new collaborator. - require - valid_node_id: a_node.id > 0 - valid_user_id: a_id > 0 - deferred - end - - update_node_title (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32) - -- Update node title to `a_title', node identified by id `a_node_id'. - -- The user `a_id' is an existing or new collaborator. - require - valid_node_id: a_node_id > 0 - valid_user_id: a_id > 0 - deferred - end - - update_node_summary (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32) - -- Update node summary to `a_summary', node identified by id `a_node_id'. - -- The user `a_id' is an existing or new collaborator. - require - valid_id: a_node_id > 0 - deferred - end - - update_node_content (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32) - -- Update node content to `a_content', node identified by id `a_node_id'. - -- The user `a_id' is an existing or new collaborator. - require - valid_id: a_node_id > 0 - valid_user_id: a_id > 0 - deferred - end - ---feature -- Misc - --- set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: READABLE_STRING_8) --- -- Save data `a_name:a_value' for type `a_type' --- deferred --- end - --- custom_value (a_name: READABLE_STRING_8; a_type: READABLE_STRING_8): detachable TABLE_ITERABLE [READABLE_STRING_8, STRING_8] --- -- Data for name `a_name' and type `a_type'. --- deferred --- end - --- custom_value_names_where (a_where_key, a_where_value: READABLE_STRING_8; a_type: READABLE_STRING_8): detachable LIST [READABLE_STRING_8] --- -- Names where custom value has item `a_where_key' same as `a_where_value' for type `a_type'. --- deferred --- end - -end diff --git a/library/src/configuration/cms_default_setup.e b/library/src/configuration/cms_default_setup.e index cad0c09..9555a8b 100644 --- a/library/src/configuration/cms_default_setup.e +++ b/library/src/configuration/cms_default_setup.e @@ -2,8 +2,8 @@ note description: "[ Default CMS_SETUP that can be reused easily, and/or redefined to match specific setup. ]" - date: "$Date: 2015-01-14 16:13:47 +0100 (mer., 14 janv. 2015) $" - revision: "$Revision: 96454 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class CMS_DEFAULT_SETUP @@ -31,7 +31,10 @@ feature {NONE} -- Initialization do configure create modules.make (3) + create storage_drivers.make (2) + build_mailer + initialize_storages initialize_modules end @@ -72,6 +75,12 @@ feature {NONE} -- Initialization compute_theme_assets_location end + initialize_storages + -- Initialize storages + do + storage_drivers.force (create {CMS_STORAGE_NULL_BUILDER}, "null") + end + initialize_modules -- Intialize core modules. local @@ -144,6 +153,11 @@ feature -- Access to_implement ("Not implemented mailer") end +feature -- Access: storage + + storage_drivers: STRING_TABLE [CMS_STORAGE_BUILDER] + -- Precursor + feature -- Element change register_module (m: CMS_MODULE) diff --git a/library/src/configuration/cms_setup.e b/library/src/configuration/cms_setup.e index e1218e6..c18fc97 100644 --- a/library/src/configuration/cms_setup.e +++ b/library/src/configuration/cms_setup.e @@ -1,11 +1,14 @@ note description: "Class that enable to set basic configuration, application layout, core modules and themes." - date: "$Date: 2015-01-14 18:12:03 +0100 (mer., 14 janv. 2015) $" - revision: "$Revision: 96456 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" deferred class CMS_SETUP +inherit + REFACTORING_HELPER + feature -- Access layout: CMS_LAYOUT @@ -88,7 +91,6 @@ feature -- Query deferred end - feature -- Access: Theme themes_location: PATH @@ -109,6 +111,54 @@ feature -- Access: Theme theme_name: READABLE_STRING_32 -- theme name. +feature -- Access: storage + + storage_drivers: STRING_TABLE [CMS_STORAGE_BUILDER] + deferred + end + + storage (a_error_handler: ERROR_HANDLER): detachable CMS_STORAGE + local + retried: BOOLEAN + l_message: STRING + do + if not retried then + to_implement ("Refactor database setup") + if + attached (create {APPLICATION_JSON_CONFIGURATION_HELPER}).new_database_configuration (layout.application_config_path) as l_database_config and then + attached storage_drivers.item (l_database_config.driver) as l_builder + then + Result := l_builder.storage (Current) + else + create {CMS_STORAGE_NULL} Result + end + else + to_implement ("Workaround code, persistence layer does not implement yet this kind of error handling.") + -- error hanling. + create {CMS_STORAGE_NULL} Result + create l_message.make (1024) + if attached ((create {EXCEPTION_MANAGER}).last_exception) as l_exception then + if attached l_exception.description as l_description then + l_message.append (l_description.as_string_32) + l_message.append ("%N%N") + elseif attached l_exception.trace as l_trace then + l_message.append (l_trace) + l_message.append ("%N%N") + else + l_message.append (l_exception.out) + l_message.append ("%N%N") + end + else + l_message.append ("The application crash without available information") + l_message.append ("%N%N") + end + a_error_handler.add_custom_error (0, " Database Connection ", l_message) + end + rescue + retried := True + retry + end + feature -- Element change register_module (m: CMS_MODULE) diff --git a/library/src/modules/node/handler/node_content_handler.e b/library/src/modules/node/handler/node_content_handler.e index 9355765..46bdbd5 100644 --- a/library/src/modules/node/handler/node_content_handler.e +++ b/library/src/modules/node/handler/node_content_handler.e @@ -1,7 +1,7 @@ note description: "Summary description for {NEW_CONTENT_HANDLER}." - date: "$Date: 2014-12-19 14:17:32 +0100 (ven., 19 déc. 2014) $" - revision: "$Revision: 96402 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class NODE_CONTENT_HANDLER @@ -120,7 +120,7 @@ feature -- HTTP Methods if attached {WSF_STRING} req.path_parameter ("id") as l_id then if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then u_node := extract_data_form (req) - u_node.set_id (l_id.integer_value) + u_node.set_id (l_id.value.to_integer_64) api.update_node_content (l_user.id, u_node.id, u_node.content) (create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url ("")) else diff --git a/library/src/modules/node/handler/node_handler.e b/library/src/modules/node/handler/node_handler.e index 0e42283..a6770ed 100644 --- a/library/src/modules/node/handler/node_handler.e +++ b/library/src/modules/node/handler/node_handler.e @@ -1,7 +1,7 @@ note description: "Summary description for {NODE_HANDLER}." - date: "$Date: 2014-12-19 14:17:32 +0100 (ven., 19 déc. 2014) $" - revision: "$Revision: 96402 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class NODE_HANDLER @@ -68,7 +68,10 @@ feature -- HTTP Methods do -- Existing node if attached {WSF_STRING} req.path_parameter ("id") as l_id then - if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then + if + l_id.is_integer and then + attached api.node (l_id.value.to_integer_64) as l_node + then create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api) l_page.add_variable (l_node, "node") l_page.execute @@ -89,7 +92,10 @@ feature -- HTTP Methods to_implement ("Check user permissions!!!") if attached current_user (req) as l_user then if attached {WSF_STRING} req.path_parameter ("id") as l_id then - if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then + if + l_id.is_integer and then + attached {CMS_NODE} api.node (l_id.value.to_integer_64) as l_node + then if attached {WSF_STRING} req.form_parameter ("method") as l_method then if l_method.is_case_insensitive_equal ("DELETE") then do_delete (req, res) @@ -104,7 +110,8 @@ feature -- HTTP Methods end else -- New node - u_node := extract_data_form (req) + create u_node.make ("", "", "") + update_node_from_data_form (req, u_node) u_node.set_author (l_user) api.new_node (u_node) (create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url ("")) @@ -116,16 +123,17 @@ feature -- HTTP Methods do_put (req: WSF_REQUEST; res: WSF_RESPONSE) -- - local - u_node: CMS_NODE do if attached current_user (req) as l_user then if attached {WSF_STRING} req.path_parameter ("id") as l_id then - if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then - u_node := extract_data_form (req) - u_node.set_id (l_id.integer_value) - api.update_node (l_user.id,u_node) + if + l_id.is_integer and then + attached api.node (l_id.value.to_integer_64) as l_node + then + update_node_from_data_form (req, l_node) + l_node.set_author (l_user) + api.update_node (l_node) (create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url ("")) else do_error (req, res, l_id) @@ -136,7 +144,6 @@ feature -- HTTP Methods else (create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res) end - end do_delete (req: WSF_REQUEST; res: WSF_RESPONSE) @@ -144,8 +151,11 @@ feature -- HTTP Methods do if attached current_user_name (req) then if attached {WSF_STRING} req.path_parameter ("id") as l_id then - if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then - api.delete_node (l_id.integer_value) + if + l_id.is_integer and then + attached api.node (l_id.integer_value) as l_node + then + api.delete_node (l_node) (create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url ("")) else do_error (req, res, l_id) @@ -198,19 +208,18 @@ feature {NONE} -- Node feature -- {NONE} Form data - extract_data_form (req: WSF_REQUEST): CMS_NODE + update_node_from_data_form (req: WSF_REQUEST; a_node: CMS_NODE) -- Extract request form data and build a object -- Node do - create Result.make ("", "", "") if attached {WSF_STRING} req.form_parameter ("title") as l_title then - Result.set_title (l_title.value) + a_node.set_title (l_title.value) end if attached {WSF_STRING} req.form_parameter ("summary") as l_summary then - Result.set_summary (l_summary.value) + a_node.set_summary (l_summary.value) end if attached {WSF_STRING} req.form_parameter ("content") as l_content then - Result.set_content (l_content.value) + a_node.set_content (l_content.value) end end diff --git a/library/src/modules/node/handler/node_summary_handler.e b/library/src/modules/node/handler/node_summary_handler.e index 8846379..8aea572 100644 --- a/library/src/modules/node/handler/node_summary_handler.e +++ b/library/src/modules/node/handler/node_summary_handler.e @@ -1,7 +1,7 @@ note description: "Summary description for {NODE_SUMMARY_HANDLER}." - date: "$Date: 2014-12-19 14:17:32 +0100 (ven., 19 déc. 2014) $" - revision: "$Revision: 96402 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class NODE_SUMMARY_HANDLER @@ -118,7 +118,7 @@ feature -- HTTP Methods if attached {WSF_STRING} req.path_parameter ("id") as l_id then if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then u_node := extract_data_form (req) - u_node.set_id (l_id.integer_value) + u_node.set_id (l_id.value.to_integer_64) api.update_node_summary (l_user.id,u_node.id, u_node.summary) (create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url ("")) else diff --git a/library/src/modules/node/handler/node_title_handler.e b/library/src/modules/node/handler/node_title_handler.e index cab8841..21cce14 100644 --- a/library/src/modules/node/handler/node_title_handler.e +++ b/library/src/modules/node/handler/node_title_handler.e @@ -1,7 +1,7 @@ note description: "Summary description for {NODE_TITLE_HANDLER}." - date: "$Date: 2014-12-19 14:17:32 +0100 (ven., 19 déc. 2014) $" - revision: "$Revision: 96402 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class NODE_TITLE_HANDLER @@ -118,7 +118,7 @@ feature -- HTTP Methods if attached {WSF_STRING} req.path_parameter ("id") as l_id then if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then u_node := extract_data_form (req) - u_node.set_id (l_id.integer_value) + u_node.set_id (l_id.value.to_integer_64) api.update_node_title (l_user.id,u_node.id, u_node.title) (create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url ("")) else diff --git a/library/src/modules/node/node_module.e b/library/src/modules/node/node_module.e index 8150e3e..add17aa 100644 --- a/library/src/modules/node/node_module.e +++ b/library/src/modules/node/node_module.e @@ -1,7 +1,7 @@ note description: "CMS module that bring support for NODE management." - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class NODE_MODULE @@ -33,7 +33,6 @@ feature {NONE} -- Initialization config := a_setup end - config: CMS_SETUP -- Node configuration. @@ -159,10 +158,42 @@ feature -- Handler do_get_nodes (req: WSF_REQUEST; res: WSF_RESPONSE; a_api: CMS_API) local r: CMS_RESPONSE + s: STRING + l_user: CMS_USER + l_node: CMS_NODE do - create {NOT_IMPLEMENTED_ERROR_CMS_RESPONSE} r.make (req, res, a_api) - r.set_main_content ("Sorry: listing the CMS nodes is not yet implemented.") - r.add_block (create {CMS_CONTENT_BLOCK}.make ("nodes_warning", Void, "/nodes/ is not yet implemented", Void), "highlighted") + create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, a_api) + + if attached a_api.user_by_name ("foo") as u then + l_user := u + else + create l_user.make ("foo") + l_user.set_password ("foobar#") + l_user.set_email ("test@example.com") + a_api.new_user (l_user) + end + if a_api.nodes_count = 0 then + create l_node.make ({STRING_32} "This is a content", {STRING_32} "And a summary", {STRING_32} "Nice title") + l_node.set_author (l_user) + a_api.new_node (l_node) + end + + create s.make_from_string ("

Nodes:

") + if attached a_api.nodes as lst then + across + lst as ic + loop + s.append ("
  • ") + s.append (a_api.html_encoded (ic.item.title)) + s.append (" (") + s.append (ic.item.id.out) + s.append (")") + s.append ("
  • %N") + end + end + + r.set_main_content (s) + r.add_block (create {CMS_CONTENT_BLOCK}.make ("nodes_warning", Void, "/nodes/ is not yet fully implemented
    ", Void), "highlighted") r.execute end diff --git a/library/src/persistence/cms_storage.e b/library/src/persistence/cms_storage.e new file mode 100644 index 0000000..3ce62fd --- /dev/null +++ b/library/src/persistence/cms_storage.e @@ -0,0 +1,47 @@ + +note + description : "[ + CMS interface to storage + ]" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_STORAGE + +inherit + CMS_USER_STORAGE + + CMS_NODE_STORAGE + + SHARED_LOGGER + +feature {NONE} -- Initialization + + initialize + do + end + +feature -- Error Handling + + error_handler: ERROR_HANDLER + -- Error handler. + +feature -- Misc + +-- set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: READABLE_STRING_8) +-- -- Save data `a_name:a_value' for type `a_type' +-- deferred +-- end + +-- custom_value (a_name: READABLE_STRING_8; a_type: READABLE_STRING_8): detachable TABLE_ITERABLE [READABLE_STRING_8, STRING_8] +-- -- Data for name `a_name' and type `a_type'. +-- deferred +-- end + +-- custom_value_names_where (a_where_key, a_where_value: READABLE_STRING_8; a_type: READABLE_STRING_8): detachable LIST [READABLE_STRING_8] +-- -- Names where custom value has item `a_where_key' same as `a_where_value' for type `a_type'. +-- deferred +-- end + +end diff --git a/library/src/persistence/cms_storage_builder.e b/library/src/persistence/cms_storage_builder.e new file mode 100644 index 0000000..3f79c98 --- /dev/null +++ b/library/src/persistence/cms_storage_builder.e @@ -0,0 +1,18 @@ +note + description: "[ + Objects that ... + ]" + author: "$Author: jfiat $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_STORAGE_BUILDER + +feature -- Factory + + storage (a_setup: CMS_SETUP): detachable CMS_STORAGE + deferred + end + +end diff --git a/library/persistence/implementation/common/cms_storage_null.e b/library/src/persistence/cms_storage_null.e similarity index 77% rename from library/persistence/implementation/common/cms_storage_null.e rename to library/src/persistence/cms_storage_null.e index 89eb3df..0b85dd9 100644 --- a/library/persistence/implementation/common/cms_storage_null.e +++ b/library/src/persistence/cms_storage_null.e @@ -1,19 +1,19 @@ note description: "Summary description for {CMS_STORAGE_NULL}." - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class CMS_STORAGE_NULL inherit - CMS_STORAGE redefine default_create select default_create end + REFACTORING_HELPER rename default_create as default_create_rh @@ -33,7 +33,7 @@ feature -- Access: user do end - all_users: LIST [CMS_USER] + users: LIST [CMS_USER] do create {ARRAYED_LIST[CMS_USER]} Result.make (0) end @@ -70,11 +70,16 @@ feature -- User Nodes feature -- Change: user - save_user (a_user: CMS_USER) + new_user (a_user: CMS_USER) -- Add a new user `a_user'. do end + update_user (a_user: CMS_USER) + -- Update user `a_user'. + do + end + feature -- Access: roles and permissions user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE @@ -93,9 +98,13 @@ feature -- Change: roles and permissions do end - feature -- Access: node + nodes_count: INTEGER_64 + -- Count of nodes. + do + end + nodes: LIST[CMS_NODE] -- List of nodes. do @@ -108,7 +117,7 @@ feature -- Access: node create {ARRAYED_LIST[CMS_NODE]} Result.make (0) end - node (a_id: INTEGER_64): detachable CMS_NODE + node_by_id (a_id: INTEGER_64): detachable CMS_NODE -- do end @@ -126,41 +135,34 @@ feature -- Access: node feature -- Node - save_node (a_node: CMS_NODE) + new_node (a_node: CMS_NODE) -- Add a new node do end - delete_node (a_id: INTEGER_64) + delete_node_by_id (a_id: INTEGER_64) -- do end - update_node (a_id: like {CMS_NODE}.id; a_node: CMS_NODE) + update_node (a_node: CMS_NODE) -- do end - update_node_title (a_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32) + update_node_title (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32) -- do end - update_node_summary (a_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32) + update_node_summary (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32) -- do end - update_node_content (a_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32) + update_node_content (a_user_id: like {CMS_NODE}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32) -- do end -feature -- User - - new_user (a_user: CMS_USER) - -- Add a new user `a_user'. - do - end - end diff --git a/library/src/persistence/cms_storage_null_builder.e b/library/src/persistence/cms_storage_null_builder.e new file mode 100644 index 0000000..3bfae86 --- /dev/null +++ b/library/src/persistence/cms_storage_null_builder.e @@ -0,0 +1,22 @@ +note + description: "[ + Objects that ... + ]" + author: "$Author: jfiat $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +class + CMS_STORAGE_NULL_BUILDER + +inherit + CMS_STORAGE_BUILDER + +feature -- Factory + + storage (a_setup: CMS_SETUP): detachable CMS_STORAGE_NULL + do + create Result + end + +end diff --git a/library/src/persistence/cms_storage_sql.e b/library/src/persistence/cms_storage_sql.e new file mode 100644 index 0000000..5b9bc13 --- /dev/null +++ b/library/src/persistence/cms_storage_sql.e @@ -0,0 +1,214 @@ +note + description: "Summary description for {CMS_STORAGE_SQL}." + author: "" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_STORAGE_SQL + +feature -- Error handler + + error_handler: ERROR_HANDLER + deferred + end + +feature -- Execution + + sql_begin_transaction + deferred + end + + sql_rollback_transaction + deferred + end + + sql_commit_transaction + deferred + end + + sql_post_execution + -- Post database execution. + deferred + end + +feature -- Operation + + check_sql_query_validity (a_sql_statement: READABLE_STRING_8; a_params: detachable STRING_TABLE [detachable ANY]) + local + l_sql_params: STRING_TABLE [READABLE_STRING_8] + i,j,n: INTEGER + s: STRING + do + create l_sql_params.make_caseless (0) + from + i := 1 + n := a_sql_statement.count + until + i > n + loop + i := a_sql_statement.index_of (':', i) + if i = 0 then + i := n -- exit + else + from + j := i + 1 + until + j > n or not (a_sql_statement[j].is_alpha_numeric or a_sql_statement[j] = '_') + loop + j := j + 1 + end + s := a_sql_statement.substring (i + 1, j - 1) + l_sql_params.force (s, s) + end + i := i + 1 + end + if a_params = Void then + if not l_sql_params.is_empty then + check False end + error_handler.add_custom_error (-1, "invalid query", "missing value for sql parameters") + end + else + across + a_params as ic + loop + if l_sql_params.has (ic.key) then + l_sql_params.remove (ic.key) + else + error_handler.add_custom_error (-1, "useless value", "value for unexpected parameter [" + ic.key + "]") + end + end + across + l_sql_params as ic + loop + error_handler.add_custom_error (-1, "invalid query", "missing value for sql parameter [" + ic.item + "]") + end + end + end + + sql_query (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY]) + deferred + end + + sql_change (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY]) + deferred + end + +feature -- Access + + sql_rows_count: INTEGER + -- Number of rows for last sql execution. + deferred + end + + sql_start + -- Set the cursor on first element. + deferred + end + + sql_after: BOOLEAN + -- Are there no more items to iterate over? + deferred + end + + sql_forth + -- Fetch next row from last sql execution, if any. + deferred + end + + sql_item (a_index: INTEGER): detachable ANY + deferred + end + + sql_read_integer_64 (a_index: INTEGER): INTEGER_64 + -- Retrieved value at `a_index' position in `item'. + local + l_item: like sql_item + do + l_item := sql_item (a_index) + if attached {INTEGER_64} l_item as i then + Result := i + elseif attached {INTEGER_64_REF} l_item as l_value then + Result := l_value.item + else + Result := sql_read_integer_32 (a_index).to_integer_64 + end + end + + sql_read_integer_32 (a_index: INTEGER): INTEGER_32 + -- Retrieved value at `a_index' position in `item'. + local + l_item: like sql_item + do + l_item := sql_item (a_index) + if attached {INTEGER_32} l_item as i then + Result := i + elseif attached {INTEGER_32_REF} l_item as l_value then + Result := l_value.item + else +-- check is_integer_32: False end + end + end + + sql_read_string (a_index: INTEGER): detachable STRING + -- Retrieved value at `a_index' position in `item'. + local + l_item: like sql_item + do + l_item := sql_item (a_index) + if attached {READABLE_STRING_8} l_item as l_string then + Result := l_string + elseif attached {BOOLEAN} l_item as l_boolean then + Result := l_boolean.out + elseif attached {BOOLEAN_REF} l_item as l_boolean_ref then + Result := l_boolean_ref.item.out + else +-- check is_string: False end + end + end + + sql_read_string_32 (a_index: INTEGER): detachable STRING_32 + -- Retrieved value at `a_index' position in `item'. + local + l_item: like sql_item + do + -- FIXME: handle string_32 ! + l_item := sql_item (a_index) + if attached {READABLE_STRING_32} l_item as l_string then + Result := l_string + else + if attached sql_read_string (a_index) as s8 then + Result := s8.to_string_32 -- FIXME + end + end + end + + sql_read_date_time (a_index: INTEGER): detachable DATE_TIME + -- Retrieved value at `a_index' position in `item'. + local + l_item: like sql_item + do + l_item := sql_item (a_index) + if attached {DATE_TIME} l_item as dt then + Result := dt + else +-- check is_date_time: False end + end + end + + sql_read_boolean (a_index: INTEGER): detachable BOOLEAN + -- Retrieved value at `a_index' position in `item'. + local + l_item: like sql_item + do + l_item := sql_item (a_index) + if attached {BOOLEAN} l_item as l_boolean then + Result := l_boolean + elseif attached {BOOLEAN_REF} l_item as l_boolean_ref then + Result := l_boolean_ref.item + else + check is_boolean: False end + end + end + +end diff --git a/library/src/persistence/node/cms_node_storage.e b/library/src/persistence/node/cms_node_storage.e new file mode 100644 index 0000000..2a29751 --- /dev/null +++ b/library/src/persistence/node/cms_node_storage.e @@ -0,0 +1,122 @@ +note + description: "Summary description for {CMS_NODE_STORAGE}." + author: "" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_NODE_STORAGE + +inherit + SHARED_LOGGER + +feature -- Error Handling + + error_handler: ERROR_HANDLER + -- Error handler. + deferred + end + +feature -- Access + + nodes_count: INTEGER_64 + -- Count of nodes. + deferred + end + + nodes: LIST [CMS_NODE] + -- List of nodes. + deferred + end + + recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE] + -- List of recent `a_count' nodes with an offset of `lower'. + deferred + end + + node_by_id (a_id: INTEGER_64): detachable CMS_NODE + -- Retrieve node by id `a_id', if any. + require + a_id > 0 + deferred + end + + node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER + -- Node's author. if any. + require + valid_node: a_id >0 + deferred + end + +feature -- Change: Node + + save_node (a_node: CMS_NODE) + -- Create or update `a_node'. + do + if a_node.has_id then + update_node (a_node) + else + new_node (a_node) + end + end + + new_node (a_node: CMS_NODE) + -- Save node `a_node'. + require + no_id: not a_node.has_id + valid_user: attached a_node.author as l_author and then l_author.id > 0 + deferred + end + + delete_node (a_node: CMS_NODE) + -- Delete `a_node'. + do + if a_node.has_id then + delete_node_by_id (a_node.id) + end + end + + delete_node_by_id (a_id: INTEGER_64) + -- Remove node by id `a_id'. + require + valid_node_id: a_id > 0 + deferred + end + + update_node (a_node: CMS_NODE) + -- Update node content `a_node'. + -- The user `a_id' is an existing or new collaborator. + require + has_id: a_node.has_id + has_author: attached a_node.author as l_author and then l_author.has_id + deferred + end + + update_node_title (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32) + -- Update node title to `a_title', node identified by id `a_node_id'. + -- The user `a_user_id' is an existing or new collaborator. + require + valid_node_id: a_node_id > 0 + valid_user_id: a_user_id > 0 + deferred + end + + update_node_summary (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32) + -- Update node summary to `a_summary', node identified by id `a_node_id'. + -- The user `a_user_id' is an existing or new collaborator. + require + valid_id: a_node_id > 0 + valid_user_id: a_user_id > 0 + deferred + end + + update_node_content (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32) + -- Update node content to `a_content', node identified by id `a_node_id'. + -- The user `a_user_id' is an existing or new collaborator. + require + valid_id: a_node_id > 0 + valid_user_id: a_user_id > 0 + deferred + end + +end diff --git a/library/src/persistence/node/cms_node_storage_sql.e b/library/src/persistence/node/cms_node_storage_sql.e new file mode 100644 index 0000000..21c05cf --- /dev/null +++ b/library/src/persistence/node/cms_node_storage_sql.e @@ -0,0 +1,339 @@ +note + description: "Summary description for {CMS_NODE_STORAGE_SQL}." + author: "" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_NODE_STORAGE_SQL + +inherit + CMS_NODE_STORAGE + + CMS_STORAGE_SQL + + REFACTORING_HELPER + + SHARED_LOGGER + +feature -- Access + + nodes_count: INTEGER_64 + -- Number of items nodes. + do + error_handler.reset + log.write_information (generator + ".nodes_count") + sql_query (select_nodes_count, Void) + if sql_rows_count = 1 then + Result := sql_read_integer_64 (1) + end + sql_post_execution + end + + nodes: LIST [CMS_NODE] + -- List of nodes. + do + create {ARRAYED_LIST [CMS_NODE]} Result.make (0) + + error_handler.reset + log.write_information (generator + ".nodes") + + from + sql_query (select_nodes, Void) + sql_post_execution + sql_start + until + sql_after + loop + if attached fetch_node as l_node then + Result.force (l_node) + end + sql_forth + end + sql_post_execution + end + + recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE] + -- List of recent `a_count' nodes with an offset of `lower'. + local + l_parameters: STRING_TABLE [detachable ANY] + do + create {ARRAYED_LIST [CMS_NODE]} Result.make (0) + + error_handler.reset + log.write_information (generator + ".nodes") + + from + create l_parameters.make (2) + l_parameters.put (a_count, "rows") + l_parameters.put (a_lower, "offset") + sql_query (select_recent_nodes, l_parameters) + sql_post_execution + sql_start + until + sql_after + loop + if attached fetch_node as l_node then + Result.force (l_node) + end + sql_forth + end + sql_post_execution + end + + node_by_id (a_id: INTEGER_64): detachable CMS_NODE + -- Retrieve node by id `a_id', if any. + local + l_parameters: STRING_TABLE [ANY] + do + error_handler.reset + log.write_information (generator + ".node") + create l_parameters.make (1) + l_parameters.put (a_id,"id") + sql_query (select_node_by_id, l_parameters) + if sql_rows_count = 1 then + Result := fetch_node + end + sql_post_execution + end + + node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER + -- Node's author for the given node id. + local + l_parameters: STRING_TABLE [ANY] + do + error_handler.reset + log.write_information (generator + ".node_author") + create l_parameters.make (1) + l_parameters.put (a_id, "node_id") + sql_query (select_node_author, l_parameters) + if sql_rows_count >= 1 then + Result := fetch_author + end + sql_post_execution + end + + last_inserted_node_id: INTEGER_64 + -- Last insert node id. + do + error_handler.reset + log.write_information (generator + ".last_inserted_node_id") + sql_query (Sql_last_insert_node_id, Void) + if sql_rows_count = 1 then + Result := sql_read_integer_64 (1) + end + sql_post_execution + end + +feature -- Change: Node + + new_node (a_node: CMS_NODE) + -- Save node `a_node'. + local + l_parameters: STRING_TABLE [detachable ANY] + do + -- New node + error_handler.reset + log.write_information (generator + ".new_node") + create l_parameters.make (7) + l_parameters.put (a_node.title, "title") + l_parameters.put (a_node.summary, "summary") + l_parameters.put (a_node.content, "content") + l_parameters.put (a_node.publication_date, "publish") + l_parameters.put (a_node.creation_date, "created") + l_parameters.put (a_node.modification_date, "changed") + if + attached a_node.author as l_author and then + l_author.id > 0 + then + l_parameters.put (l_author.id, "author") + else + l_parameters.put (0, "author") + end + sql_change (sql_insert_node, l_parameters) + sql_post_execution + if not error_handler.has_error then + a_node.set_id (last_inserted_node_id) + sql_post_execution + end + end + + delete_node_by_id (a_id: INTEGER_64) + -- Remove node by id `a_id'. + local + l_parameters: STRING_TABLE [ANY] + do + log.write_information (generator + ".delete_node") + + error_handler.reset + create l_parameters.make (1) + l_parameters.put (a_id, "id") + sql_change (sql_delete_node, l_parameters) + sql_post_execution + end + + update_node (a_node: CMS_NODE) + -- Update node content `a_node'. + local + l_parameters: STRING_TABLE [detachable ANY] + now: DATE_TIME + do + create now.make_now_utc + error_handler.reset + log.write_information (generator + ".update_node") + create l_parameters.make (7) + l_parameters.put (a_node.title, "title") + l_parameters.put (a_node.summary, "summary") + l_parameters.put (a_node.content, "content") + l_parameters.put (a_node.publication_date, "publish") + l_parameters.put (now, "changed") + l_parameters.put (a_node.id, "id") + if attached a_node.author as l_author then + l_parameters.put (l_author.id, "author") + else + l_parameters.put (0, "author") + end + sql_change (sql_update_node, l_parameters) + sql_post_execution + if not error_handler.has_error then + a_node.set_modification_date (now) + end + end + + update_node_title (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32) + -- + local + l_parameters: STRING_TABLE [detachable ANY] + do + -- FIXME: unused a_user_id ! + error_handler.reset + log.write_information (generator + ".update_node_title") + create l_parameters.make (3) + l_parameters.put (a_title, "title") + l_parameters.put (create {DATE_TIME}.make_now_utc, "changed") + l_parameters.put (a_node_id, "nid") + sql_change (sql_update_node_title, l_parameters) + sql_post_execution + end + + update_node_summary (a_user_id: Like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32) + -- + local + l_parameters: STRING_TABLE [detachable ANY] + do + -- FIXME: unused a_user_id ! + error_handler.reset + log.write_information (generator + ".update_node_summary") + create l_parameters.make (3) + l_parameters.put (a_summary, "summary") + l_parameters.put (create {DATE_TIME}.make_now_utc, "changed") + l_parameters.put (a_node_id, "nid") + sql_change (sql_update_node_summary, l_parameters) + sql_post_execution + end + + update_node_content (a_user_id: Like {CMS_USER}.id;a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32) + -- + local + l_parameters: STRING_TABLE [detachable ANY] + do + -- FIXME: unused a_user_id ! + error_handler.reset + log.write_information (generator + ".update_node_content") + create l_parameters.make (3) + l_parameters.put (a_content, "content") + l_parameters.put (create {DATE_TIME}.make_now_utc, "changed") + l_parameters.put (a_node_id, "nid") + sql_change (sql_update_node_content, l_parameters) + sql_post_execution + end + +feature {NONE} -- Queries + + Select_nodes_count: STRING = "select count(*) from Nodes;" + + Select_nodes: STRING = "select * from Nodes;" + -- SQL Query to retrieve all nodes. + + Select_node_by_id: STRING = "select * from Nodes where nid =:nid order by nid desc, publish desc;" + + Select_recent_nodes: STRING = "select * from Nodes order by nid desc, publish desc LIMIT :rows OFFSET :offset ;" + + SQL_Insert_node: STRING = "insert into nodes (title, summary, content, publish, created, changed, author) values (:title, :summary, :content, :publish, :created, :changed, :author);" + -- SQL Insert to add a new node. + + SQL_Update_node : STRING = "update nodes SET title=:title, summary=:summary, content=:content, publish=:publish, changed=:changed, version = version + 1, author=:author where nid=:nid;" + -- SQL node. + + SQL_Delete_node: STRING = "delete from nodes where nid=:nid;" + + Sql_update_node_author: STRING = "update nodes SET author=:author where nid=:nid;" + + SQL_Update_node_title: STRING ="update nodes SET title=:title, changed=:changed, version = version + 1 where nid=:nid;" + -- SQL update node title. + + SQL_Update_node_summary: STRING ="update nodes SET summary=:summary, changed=:changed, version = version + 1 where nid=:nid;" + -- SQL update node summary. + + SQL_Update_node_content: STRING ="update nodes SET content=:content, changed=:changed, version = version + 1 where nid=:nid;" + -- SQL node content. + + Sql_last_insert_node_id: STRING = "SELECT MAX(nid) from nodes;" + +feature {NONE} -- Sql Queries: USER_ROLES collaborators, author + + Select_user_author: STRING = "SELECT * FROM Nodes INNER JOIN users ON nodes.author=users.uid and users.uid = :uid;" + + Select_node_author: STRING = "SELECT * FROM Users INNER JOIN nodes ON nodes.author=users.uid and nodes.nid =:nid;" + +feature {NONE} -- Implementation + + fetch_node: CMS_NODE + do + create Result.make ("", "", "") + if attached sql_read_integer_64 (1) as l_id then + Result.set_id (l_id) + end + if attached sql_read_string_32 (4) as l_title then + Result.set_title (l_title) + end + if attached sql_read_string_32 (5) as l_summary then + Result.set_summary (l_summary) + end + if attached sql_read_string (6) as l_content then + Result.set_content (l_content) + end + if attached sql_read_date_time (8) as l_publication_date then + Result.set_publication_date (l_publication_date) + end + if attached sql_read_date_time (9) as l_creation_date then + Result.set_creation_date (l_creation_date) + end + if attached sql_read_date_time (10) as l_modif_date then + Result.set_modification_date (l_modif_date) + end + if attached sql_read_integer_64 (7) as l_author_id then + -- access to API ... + end + end + + fetch_author: detachable CMS_USER + do + if attached sql_read_string_32 (2) as l_name and then not l_name.is_whitespace then + create Result.make (l_name) + if attached sql_read_integer_32 (1) as l_id then + Result.set_id (l_id) + end + if attached sql_read_string (3) as l_password then + -- FIXME: should we return the password here ??? + Result.set_hashed_password (l_password) + end + if attached sql_read_string (5) as l_email then + Result.set_email (l_email) + end + else + check expected_valid_user: False end + end + end + +end diff --git a/library/src/persistence/user/cms_user_storage.e b/library/src/persistence/user/cms_user_storage.e new file mode 100644 index 0000000..abbc2f0 --- /dev/null +++ b/library/src/persistence/user/cms_user_storage.e @@ -0,0 +1,139 @@ +note + description: "Summary description for {CMS_USER_STORAGE}." + author: "" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_USER_STORAGE + +inherit + SHARED_LOGGER + +feature -- Error Handling + + error_handler: ERROR_HANDLER + -- Error handler. + deferred + end + +feature -- Access + + has_user: BOOLEAN + -- Has any user? + deferred + end + + users: LIST [CMS_USER] + -- List of users. + deferred + end + + user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER + -- User with id `a_id', if any. + require + a_id > 0 + deferred + ensure + same_id: Result /= Void implies Result.id = a_id + password: Result /= Void implies (Result.hashed_password /= Void and Result.password = Void) + end + + user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER + -- User with name `a_name', if any. + require + a_name /= Void and then not a_name.is_empty + deferred + ensure + same_name: Result /= Void implies a_name ~ Result.name + password: Result /= Void implies (Result.hashed_password /= Void and Result.password = Void) + end + + user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER + -- User with name `a_email', if any. + deferred + ensure + same_email: Result /= Void implies a_email ~ Result.email + password: Result /= Void implies (Result.hashed_password /= Void and Result.password = Void) + end + + is_valid_credential (a_u, a_p: READABLE_STRING_32): BOOLEAN + -- Does account with username `a_username' and password `a_password' exist? + deferred + end + +feature -- Change: user + + save_user (a_user: CMS_USER) + -- Create or update `a_user'. + do + if a_user.has_id then + update_user (a_user) + else + new_user (a_user) + end + end + + new_user (a_user: CMS_USER) + -- New user `a_user'. + require + no_id: not a_user.has_id + deferred + end + + update_user (a_user: CMS_USER) + -- Save user `a_user'. + require + has_id: a_user.has_id + deferred + end + +feature -- Access: roles and permissions + + user_has_permission (u: detachable CMS_USER; s: detachable READABLE_STRING_8): BOOLEAN + -- Anonymous or user `u' has permission for `s' ? + --| `s' could be "create page", + do +-- if s = Void then +-- Result := True +-- elseif u = Void then +---- Result := user_role_has_permission (anonymous_user_role, s) +-- else +-- Result := user_role_has_permission (authenticated_user_role, s) +-- if not Result and attached u.roles as l_roles then +-- across +-- l_roles as r +-- until +-- Result +-- loop +-- if attached user_role_by_id (r.item) as ur then +-- Result := user_role_has_permission (ur, s) +-- end +-- end +-- end +-- end + end + + user_role_has_permission (a_role: CMS_USER_ROLE; s: READABLE_STRING_8): BOOLEAN + do + Result := a_role.has_permission (s) + end + + user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE + -- User role by id `a_id', if any. + deferred + end + + user_roles: LIST [CMS_USER_ROLE] + -- Possible list of user roles. + deferred + end + +feature -- Change: roles and permissions + + save_user_role (a_user_role: CMS_USER_ROLE) + -- Save user role `a_user_role' + deferred + end + +end diff --git a/library/src/persistence/user/cms_user_storage_sql.e b/library/src/persistence/user/cms_user_storage_sql.e new file mode 100644 index 0000000..efa0649 --- /dev/null +++ b/library/src/persistence/user/cms_user_storage_sql.e @@ -0,0 +1,331 @@ +note + description: "Summary description for {CMS_USER_STORAGE_SQL}." + author: "" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" + +deferred class + CMS_USER_STORAGE_SQL + +inherit + CMS_USER_STORAGE + + CMS_STORAGE_SQL + + REFACTORING_HELPER + + SHARED_LOGGER + +feature -- Access: user + + has_user: BOOLEAN + -- Has any user? + do + Result := user_count > 0 + end + + user_count: INTEGER + -- Number of items users. + do + error_handler.reset + log.write_information (generator + ".user_count") + + sql_query (select_users_count, Void) + if sql_rows_count = 1 then + Result := sql_read_integer_32 (1) + end + sql_post_execution + end + + users: LIST [CMS_USER] + do + create {ARRAYED_LIST [CMS_USER]} Result.make (0) + + error_handler.reset + log.write_information (generator + ".all_users") + + from + sql_query (select_users, Void) + sql_post_execution + sql_start + until + sql_after + loop + if attached fetch_user as l_user then + Result.force (l_user) + end + sql_forth + end + sql_post_execution + end + + user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER + -- User for the given id `a_id', if any. + local + l_parameters: STRING_TABLE [detachable ANY] + do + error_handler.reset + log.write_information (generator + ".user") + create l_parameters.make (1) + l_parameters.put (a_id, "uid") + sql_query (select_user_by_id, l_parameters) + if sql_rows_count = 1 then + Result := fetch_user + else + check no_more_than_one: sql_rows_count = 0 end + end + sql_post_execution + end + + user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER + -- User for the given name `a_name', if any. + local + l_parameters: STRING_TABLE [detachable ANY] + do + error_handler.reset + log.write_information (generator + ".user_by_name") + create l_parameters.make (1) + l_parameters.put (a_name, "name") + sql_query (select_user_by_name, l_parameters) + if sql_rows_count = 1 then + Result := fetch_user + else + check no_more_than_one: sql_rows_count = 0 end + end + sql_post_execution + end + + user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER + -- User for the given email `a_email', if any. + local + l_parameters: STRING_TABLE [detachable ANY] + do + error_handler.reset + log.write_information (generator + ".user_by_email") + create l_parameters.make (1) + l_parameters.put (a_email, "email") + sql_query (select_user_by_email, l_parameters) + if sql_rows_count = 1 then + Result := fetch_user + else + check no_more_than_one: sql_rows_count = 0 end + end + sql_post_execution + end + + is_valid_credential (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN + local + l_security: SECURITY_PROVIDER + do + if attached user_salt (l_auth_login) as l_hash then + if attached user_by_name (l_auth_login) as l_user then + create l_security + if + attached l_user.hashed_password as l_hashed_password and then + l_security.password_hash (l_auth_password, l_hash).is_case_insensitive_equal (l_hashed_password) + then + Result := True + else + log.write_information (generator + ".is_valid_credential User: wrong username or password" ) + end + else + log.write_information (generator + ".is_valid_credential User:" + l_auth_login + "does not exist" ) + end + end + + end + +feature -- Change: user + + new_user (a_user: CMS_USER) + -- Add a new user `a_user'. + local + l_parameters: STRING_TABLE [detachable ANY] + l_password_salt, l_password_hash: STRING + l_security: SECURITY_PROVIDER + do + error_handler.reset + if + attached a_user.password as l_password and then + attached a_user.email as l_email + then + sql_begin_transaction + create l_security + l_password_salt := l_security.salt + l_password_hash := l_security.password_hash (l_password, l_password_salt) + + log.write_information (generator + ".new_user") + create l_parameters.make (4) + l_parameters.put (a_user.name, "name") + l_parameters.put (l_password_hash, "password") + l_parameters.put (l_password_salt, "salt") + l_parameters.put (l_email, "email") + l_parameters.put (create {DATE_TIME}.make_now_utc, "created") + + sql_change (sql_insert_user, l_parameters) + sql_post_execution + if not error_handler.has_error then + a_user.set_id (last_inserted_user_id) + sql_post_execution + end + sql_commit_transaction + else + -- set error + error_handler.add_custom_error (-1, "bad request" , "Missing password or email") + end + end + + update_user (a_user: CMS_USER) + -- Save user `a_user'. + local + l_parameters: STRING_TABLE [detachable ANY] + l_password_salt, l_password_hash: detachable READABLE_STRING_8 + l_security: SECURITY_PROVIDER + do + error_handler.reset + if attached a_user.password as l_password then + -- New password! + create l_security + l_password_salt := l_security.salt + l_password_hash := l_security.password_hash (l_password, l_password_salt) + else + -- Existing hashed password + l_password_hash := a_user.hashed_password + l_password_salt := user_salt (a_user.name) + end + if + l_password_hash /= Void and l_password_salt /= Void and + attached a_user.email as l_email + then + log.write_information (generator + ".update_user") + create l_parameters.make (6) + l_parameters.put (a_user.id, "uid") + l_parameters.put (a_user.name, "name") + l_parameters.put (l_password_hash, "password") + l_parameters.put (l_password_salt, "salt") + l_parameters.put (l_email, "email") + l_parameters.put (create {DATE_TIME}.make_now_utc, "changed") + + sql_change (sql_update_user, l_parameters) + sql_post_execution + else + -- set error + error_handler.add_custom_error (-1, "bad request" , "Missing password or email") + end + end + +feature -- Access: roles and permissions + + user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE + do + to_implement (generator + ".user_role_by_id") + end + + user_roles: LIST [CMS_USER_ROLE] + do + to_implement (generator + ".user_roles") + create {ARRAYED_LIST[CMS_USER_ROLE]} Result.make (0) + end + +feature -- Change: roles and permissions + + save_user_role (a_user_role: CMS_USER_ROLE) + do + to_implement (generator + ".save_user_role") + end + +feature {NONE} -- Implementation + + user_salt (a_username: READABLE_STRING_32): detachable READABLE_STRING_8 + -- User salt for the given user `a_username', if any. + local + l_parameters: STRING_TABLE [detachable ANY] + do + error_handler.reset + log.write_information (generator + ".user_salt") + create l_parameters.make (1) + l_parameters.put (a_username, "name") + sql_query (select_salt_by_username, l_parameters) + if sql_rows_count = 1 then + if attached sql_read_string (1) as l_salt then + Result := l_salt + end + end + sql_post_execution + end + + fetch_user: detachable CMS_USER + local + l_id: INTEGER_64 + l_name: detachable READABLE_STRING_32 + do + if attached sql_read_integer_32 (1) as i then + l_id := i + end + if attached sql_read_string_32 (2) as s and then not s.is_whitespace then + l_name := s + end + + if l_name /= Void then + create Result.make (l_name) + if l_id > 0 then + Result.set_id (l_id) + end + elseif l_id > 0 then + create Result.make_with_id (l_id) + end + + if Result /= Void then + if attached sql_read_string (3) as l_password then + -- FIXME: should we return the password here ??? + Result.set_hashed_password (l_password) + end + if attached sql_read_string (5) as l_email then + Result.set_email (l_email) + end + else + check expected_valid_user: False end + end + end + + last_inserted_user_id: INTEGER_64 + -- Last insert user id. + do + error_handler.reset + log.write_information (generator + ".last_inserted_user_id") + sql_query (Sql_last_insert_user_id, Void) + if sql_rows_count = 1 then + Result := sql_read_integer_64 (1) + end + sql_post_execution + end + +feature {NONE} -- Sql Queries: USER + + Select_users_count: STRING = "select count(*) from Users;" + -- Number of users. + + Sql_last_insert_user_id: STRING = "SELECT MAX(uid) from Users;" + + Select_users: STRING = "select * from Users;" + -- List of users. + + Select_user_by_id: STRING = "select * from Users where uid =:uid;" + -- Retrieve user by id if exists. + + Select_user_by_name: STRING = "select * from Users where name =:name;" + -- Retrieve user by name if exists. + + Select_user_by_email: STRING = "select * from Users where email =:email;" + -- Retrieve user by email if exists. + + Select_salt_by_username: STRING = "select salt from Users where name =:name;" + -- Retrieve salt by username if exists. + + Sql_Insert_user: STRING = "insert into users (name, password, salt, email, created) values (:name, :password, :salt, :email, :created);" + -- SQL Insert to add a new node. + + sql_update_user: STRING = "update users SET name=:name, password=:password, salt=:salt, email=:email WHERE uid=:uid;" + + +end diff --git a/library/persistence/implementation/common/security/security_provider.e b/library/src/security/security_provider.e similarity index 90% rename from library/persistence/implementation/common/security/security_provider.e rename to library/src/security/security_provider.e index ae40a8c..5f856b8 100644 --- a/library/persistence/implementation/common/security/security_provider.e +++ b/library/src/security/security_provider.e @@ -1,7 +1,7 @@ note description: "Provides security routine helpers" - date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $" - revision: "$Revision: 95678 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class SECURITY_PROVIDER @@ -34,10 +34,16 @@ feature -- Access Result.keep_head (Result.count - 2) end - password_hash (a_password, a_salt: STRING): STRING + password_hash (a_password: READABLE_STRING_GENERAL; a_salt: STRING): STRING -- Password hash based on password `a_password' and salt value `a_salt'. + local + utf: UTF_CONVERTER + s: STRING do - Result := sha1_string (a_password + a_salt ) + create s.make (a_password.count + a_salt.count) + utf.utf_32_string_into_utf_8_string_8 (a_password, s) + s.append (a_salt) + Result := sha1_string (s) end feature {NONE} -- Implementation diff --git a/library/src/service/cms_api.e b/library/src/service/cms_api.e index 7476eb4..392f12f 100644 --- a/library/src/service/cms_api.e +++ b/library/src/service/cms_api.e @@ -1,15 +1,26 @@ note description: "API for a CMS" - date: "$Date: 2015-01-14 16:13:47 +0100 (mer., 14 janv. 2015) $" - revision: "$Revision: 96454 $" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class CMS_API inherit + ANY REFACTORING_HELPER + SHARED_HTML_ENCODER + export + {NONE} all + end + + SHARED_WSF_PERCENT_ENCODER + export + {NONE} all + end + create make @@ -31,46 +42,13 @@ feature -- Initialize initialize -- Initialize the persitent layer. - local - l_database: DATABASE_CONNECTION - retried: BOOLEAN - l_message: STRING do - if not retried then - to_implement ("Refactor database setup") - if attached (create {APPLICATION_JSON_CONFIGURATION_HELPER}).new_database_configuration (setup.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 {CMS_STORAGE_MYSQL} storage.make (l_database) - else - create {DATABASE_CONNECTION_NULL} l_database.make_common - create {CMS_STORAGE_NULL} storage - end + to_implement ("Refactor database setup") + if attached setup.storage (error_handler) as l_storage then + storage := l_storage else - to_implement ("Workaround code, persistence layer does not implement yet this kind of error handling.") - -- error hanling. - create {DATABASE_CONNECTION_NULL} l_database.make_common create {CMS_STORAGE_NULL} storage - create l_message.make (1024) - if attached ((create {EXCEPTION_MANAGER}).last_exception) as l_exception then - if attached l_exception.description as l_description then - l_message.append (l_description.as_string_32) - l_message.append ("%N%N") - elseif attached l_exception.trace as l_trace then - l_message.append (l_trace) - l_message.append ("%N%N") - else - l_message.append (l_exception.out) - l_message.append ("%N%N") - end - else - l_message.append ("The application crash without available information") - l_message.append ("%N%N") - end - error_handler.add_custom_error (0, " Database Connection ", l_message) end - rescue - retried := True - retry end feature -- Access: Error @@ -110,16 +88,18 @@ feature -- Status Report feature -- Access: Node - nodes: LIST[CMS_NODE] - -- List of nodes. + nodes_count: INTEGER_64 do - debug ("refactor_fixme") - fixme ("Implementation") - end - Result := storage.recent_nodes (0, 10) + Result := storage.nodes_count end - recent_nodes (a_offset, a_rows: INTEGER): LIST[CMS_NODE] + nodes: LIST [CMS_NODE] + -- List of nodes. + do + Result := storage.nodes + end + + recent_nodes (a_offset, a_rows: INTEGER): LIST [CMS_NODE] -- List of the `a_rows' most recent nodes starting from `a_offset'. do Result := storage.recent_nodes (a_offset, a_rows) @@ -131,54 +111,58 @@ feature -- Access: Node debug ("refactor_fixme") fixme ("Check preconditions") end - Result := storage.node (a_id) + Result := storage.node_by_id (a_id) end feature -- Change: Node new_node (a_node: CMS_NODE) -- Add a new node `a_node' + require + no_id: not a_node.has_id do - storage.save_node (a_node) + storage.new_node (a_node) end - delete_node (a_id: INTEGER_64) - -- Delete a node identified by `a_id', if any. + delete_node (a_node: CMS_NODE) + -- Delete `a_node'. do - storage.delete_node (a_id) + if a_node.has_id then + storage.delete_node (a_node) + end end - update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE) - -- Update node by id `a_id' with `a_node' data. + update_node (a_node: CMS_NODE) + -- Update node `a_node' data. do - storage.update_node (a_id,a_node) + storage.update_node (a_node) end - update_node_title (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32) + update_node_title (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32) -- Update node title, with user identified by `a_id', with node id `a_node_id' and a new title `a_title'. do debug ("refactor_fixme") fixme ("Check preconditions") end - storage.update_node_title (a_id,a_node_id,a_title) + storage.update_node_title (a_user_id, a_node_id, a_title) end - update_node_summary (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32) - -- Update node summary, with user identified by `a_id', with node id `a_node_id' and a new summary `a_summary'. + update_node_summary (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32) + -- Update node summary, with user identified by `a_user_id', with node id `a_node_id' and a new summary `a_summary'. do debug ("refactor_fixme") fixme ("Check preconditions") end - storage.update_node_summary (a_id,a_node_id, a_summary) + storage.update_node_summary (a_user_id, a_node_id, a_summary) end - update_node_content (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32) - -- Update node content, with user identified by `a_id', with node id `a_node_id' and a new content `a_content'. + update_node_content (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32) + -- Update node content, with user identified by `a_user_id', with node id `a_node_id' and a new content `a_content'. do debug ("refactor_fixme") fixme ("Check preconditions") end - storage.update_node_content (a_id,a_node_id, a_content) + storage.update_node_content (a_user_id, a_node_id, a_content) end @@ -194,12 +178,15 @@ feature -- Change User new_user (a_user: CMS_USER) -- Add a new user `a_user'. + require + no_id: not a_user.has_id + no_hashed_password: a_user.hashed_password = Void do if attached a_user.password as l_password and then attached a_user.email as l_email then - storage.save_user (a_user) + storage.new_user (a_user) else debug ("refactor_fixme") fixme ("Add error") @@ -207,6 +194,28 @@ feature -- Change User end end + update_user (a_user: CMS_USER) + -- Update user `a_user'. + require + has_id: a_user.has_id + do + storage.update_user (a_user) + end + +feature -- Helpers + + html_encoded (a_string: READABLE_STRING_GENERAL): STRING_8 + -- `a_string' encoded for html output. + do + Result := html_encoder.general_encoded_string (a_string) + end + + percent_encoded (a_string: READABLE_STRING_GENERAL): STRING_8 + -- `a_string' encoded with percent encoding, mainly used for url. + do + Result := percent_encoder.percent_encoded_string (a_string) + end + feature -- Layout module_configuration (a_module_name: READABLE_STRING_GENERAL; a_name: detachable READABLE_STRING_GENERAL): detachable CONFIG_READER diff --git a/library/src/service/response/not_implemented_error_cms_response.e b/library/src/service/response/not_implemented_error_cms_response.e index b2c9e81..159b9b4 100644 --- a/library/src/service/response/not_implemented_error_cms_response.e +++ b/library/src/service/response/not_implemented_error_cms_response.e @@ -1,7 +1,7 @@ note description: "Summary description for {NOT_IMPLEMENTED_ERROR_CMS_RESPONSE}." - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" + revision: "$Revision: 96542 $" class NOT_IMPLEMENTED_ERROR_CMS_RESPONSE @@ -32,7 +32,9 @@ feature -- Execution do set_title ("Not Implemented") set_page_title (Void) - set_main_content (request.percent_encoded_path_info + " is not implemented!") + if main_content = Void then + set_main_content (request.percent_encoded_path_info + " is not implemented!") + end end end