lorj 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +46 -0
- data/Gemfile +15 -15
- data/README.md +22 -17
- data/Rakefile +12 -2
- data/bin/cloud_test.rb +13 -65
- data/example/students_1/process/students.rb +39 -0
- data/example/students_1/students.rb +22 -5
- data/example/students_2/process/students.rb +48 -0
- data/example/students_2/students.rb +39 -16
- data/example/students_3/controller/yaml_students.rb +50 -43
- data/example/students_3/controller/yaml_students_controller.rb +100 -87
- data/example/students_3/process/students.rb +161 -97
- data/example/students_3/students.rb +85 -56
- data/example/yaml_students/students.rb +40 -40
- data/example/yaml_students/yaml_students.rb +103 -90
- data/lib/core/core.rb +356 -696
- data/lib/core/core_controller.rb +227 -0
- data/lib/core/core_internal.rb +339 -0
- data/lib/core/core_model.rb +328 -0
- data/lib/core/core_object_data.rb +330 -0
- data/lib/core/core_object_params.rb +230 -0
- data/lib/core/core_process.rb +391 -0
- data/lib/core/core_process_setup.rb +353 -0
- data/lib/core/core_setup_ask.rb +241 -0
- data/lib/core/core_setup_encrypt.rb +146 -0
- data/lib/core/core_setup_init.rb +229 -0
- data/lib/core/core_setup_list.rb +160 -0
- data/lib/core/definition.rb +647 -469
- data/lib/core/definition_internal.rb +264 -308
- data/lib/core/lorj_basecontroller.rb +95 -0
- data/lib/core/lorj_basedefinition.rb +307 -0
- data/lib/core/lorj_baseprocess.rb +265 -0
- data/lib/core/lorj_data.rb +583 -0
- data/lib/core/lorj_keypath.rb +119 -0
- data/lib/core_process/cloud/process/common.rb +63 -0
- data/lib/core_process/cloud/process/connection.rb +93 -0
- data/lib/core_process/cloud/process/external_network.rb +94 -0
- data/lib/core_process/cloud/process/flavor.rb +99 -0
- data/lib/core_process/cloud/process/images.rb +87 -0
- data/lib/core_process/cloud/process/internet_network.rb +34 -0
- data/lib/core_process/cloud/process/internet_server.rb +30 -0
- data/lib/core_process/cloud/process/keypairs.rb +276 -0
- data/lib/core_process/cloud/process/network.rb +108 -0
- data/lib/core_process/cloud/process/public_ip.rb +100 -0
- data/lib/core_process/cloud/process/router.rb +260 -0
- data/lib/core_process/cloud/process/rules.rb +120 -0
- data/lib/core_process/cloud/process/security_groups.rb +121 -0
- data/lib/core_process/cloud/process/server.rb +127 -0
- data/lib/core_process/cloud/process/server_log.rb +35 -0
- data/lib/core_process/cloud/process/subnetwork.rb +108 -0
- data/lib/core_process/cloud_process.rb +30 -0
- data/lib/logging.rb +298 -0
- data/lib/lorj/version.rb +18 -1
- data/lib/lorj.rb +58 -18
- data/lib/lorj_account.rb +556 -0
- data/lib/lorj_config.rb +468 -0
- data/lib/lorj_defaults.rb +278 -0
- data/lib/prc.rb +136 -104
- data/lib/prc_base_config.rb +285 -0
- data/lib/prc_core_config.rb +878 -0
- data/lib/prc_section_config.rb +57 -0
- data/lib/providers/hpcloud/compute.rb +81 -93
- data/lib/providers/hpcloud/hpcloud.rb +462 -0
- data/lib/providers/hpcloud/network.rb +96 -98
- data/lib/providers/hpcloud/security_groups.rb +41 -40
- data/lib/providers/mock/mock.rb +144 -0
- data/lib/providers/openstack/openstack.rb +45 -0
- data/lib/providers/templates/compute.rb +21 -23
- data/lib/providers/templates/mycloud.rb +72 -0
- data/lib/providers/templates/network.rb +11 -12
- data/lib/rh.rb +339 -0
- data/lorj-spec/defaults.yaml +4 -0
- data/lorj.gemspec +6 -0
- data/spec/00_lorj_log_spec.rb +53 -0
- data/spec/01_hash_rh_spec.rb +243 -0
- data/spec/02_prc_base_config_spec.rb +216 -0
- data/spec/04_prc_core_config_spec.rb +83 -0
- data/spec/11_lorj_config_spec.rb +263 -0
- data/spec/12_lorj_account_spec.rb +181 -0
- metadata +76 -28
- data/Gemfile.lock +0 -37
- data/example/students_1/process/Students.rb +0 -20
- data/example/students_2/process/Students.rb +0 -27
- data/example/students_4/controller/yaml_students.rb +0 -82
- data/example/students_4/controller/yaml_students_controller.rb +0 -141
- data/example/students_4/process/students.rb +0 -112
- data/example/students_4/students.rb +0 -103
- data/lib/core/lorj-basecontroller.rb +0 -90
- data/lib/core/lorj-basedefinition.rb +0 -1139
- data/lib/core/lorj-baseprocess.rb +0 -236
- data/lib/core/lorj-data.rb +0 -567
- data/lib/core/lorj-keypath.rb +0 -115
- data/lib/core_process/CloudProcess.rb +0 -337
- data/lib/core_process/global_process.rb +0 -502
- data/lib/core_process/network_process.rb +0 -605
- data/lib/prc-account.rb +0 -339
- data/lib/prc-config.rb +0 -1030
- data/lib/prc-logging.rb +0 -261
- data/lib/providers/hpcloud/Hpcloud.rb +0 -426
- data/lib/providers/mock/Mock.rb +0 -141
- data/lib/providers/openstack/Openstack.rb +0 -47
- data/lib/providers/templates/core.rb +0 -61
- data/spec/forj-account_spec.rb +0 -75
- data/spec/forj-config_spec.rb +0 -196
|
@@ -14,81 +14,88 @@
|
|
|
14
14
|
# See the License for the specific language governing permissions and
|
|
15
15
|
# limitations under the License.
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
# This class describes how to process some actions, and will do everything prior
|
|
19
18
|
# this task to make it to work.
|
|
20
19
|
|
|
21
|
-
|
|
22
20
|
# declare yaml student API to the controller
|
|
23
21
|
cur_path = File.dirname(__FILE__)
|
|
24
|
-
api_file = File.expand_path(File.join(cur_path,
|
|
22
|
+
api_file = File.expand_path(File.join(cur_path, '..', '..',
|
|
23
|
+
'yaml_students', 'yaml_students.rb'))
|
|
25
24
|
require api_file
|
|
26
25
|
|
|
27
26
|
# The controller is a combination of 2 elements:
|
|
28
27
|
# - Controller class
|
|
29
28
|
# Code which will interfere with the external API.
|
|
30
29
|
#
|
|
31
|
-
# The file name must respect the name of the class. 1st letter already
|
|
30
|
+
# The file name must respect the name of the class. 1st letter already
|
|
31
|
+
# capitalized and letter after _ is capitalized.
|
|
32
32
|
# file: my_code.rb => needs to create MyCodeController class
|
|
33
33
|
#
|
|
34
34
|
# - Definition class
|
|
35
35
|
# This class declare any kind of mapping or additional fields to consider.
|
|
36
|
-
# Additionnal fields are unknow by the process. So, those fields will needs
|
|
36
|
+
# Additionnal fields are unknow by the process. So, those fields will needs
|
|
37
|
+
# to be setup before.
|
|
37
38
|
#
|
|
38
39
|
# file name convention is identical than controller class.
|
|
39
40
|
# file: my_code.rb => needs to create MyCode class
|
|
40
41
|
|
|
41
|
-
controller_file = File.expand_path(File.join(cur_path,
|
|
42
|
+
controller_file = File.expand_path(File.join(cur_path,
|
|
43
|
+
'yaml_students_controller.rb'))
|
|
42
44
|
require controller_file # Load controller mapping
|
|
43
45
|
|
|
44
46
|
# Declare
|
|
45
|
-
# - additional objects and their specific process (:connection using basic
|
|
47
|
+
# - additional objects and their specific process (:connection using basic
|
|
48
|
+
# predefined :controller_create process)
|
|
46
49
|
# - data_mapping :
|
|
47
50
|
# :connection_string => :file_name
|
|
48
51
|
# :course => :training
|
|
49
52
|
#
|
|
50
|
-
# If some data has been added by the controller, the main and process,
|
|
53
|
+
# If some data has been added by the controller, the main and process,
|
|
54
|
+
# won't take care and the framework will fails.
|
|
51
55
|
# To eliminate this errors, there is 2 cases:
|
|
52
56
|
# - detect this change in the process or the main.
|
|
53
|
-
# - set it up, using lorj setup function, if the data is declared askable by
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
-
|
|
57
|
+
# - set it up, using lorj setup function, if the data is declared askable by
|
|
58
|
+
# the controller.
|
|
59
|
+
# The controller can define how the setup have to ask values, and even can get
|
|
60
|
+
# data from itself.
|
|
57
61
|
class YamlStudents
|
|
62
|
+
# This is a new object which is known by the controller only.
|
|
63
|
+
# Used to open the yaml file. Generically, I named it :connection.
|
|
64
|
+
# But this can be any name you want. Only the controller will deal with it.
|
|
65
|
+
define_obj(:connection,
|
|
66
|
+
# Nothing complex to do. So, simply call the controller create.
|
|
67
|
+
:create_e => :controller_create
|
|
68
|
+
)
|
|
58
69
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
define_obj(:connection,{
|
|
63
|
-
:create_e => :controller_create # Nothing complex to do. So, simply call the controller create.
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
obj_needs :data, :connection_string, :mapping => :file_name
|
|
67
|
-
undefine_attribute :id # Do not return any predefined ID
|
|
68
|
-
undefine_attribute :name # Do not return any predefined NAME
|
|
70
|
+
obj_needs :data, :connection_string, :mapping => :file_name
|
|
71
|
+
undefine_attribute :id # Do not return any predefined ID
|
|
72
|
+
undefine_attribute :name # Do not return any predefined NAME
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
# The student model have to be expanded.
|
|
75
|
+
define_obj(:student)
|
|
76
|
+
# It requires to create a connection to the data, ie opening the yaml file.
|
|
77
|
+
# So, before working with the :student object, the controller requires a
|
|
78
|
+
# connection
|
|
79
|
+
# This connection will be loaded in the memory and provided to the controller
|
|
80
|
+
# when needed.
|
|
81
|
+
# obj_needs :CloudObject update the :student object to requires a connection
|
|
82
|
+
# before.
|
|
83
|
+
obj_needs :CloudObject, :connection
|
|
78
84
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
# To simplify controller wrapper, we use hdata built by lorj, and passed to
|
|
86
|
+
# the API
|
|
87
|
+
# This hdata is a hash containing mapped data, thanks to def_hdata.
|
|
88
|
+
def_hdata :first_name
|
|
89
|
+
def_hdata :last_name
|
|
90
|
+
# Instead of 'course', the yaml API uses 'training'
|
|
91
|
+
def_hdata :course, :mapping => :training
|
|
85
92
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
def_attr_mapping :course, :training
|
|
94
|
+
# instead of 'student_name', the yaml API uses 'name'
|
|
95
|
+
def_attr_mapping :student_name, :name
|
|
89
96
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
# This controller will know how to manage a student file with those data.
|
|
98
|
+
# But note that the file can have a lot of more data than what the process
|
|
99
|
+
# usually manage. It is up to you to increase your process to manage more data
|
|
100
|
+
# Then each controller may need to define mapping fields.
|
|
94
101
|
end
|
|
@@ -14,110 +14,123 @@
|
|
|
14
14
|
# See the License for the specific language governing permissions and
|
|
15
15
|
# limitations under the License.
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
# This class describes how to process some actions, and will do everything prior
|
|
19
18
|
# this task to make it to work.
|
|
20
19
|
|
|
21
20
|
# This Mock controller keep the data in memory in hash/Array data.
|
|
22
21
|
|
|
23
22
|
# declare yaml student API to the controller
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
yaml_students_file = File.expand_path(
|
|
24
|
+
File.join(
|
|
25
|
+
File.dirname(__FILE__),
|
|
26
|
+
'..', '..', 'yaml_students', 'yaml_students.rb'))
|
|
27
|
+
require yaml_students_file
|
|
26
28
|
|
|
27
29
|
# The controller is a combination of 2 elements:
|
|
28
30
|
# - Controller class
|
|
29
31
|
# Code which will interfere with the external API.
|
|
30
32
|
#
|
|
31
|
-
# The file name must respect the name of the class. 1st letter already
|
|
33
|
+
# The file name must respect the name of the class. 1st letter already
|
|
34
|
+
# capitalized and letter after _ is capitalized.
|
|
32
35
|
# file: my_code.rb => needs to create MyCodeController class
|
|
33
36
|
#
|
|
34
37
|
# - Definition class
|
|
35
38
|
# This class declare any kind of mapping or additional fields to consider.
|
|
36
|
-
# Additionnal fields are unknow by the process. So, those fields will needs
|
|
39
|
+
# Additionnal fields are unknow by the process. So, those fields will needs
|
|
40
|
+
# to be setup before.
|
|
37
41
|
#
|
|
38
42
|
# file name convention is identical than controller class.
|
|
39
43
|
# file: my_code.rb => needs to create MyCode class
|
|
40
|
-
|
|
41
44
|
class YamlStudentsController
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
45
|
+
# controller wrapper
|
|
46
|
+
# rubocop: disable Metrics/MethodLength
|
|
47
|
+
def create(sObjectType, hParams)
|
|
48
|
+
case sObjectType
|
|
49
|
+
when :connection
|
|
50
|
+
required?(hParams, :hdata, :file_name)
|
|
51
|
+
YamlSchool.new(hParams[:hdata, :file_name])
|
|
52
|
+
when :student
|
|
53
|
+
required?(hParams, :connection)
|
|
54
|
+
required?(hParams, :student_name)
|
|
55
|
+
|
|
56
|
+
hParams[:connection].create_student(hParams[:student_name],
|
|
57
|
+
hParams[:hdata])
|
|
58
|
+
else
|
|
59
|
+
Error format("'%s' is not a valid object for 'create'", sObjectType)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
# rubocop: enable Metrics/MethodLength
|
|
63
|
+
|
|
64
|
+
# This function return a collection which have to provide:
|
|
65
|
+
# functions: [], length, each
|
|
66
|
+
# Used by network process.
|
|
67
|
+
def query(sObjectType, sQuery, hParams)
|
|
68
|
+
case sObjectType
|
|
69
|
+
when :student
|
|
70
|
+
required?(hParams, :connection)
|
|
71
|
+
|
|
72
|
+
hParams[:connection].query_student(sQuery)
|
|
73
|
+
else
|
|
74
|
+
Error format("'%s' is not a valid object for 'create'", sObjectType)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def delete(sObjectType, hParams)
|
|
79
|
+
case sObjectType
|
|
80
|
+
when :student
|
|
81
|
+
required?(hParams, :connection)
|
|
82
|
+
|
|
83
|
+
hParams[:connection].delete_student(hParams[sObjectType][:id])
|
|
84
|
+
else
|
|
85
|
+
Error format("'%s' is not a valid object for 'create'", sObjectType)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def get_attr(oControlerObject, key)
|
|
90
|
+
# This controller function read the data and
|
|
91
|
+
# extract the information requested by the framework.
|
|
92
|
+
# Those data will be mapped to the process data model.
|
|
93
|
+
# The key is an array, to get data from a level tree.
|
|
94
|
+
# [data_l1, data_l2, data_l3] => should retrieve data from structure like
|
|
95
|
+
# data[ data_l2[ data_l3 ] ]
|
|
96
|
+
attributes = oControlerObject
|
|
97
|
+
|
|
98
|
+
fail format("get_attr: attribute '%s' is unknown in '%s'. "\
|
|
99
|
+
"Valid one are : '%s'",
|
|
100
|
+
key[0],
|
|
101
|
+
oControlerObject.class,
|
|
102
|
+
valid_attributes) unless valid_attributes.include?(key[0])
|
|
103
|
+
attributes.rh_get(key)
|
|
104
|
+
rescue => e
|
|
105
|
+
Error format("get_attr: Unable to map '%s'. %s", key, e.message)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def set_attr(oControlerObject, key, value)
|
|
109
|
+
attributes = oControlerObject
|
|
110
|
+
fail format("set_attr: attribute '%s' is unknown in '%s'. "\
|
|
111
|
+
"Valid one are : '%s'",
|
|
112
|
+
key[0],
|
|
113
|
+
oControlerObject.class,
|
|
114
|
+
valid_attributes) unless valid_attributes.include?(key[0])
|
|
115
|
+
attributes.rh_set(value, key)
|
|
116
|
+
rescue
|
|
117
|
+
Error format("set_attr: Unable to map '%s' on '%s'", key, sObjectType)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def update(sObjectType, oObject, hParams)
|
|
121
|
+
case sObjectType
|
|
122
|
+
when :student
|
|
123
|
+
required?(hParams, :connection)
|
|
124
|
+
|
|
125
|
+
hParams[:connection].update_student(oObject)
|
|
126
|
+
else
|
|
127
|
+
Error format("'%s' is not a valid object for 'create'", sObjectType)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
private
|
|
132
|
+
|
|
133
|
+
def valid_attributes
|
|
134
|
+
[:name, :first_name, :last_name, :id, :status, :training]
|
|
135
|
+
end
|
|
123
136
|
end
|
|
@@ -16,103 +16,167 @@
|
|
|
16
16
|
|
|
17
17
|
# Students process - Define specific handlers
|
|
18
18
|
class StudentsProcess
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
19
|
+
# create_student process handler to get a student.
|
|
20
|
+
#
|
|
21
|
+
# * If not found, create it.
|
|
22
|
+
# * If multiple found, remove duplicates
|
|
23
|
+
# * otherwise return the one found.
|
|
24
|
+
# rubocop:disable Metrics/MethodLength
|
|
25
|
+
def create_student(sObjectType, hParams)
|
|
26
|
+
PrcLib.state(format("Running creation process for object '%s' = '%s'",
|
|
27
|
+
sObjectType, hParams[:student_name]))
|
|
28
|
+
|
|
29
|
+
list = process_query(sObjectType, :student_name => hParams[:student_name])
|
|
30
|
+
case list.length
|
|
31
|
+
when 0
|
|
32
|
+
create_new_student(hParams[:student_name])
|
|
33
|
+
when 1
|
|
34
|
+
found_one_student(list[0], hParams[:student_name])
|
|
35
|
+
else
|
|
36
|
+
found_multiple_students(list, hParams[:student_name])
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
# rubocop:enable Metrics/MethodLength
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
# Create a single new student
|
|
44
|
+
def create_new_student(student_name)
|
|
45
|
+
object = controller_create(:student)
|
|
46
|
+
fail format("Student '%s' not created.", student_name) if object.nil?
|
|
47
|
+
|
|
48
|
+
PrcLib.info(format("'student': '%s' created with id %s",
|
|
49
|
+
student_name,
|
|
50
|
+
object[:id]))
|
|
51
|
+
object
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Identified 1 student
|
|
55
|
+
def found_one_student(object, student_name)
|
|
56
|
+
PrcLib.info(format("'student': '%s' loaded with id %s",
|
|
57
|
+
student_name, object[:id]))
|
|
58
|
+
object
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Identified multiple identical students
|
|
62
|
+
# It will remove duplicated.
|
|
63
|
+
def found_multiple_students(list, student_name)
|
|
64
|
+
object = list[0]
|
|
65
|
+
PrcLib.warning(format("More than one student named '%s' is found: %s "\
|
|
66
|
+
'records. Selecting the first one and removing '\
|
|
67
|
+
'duplicates.',
|
|
68
|
+
student_name, list.length))
|
|
69
|
+
remove_multiple_students(list[1..-1], student_name)
|
|
70
|
+
object
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Remove list of identical students
|
|
74
|
+
def remove_multiple_students(list, student_name)
|
|
75
|
+
return false unless list.is_a?(Array)
|
|
76
|
+
return false if list.length == 0
|
|
77
|
+
|
|
78
|
+
count = 0
|
|
79
|
+
list.each { | elem | count += remove_student_object(elem) }
|
|
80
|
+
PrcLib.info(format("'student': %s duplicated '%s' removed. "\
|
|
81
|
+
'First loaded with id %s',
|
|
82
|
+
count, student_name, object[:id]))
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def remove_student_object(object)
|
|
86
|
+
register(object)
|
|
87
|
+
controller_delete(:student)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# The following handler is inactive.
|
|
91
|
+
# It provides a simple print-out code.
|
|
92
|
+
# If you want to activate it:
|
|
93
|
+
# * uncomment query_student function
|
|
94
|
+
# * update the :student data model
|
|
95
|
+
# on query_e, replace controller_query by query_student
|
|
96
|
+
|
|
97
|
+
# def query_student(sObjectType, sQuery, hParams)
|
|
98
|
+
# PrcLib::state (format("Running query process for object '%s' "\
|
|
99
|
+
# "with query '%s'",
|
|
100
|
+
# sObjectType,
|
|
101
|
+
# sQuery))
|
|
102
|
+
#
|
|
103
|
+
# objects = controller_query(sObjectType, sQuery)
|
|
104
|
+
# raise "Query error." if objects.nil?
|
|
105
|
+
#
|
|
106
|
+
# PrcLib::info (format("'%s': Queried. %s records found.",
|
|
107
|
+
# sObjectType,
|
|
108
|
+
# objects.length))
|
|
109
|
+
# objects
|
|
110
|
+
# end
|
|
111
|
+
|
|
112
|
+
# This handler is inactive.
|
|
113
|
+
# It provides a simple print-out code.
|
|
114
|
+
# If you want to activate it:
|
|
115
|
+
# * uncomment get_student function
|
|
116
|
+
# * update the :student data model
|
|
117
|
+
# on get_e, replace controller_get by get_student
|
|
118
|
+
|
|
119
|
+
# def delete_student(sObjectType, hParams)
|
|
120
|
+
# controller_delete(:student)
|
|
121
|
+
# PrcLib::info (format("'%s:%s' student removed",
|
|
122
|
+
# hParams[:student, :id],
|
|
123
|
+
# hParams[:student, :name]))
|
|
124
|
+
# end
|
|
73
125
|
end
|
|
74
126
|
|
|
75
|
-
|
|
76
|
-
#
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
127
|
+
module Lorj
|
|
128
|
+
# Declaring your data model and handlers.
|
|
129
|
+
# Process Handlers functions have to be declared before, as lorj check their
|
|
130
|
+
# existence during data model definition.
|
|
131
|
+
class BaseDefinition
|
|
132
|
+
# We need to define the student object data model and process handlers to
|
|
133
|
+
# use.
|
|
134
|
+
# Process handlers must manipulate data defined here.
|
|
135
|
+
#
|
|
136
|
+
# The controller can redefine object for it needs, but should NEVER impact
|
|
137
|
+
# the main process.
|
|
138
|
+
# The controller can add specific process to deal with internal controller
|
|
139
|
+
# objects.
|
|
140
|
+
# But this should never influence the original process model.
|
|
141
|
+
|
|
142
|
+
# Use define_obj, to declare the new object managed by lorj with process
|
|
143
|
+
# handlers.
|
|
144
|
+
|
|
145
|
+
define_obj(:student,
|
|
146
|
+
# The function to call in the class Students
|
|
147
|
+
:create_e => :create_student,
|
|
148
|
+
# We use predefined call to the controller query
|
|
149
|
+
:query_e => :controller_query,
|
|
150
|
+
# We use predefined call to the controller delete
|
|
151
|
+
:delete_e => :controller_delete
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
# obj_needs is used to declare parameters to pass to handlers.
|
|
155
|
+
# :for indicates those parameters to be passed to create_e handler only.
|
|
156
|
+
# Those data (or objects) will be collected and passed to the process
|
|
157
|
+
# handler as hParams.
|
|
158
|
+
|
|
159
|
+
obj_needs :data, :student_name, :for => [:create_e]
|
|
160
|
+
|
|
161
|
+
# By default, all data are required.
|
|
162
|
+
# You can set it as optional. Your process will need to deal with this
|
|
163
|
+
# optional data.
|
|
164
|
+
obj_needs_optional
|
|
165
|
+
obj_needs :data, :first_name, :for => [:create_e]
|
|
166
|
+
obj_needs :data, :last_name, :for => [:create_e]
|
|
167
|
+
obj_needs :data, :course
|
|
168
|
+
# Note that in this model, the training is renamed as course.
|
|
169
|
+
|
|
170
|
+
# the controller will need to map it to 'training'.
|
|
171
|
+
|
|
172
|
+
# def_attribute defines the data model.
|
|
173
|
+
# The process will be able to access those data
|
|
174
|
+
def_attribute :course
|
|
175
|
+
def_attribute :student_name
|
|
176
|
+
def_attribute :first_name
|
|
177
|
+
def_attribute :last_name
|
|
178
|
+
def_attribute :status
|
|
179
|
+
|
|
180
|
+
undefine_attribute :name
|
|
181
|
+
end
|
|
118
182
|
end
|