Initial Import Model Library

This commit is contained in:
jvelilla
2014-10-15 19:41:47 -03:00
parent 8a06dc11ac
commit 3c73202a0d
13 changed files with 312 additions and 1 deletions

19
model/model-safe.ecf Normal file
View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="model" uuid="57C6F407-E894-4554-8A59-C8D1F3BBC5D7" library_target="model">
<target name="model">
<root all_classes="True"/>
<option warning="true">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="console_application" value="true"/>
<library name="base" location="$ISE_LIBRARY/library/base/base-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<cluster name="model" location=".\src" recursive="true">
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
<exclude>/CVS$</exclude>
</file_rule>
</cluster>
</target>
</system>

View File

@@ -0,0 +1,10 @@
note
description: "Summary description for {CMS_CONTENT_TYPE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CMS_CONTENT_TYPE
end

71
model/src/cms_link.e Normal file
View File

@@ -0,0 +1,71 @@
note
description: "Summary description for {CMS_MENU}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_LINK
inherit
REFACTORING_HELPER
DEBUG_OUTPUT
ITERABLE [CMS_LINK]
feature -- Access
title: READABLE_STRING_32
-- link's title.
location: READABLE_STRING_8
-- link's location.
feature -- status report
is_active: BOOLEAN
deferred
end
is_expanded: BOOLEAN
deferred
end
is_expandable: BOOLEAN
deferred
end
has_children: BOOLEAN
deferred
end
feature -- Query
parent: detachable CMS_LINK
children: detachable LIST [CMS_LINK]
deferred
end
feature -- Access
new_cursor: ITERATION_CURSOR [CMS_LINK]
-- Fresh cursor associated with current structure
do
if attached children as lst then
Result := lst.new_cursor
else
Result := (create {ARRAYED_LIST [CMS_LINK]}.make (0)).new_cursor
end
end
feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := title.as_string_8 + " -> " + location
end
end

View File

@@ -0,0 +1,27 @@
note
description: "Summary description for {CMS_LINK_COMPOSITE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
CMS_LINK_COMPOSITE
inherit
ITERABLE [CMS_LINK]
feature -- Access
items: detachable LIST [CMS_LINK]
deferred
end
extend (lnk: CMS_LINK)
deferred
end
remove (lnk: CMS_LINK)
deferred
end
end

109
model/src/cms_local_link.e Normal file
View File

@@ -0,0 +1,109 @@
note
description: "Summary description for {CMS_LOCAL_MENU}."
date: "$Date$"
revision: "$Revision$"
class
CMS_LOCAL_LINK
inherit
CMS_LINK
CMS_LINK_COMPOSITE
rename
items as children,
extend as add_link,
remove as remove_link
end
create
make
feature {NONE} -- Initialization
make (a_title: detachable like title; a_location: like location)
do
if a_title /= Void then
title := a_title
else
title := a_location
end
location := a_location
end
feature -- Status report
is_active: BOOLEAN
is_expanded: BOOLEAN
do
Result := is_expandable and then internal_is_expanded
end
is_expandable: BOOLEAN
do
Result := internal_is_expandable or internal_is_expanded or has_children
end
has_children: BOOLEAN
do
Result := attached children as l_children and then not l_children.is_empty
end
permission_arguments: detachable ITERABLE [READABLE_STRING_8]
children: detachable LIST [CMS_LINK]
internal_is_expandable: BOOLEAN
internal_is_expanded: BOOLEAN
feature -- Element change
add_link (lnk: CMS_LINK)
local
lst: like children
do
lst := children
if lst = Void then
create {ARRAYED_LIST [CMS_LINK]} lst.make (1)
children := lst
end
lst.force (lnk)
end
remove_link (lnk: CMS_LINK)
local
lst: like children
do
lst := children
if lst /= Void then
lst.prune_all (lnk)
if lst.is_empty then
children := Void
end
end
end
set_children (lst: like children)
do
children := lst
end
set_expanded (b: like is_expanded)
do
internal_is_expanded := b
end
set_expandable (b: like is_expandable)
do
internal_is_expandable := b
end
set_permission_arguments (args: like permission_arguments)
do
permission_arguments := args
end
end

72
model/src/cms_menu.e Normal file
View File

@@ -0,0 +1,72 @@
note
description: "Summary description for {CMS_MENU}."
date: "$Date$"
revision: "$Revision$"
class
CMS_MENU
inherit
CMS_LINK_COMPOSITE
create
make,
make_with_title
feature {NONE} -- Initialization
make (a_name: like name; n: INTEGER)
do
name := a_name
create items.make (n)
end
make_with_title (a_name: like name; a_title: READABLE_STRING_32; n: INTEGER)
do
make (a_name, n)
set_title (a_title)
end
feature -- Access
name: READABLE_STRING_8
title: detachable READABLE_STRING_32
items: ARRAYED_LIST [CMS_LINK]
extend (lnk: CMS_LINK)
do
items.extend (lnk)
end
remove (lnk: CMS_LINK)
do
items.prune_all (lnk)
end
feature -- status report
is_empty: BOOLEAN
do
Result := items.is_empty
end
feature -- Element change
set_title (t: like title)
do
title := t
end
feature -- Access
new_cursor: ITERATION_CURSOR [CMS_LINK]
-- Fresh cursor associated with current structure
do
Result := items.new_cursor
end
invariant
end

181
model/src/cms_node.e Normal file
View File

@@ -0,0 +1,181 @@
note
description: "Summary description for {NODE}."
date: "$Date$"
revision: "$Revision$"
class
CMS_NODE
inherit
REFACTORING_HELPER
create
make
feature{NONE} -- Initialization
make (a_content: READABLE_STRING_32; a_summary:READABLE_STRING_32; a_title: READABLE_STRING_32)
local
l_time: DATE_TIME
do
create l_time.make_now_utc
set_content (a_content)
set_summary (a_summary)
set_title (a_title)
set_creation_date (l_time)
set_modification_date (l_time)
set_publication_date (l_time)
fixme ("Remove harcode format")
set_format ("HTML")
fixme ("Remove harcode content type")
set_content_type ("Page")
ensure
content_set: content = a_content
summary_set: summary = a_summary
title_set: title = a_title
end
feature -- Access
content: READABLE_STRING_32
-- Content of the node.
summary: READABLE_STRING_32
-- A short summary of the node.
title: READABLE_STRING_32
-- Full title of the node.
modification_date: DATE_TIME
-- When the node was updated.
creation_date: DATE_TIME
-- When the node was created.
publication_date: DATE_TIME
-- When the node was published.
publication_date_output: READABLE_STRING_32
-- Formatted output.
id: INTEGER_64 assign set_id
-- Unique id.
format: READABLE_STRING_32
-- Format associated with `body'.
-- For example: text, mediawiki, html, etc
content_type: READABLE_STRING_32
-- Associated content type name.
-- Page, Article, Blog, News, etc.
feature -- status report
has_id: BOOLEAN
do
Result := id > 0
end
author: detachable CMS_USER
-- Node's author.
collaborators: detachable LIST[CMS_USER]
-- Node's collaborators.
feature -- Element change
set_content (a_content: like content)
-- Assign `content' with `a_content'.
do
content := a_content
ensure
content_assigned: content = a_content
end
set_summary (a_summary: like summary)
-- Assign `summary' with `a_summary'.
do
summary := a_summary
ensure
summary_assigned: summary = a_summary
end
set_title (a_title: like title)
-- Assign `title' with `a_title'.
do
title := a_title
ensure
title_assigned: title = a_title
end
set_modification_date (a_modification_date: like modification_date)
-- Assign `modification_date' with `a_modification_date'.
do
modification_date := a_modification_date
ensure
modification_date_assigned: modification_date = a_modification_date
end
set_creation_date (a_creation_date: like creation_date)
-- Assign `creation_date' with `a_creation_date'.
do
creation_date := a_creation_date
ensure
creation_date_assigned: creation_date = a_creation_date
end
set_publication_date (a_publication_date: like publication_date)
-- Assign `publication_date' with `a_publication_date'.
do
publication_date := a_publication_date
publication_date_output := publication_date.formatted_out ("yyyy/[0]mm/[0]dd")
ensure
publication_date_assigned: publication_date = a_publication_date
end
set_content_type (a_content_type: like content_type)
-- Assign `content_type' with `a_content_type'.
do
content_type := a_content_type
ensure
content_type_assigned: content_type = a_content_type
end
set_format (a_format: like format)
-- Assign `format' with `a_format'.
do
format := a_format
ensure
format_assigned: format = a_format
end
set_id (an_id: like id)
-- Assign `id' with `an_id'.
do
id := an_id
ensure
id_assigned: id = an_id
end
set_author (u: like author)
-- Assign 'author' with `u'
do
author := u
ensure
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
end

166
model/src/cms_user.e Normal file
View File

@@ -0,0 +1,166 @@
note
description: "Summary description for {USER}."
date: "$Date$"
revision: "$Revision$"
class
CMS_USER
inherit
DEBUG_OUTPUT
create
make
feature {NONE} -- Initialization
make (a_name: READABLE_STRING_32)
-- Create an object with name `a_name'.
do
name := a_name
create creation_date.make_now_utc
ensure
name_set: name = a_name
end
feature -- Access
id: INTEGER_64
-- Unique id.
name: READABLE_STRING_32
-- User name.
password: detachable READABLE_STRING_32
-- User password.
email: detachable READABLE_STRING_32
-- User email.
profile: detachable CMS_USER_PROFILE
-- User profile.
creation_date: DATE_TIME
-- Creation date.
last_login_date: detachable DATE_TIME
-- User last login.
data: detachable STRING_TABLE [detachable ANY]
-- Additional user's data.
data_item (k: READABLE_STRING_GENERAL): detachable ANY
-- Additional item data.
do
if attached data as l_data then
Result := l_data.item (k)
end
end
feature -- Status report
has_id: BOOLEAN
do
Result := id > 0
end
has_email: BOOLEAN
do
Result := attached email as e and then not e.is_empty
end
debug_output: STRING
do
Result := name
end
same_as (u: detachable CMS_USER): BOOLEAN
do
Result := u /= Void and then id = u.id
end
feature -- Change element
set_id (a_id: like id)
-- Set `id' with `a_id'.
do
id := a_id
ensure
id_set: id = a_id
end
set_name (n: like name)
-- Set `name' with `n'.
do
name := n
ensure
name_set: name = n
end
set_password (p: like password)
-- Set `password' with `p'.
do
password := p
ensure
password_set: password = p
end
set_email (m: like email)
-- Set `email' with `m'.
do
email := m
ensure
email_set: email = m
end
set_profile (prof: like profile)
-- Set `profile' with `prof'.
do
profile := prof
ensure
profile_set: profile = prof
end
set_data_item (k: READABLE_STRING_GENERAL; d: like data_item)
local
l_data: like data
do
l_data := data
if l_data = Void then
create l_data.make (1)
data := l_data
end
l_data.force (d, k)
end
remove_data_item (k: READABLE_STRING_GENERAL)
do
if attached data as l_data then
l_data.remove (k)
end
end
set_profile_item (k: READABLE_STRING_8; v: READABLE_STRING_8)
local
prof: like profile
do
prof := profile
if prof = Void then
create prof.make
profile := prof
end
prof.force (v, k)
end
set_last_login_date (dt: like last_login_date)
do
last_login_date := dt
end
set_last_login_date_now
do
set_last_login_date (create {DATE_TIME}.make_now_utc)
end
end

View File

@@ -0,0 +1,48 @@
note
description: "Summary description for {CMS_USER_PROFILE}."
date: "$Date$"
revision: "$Revision$"
class
CMS_USER_PROFILE
inherit
TABLE_ITERABLE [READABLE_STRING_8, READABLE_STRING_8]
create
make
feature {NONE} -- Initialization
make
do
create items.make (0)
end
feature -- Access
item (k: READABLE_STRING_8): detachable READABLE_STRING_8
do
Result := items.item (k.as_string_8)
end
feature -- Change
force (v: READABLE_STRING_8; k: READABLE_STRING_8)
do
items.force (v, k.as_string_8)
end
feature -- Access
new_cursor: TABLE_ITERATION_CURSOR [READABLE_STRING_8, READABLE_STRING_8]
-- Fresh cursor associated with current structure
do
Result := items.new_cursor
end
feature {NONE} -- Implementation
items: HASH_TABLE [READABLE_STRING_8, STRING_8]
end

90
model/src/cms_user_role.e Normal file
View File

@@ -0,0 +1,90 @@
note
description: "Summary description for {CMS_USER_ROLE}."
date: "$Date$"
revision: "$Revision$"
class
CMS_USER_ROLE
inherit
ANY
redefine
is_equal
end
create
make,
make_with_id
feature {NONE} -- Initialization
make_with_id (a_id: like id; a_name: like name)
do
id := a_id
make (a_name)
end
make (a_name: like name)
do
name := a_name
create {ARRAYED_LIST [READABLE_STRING_8]} permissions.make (0)
end
feature -- Status report
has_id: BOOLEAN
do
Result := id > 0
end
has_permission (p: READABLE_STRING_8): BOOLEAN
do
Result := across permissions as c some c.item.is_case_insensitive_equal (p) end
end
feature -- Access
id: INTEGER
name: READABLE_STRING_8
permissions: LIST [READABLE_STRING_8]
feature -- Comparison
same_user_role (r: CMS_USER_ROLE): BOOLEAN
do
Result := r.id = id
end
is_equal (other: like Current): BOOLEAN
-- Is `other' attached to an object considered
-- equal to current object?
do
Result := id = other.id
end
feature -- Change
set_id (a_id: like id)
-- Set `id' with `a_id'.
do
id := a_id
ensure
set_id: id = a_id
end
set_name (a_name: like name)
-- Set `name' with `a_name'.
do
name := a_name
ensure
name_set: name = a_name
end
add_permission (n: READABLE_STRING_8)
do
permissions.force (n)
end
end