kuali_toolbox 0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.gitignore +14 -0
- data/.travis.yml +10 -0
- data/Account_Provisioning_CSV_Template.xlsx +0 -0
- data/Gemfile +20 -0
- data/LICENSE.txt +663 -0
- data/README.md +57 -0
- data/Rakefile +26 -0
- data/bin/transform_CSV_to_HR_XML +332 -0
- data/bin/validate_HR_XML +32 -0
- data/kuali_toolbox.gemspec +48 -0
- data/lib/kuali_toolbox/etl/grm.rb +394 -0
- data/lib/kuali_toolbox/etl.rb +410 -0
- data/lib/kuali_toolbox/version.rb +20 -0
- data/lib/kuali_toolbox.rb +23 -0
- data/spec/kuali_toolbox/etl/grm_spec.rb +620 -0
- data/spec/kuali_toolbox/etl_spec.rb +521 -0
- data/spec/kuali_toolbox_spec.rb +27 -0
- data/spec/spec_helper.rb +42 -0
- data.tar.gz.sig +0 -0
- metadata +190 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,394 @@
|
|
1
|
+
# KualiCo's client library and command-line tool to help interact with KualiCo's cloud APIs.
|
2
|
+
# Copyright (C) 2014-2015 KualiCo, Inc.
|
3
|
+
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU Affero General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU Affero General Public License for more details.
|
13
|
+
|
14
|
+
# You should have received a copy of the GNU Affero General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require 'net/http'
|
18
|
+
require 'nokogiri'
|
19
|
+
require 'tempfile'
|
20
|
+
require "kuali_toolbox/etl"
|
21
|
+
|
22
|
+
# KualiCo Grant and Research Management methods.
|
23
|
+
module KualiCo::ETL::GRM
|
24
|
+
|
25
|
+
# Parses the <tt>ROLODEX_ID</tt> by column :name and mutates the SQL statement accordingly.
|
26
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
27
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
28
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
29
|
+
# @param opt [Hash] options Hash will be passed through to {KualiCo::ETL.parse_integer!}.
|
30
|
+
# @return [void]
|
31
|
+
# @see parse_integer!
|
32
|
+
def self.parse_rolodex_id!(row, insert_str, values_str, opt={ name: 'ROLODEX_ID', required: true, length: 6 })
|
33
|
+
# `ROLODEX_ID` decimal(6,0) NOT NULL DEFAULT '0',
|
34
|
+
opt[:name] = "ROLODEX_ID" if opt[:name].nil?
|
35
|
+
opt[:required] = true if opt[:required].nil?
|
36
|
+
opt[:length] = 6 if opt[:length].nil?
|
37
|
+
KualiCo::ETL::parse_integer! row, insert_str, values_str, opt
|
38
|
+
end
|
39
|
+
|
40
|
+
# Parses the <tt>COUNTRY_CODE</tt> by column :name and mutates the SQL statement accordingly.
|
41
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
42
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
43
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
44
|
+
# @param opt [Hash] options Hash will be passed through to {KualiCo::ETL.parse_string!}.
|
45
|
+
# @return [void]
|
46
|
+
# @see parse_string!
|
47
|
+
def self.parse_country_code!(row, insert_str, values_str, opt={ name: 'COUNTRY_CODE', length: 3 })
|
48
|
+
# `COUNTRY_CODE` char(3) COLLATE utf8_bin DEFAULT NULL,
|
49
|
+
opt[:name] = "COUNTRY_CODE" if opt[:name].nil?
|
50
|
+
opt[:length] = 3 if opt[:length].nil?
|
51
|
+
KualiCo::ETL::parse_string! row, insert_str, values_str, opt
|
52
|
+
end
|
53
|
+
|
54
|
+
# Parses the <tt>STATE</tt> by column :name and mutates the SQL statement accordingly.
|
55
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
56
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
57
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
58
|
+
# @param opt [Hash] options Hash will be passed through to {KualiCo::ETL.parse_string!}.
|
59
|
+
# @return [void]
|
60
|
+
# @see parse_string!
|
61
|
+
def self.parse_state!(row, insert_str, values_str, opt={ name: 'STATE', length: 30 })
|
62
|
+
# `STATE` varchar(30) COLLATE utf8_bin DEFAULT NULL,
|
63
|
+
opt[:name] = "STATE" if opt[:name].nil?
|
64
|
+
opt[:length] = 30 if opt[:length].nil?
|
65
|
+
KualiCo::ETL::parse_string! row, insert_str, values_str, opt
|
66
|
+
end
|
67
|
+
|
68
|
+
# Parses the <tt>SPONSOR_CODE</tt> by column :name and mutates the SQL statement accordingly.
|
69
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
70
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
71
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
72
|
+
# @param opt [Hash] options Hash will be passed through to {KualiCo::ETL.parse_string!}.
|
73
|
+
# @return [void]
|
74
|
+
# @see parse_string!
|
75
|
+
def self.parse_sponsor_code!(row, insert_str, values_str, opt={ name: 'SPONSOR_CODE', required: false, length: 6 })
|
76
|
+
# `SPONSOR_CODE` char(6) COLLATE utf8_bin NOT NULL DEFAULT '',
|
77
|
+
opt[:name] = "SPONSOR_CODE" if opt[:name].nil?
|
78
|
+
opt[:required] = false if opt[:required].nil?
|
79
|
+
opt[:length] = 6 if opt[:length].nil?
|
80
|
+
KualiCo::ETL::parse_string! row, insert_str, values_str, opt
|
81
|
+
end
|
82
|
+
|
83
|
+
# Parses the <tt>POSTAL_CODE</tt> by column :name and mutates the SQL statement accordingly.
|
84
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
85
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
86
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
87
|
+
# @param opt [Hash] options Hash will be passed through to {KualiCo::ETL.parse_string!}.
|
88
|
+
# @return [void]
|
89
|
+
# @see parse_string!
|
90
|
+
def self.parse_postal_code!(row, insert_str, values_str, opt={ name: 'POSTAL_CODE', length: 15 })
|
91
|
+
# `POSTAL_CODE` varchar(15) COLLATE utf8_bin DEFAULT NULL,
|
92
|
+
opt[:name] = "POSTAL_CODE" if opt[:name].nil?
|
93
|
+
opt[:length] = 15 if opt[:length].nil?
|
94
|
+
KualiCo::ETL::parse_string! row, insert_str, values_str, opt
|
95
|
+
end
|
96
|
+
|
97
|
+
# Parses the <tt>OWNED_BY_UNIT</tt> by column :name and mutates the SQL statement accordingly.
|
98
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
99
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
100
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
101
|
+
# @param opt [Hash] options Hash will be passed through to {KualiCo::ETL.parse_string!}.
|
102
|
+
# @return [void]
|
103
|
+
# @see parse_string!
|
104
|
+
def self.parse_owned_by_unit!(row, insert_str, values_str, opt={ name: 'OWNED_BY_UNIT', required: true, length: 8 })
|
105
|
+
# `OWNED_BY_UNIT` varchar(8) COLLATE utf8_bin NOT NULL,
|
106
|
+
opt[:name] = "OWNED_BY_UNIT" if opt[:name].nil?
|
107
|
+
opt[:required] = true if opt[:required].nil?
|
108
|
+
opt[:length] = 8 if opt[:length].nil?
|
109
|
+
KualiCo::ETL::parse_string! row, insert_str, values_str, opt
|
110
|
+
end
|
111
|
+
|
112
|
+
# Parse an <tt>EMAIL_ADDRESS</tt> from a String.
|
113
|
+
# @note The result is validated against a email address RegExp.
|
114
|
+
# @param [String] str the String to be parsed.
|
115
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
116
|
+
# @return [String] the parsed <tt>EMAIL_ADDRESS</tt>.
|
117
|
+
# @raise [TextParseError] if the email address is not valid.
|
118
|
+
# @see parse_string
|
119
|
+
def self.parse_email_address(str, opt={ name: 'EMAIL_ADDRESS', length: 60 })
|
120
|
+
# `EMAIL_ADDRESS` varchar(60) COLLATE utf8_bin DEFAULT NULL,
|
121
|
+
opt[:name] = "EMAIL_ADDRESS" if opt[:name].nil?
|
122
|
+
opt[:length] = 60 if opt[:length].nil?
|
123
|
+
opt[:valid_values] = /^(([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?))?$/ if opt[:valid_values].nil?
|
124
|
+
return KualiCo::ETL::parse_string str, opt
|
125
|
+
end
|
126
|
+
|
127
|
+
# Parses the <tt>EMAIL_ADDRESS</tt> by column :name and mutates the SQL statement accordingly.
|
128
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
129
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
130
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
131
|
+
# @param opt [Hash] options Hash will be passed through to {parse_email_address}.
|
132
|
+
# @return [void]
|
133
|
+
# @see parse_email_address
|
134
|
+
# @see mutate_sql_stmt!
|
135
|
+
def self.parse_email_address!(row, insert_str, values_str, opt={ name: 'EMAIL_ADDRESS' })
|
136
|
+
# `EMAIL_ADDRESS` varchar(60) COLLATE utf8_bin DEFAULT NULL,
|
137
|
+
opt[:name] = "EMAIL_ADDRESS" if opt[:name].nil?
|
138
|
+
email_address = parse_email_address row[ KualiCo::ETL::to_symbol( opt[:name] ) ]
|
139
|
+
KualiCo::ETL::mutate_sql_stmt! insert_str, opt[:name], values_str, email_address
|
140
|
+
end
|
141
|
+
|
142
|
+
# Parse a <tt>PRNCPL_ID</tt> from a String.
|
143
|
+
# @param [String] str the String to be parsed.
|
144
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
145
|
+
# @return [String] the parsed <tt>PRNCPL_ID</tt>.
|
146
|
+
# @see parse_string
|
147
|
+
def self.parse_principal_id(str, opt={ name: 'PRNCPL_ID', required: true, length: 40 })
|
148
|
+
# `PRNCPL_ID` varchar(40) COLLATE utf8_bin NOT NULL DEFAULT '',
|
149
|
+
opt[:name] = "PRNCPL_ID" if opt[:name].nil?
|
150
|
+
opt[:required] = true if opt[:required].nil?
|
151
|
+
opt[:length] = 40 if opt[:length].nil?
|
152
|
+
KualiCo::ETL::parse_string str, opt
|
153
|
+
end
|
154
|
+
|
155
|
+
# Parse a <tt>PRNCPL_NM</tt> from a String.
|
156
|
+
# @param [String] str the String to be parsed.
|
157
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
158
|
+
# @return [String] the parsed <tt>PRNCPL_NM</tt>.
|
159
|
+
# @see parse_string
|
160
|
+
def self.parse_principal_name(str, opt={ name: 'PRNCPL_NM', required: true, length: 100 })
|
161
|
+
# `PRNCPL_NM` varchar(100) COLLATE utf8_bin NOT NULL,
|
162
|
+
opt[:name] = "PRNCPL_NM" if opt[:name].nil?
|
163
|
+
opt[:length] = 100 if opt[:length].nil?
|
164
|
+
opt[:required] = true if opt[:required].nil?
|
165
|
+
prncpl_nm = KualiCo::ETL::parse_string str, opt
|
166
|
+
unless prncpl_nm =~ /^([a-z0-9\@\.\_\-]+)$/
|
167
|
+
raise KualiCo::ETL::error TextParseError.new "Illegal prncpl_nm found: '#{prncpl_nm}'"
|
168
|
+
end
|
169
|
+
return prncpl_nm
|
170
|
+
end
|
171
|
+
|
172
|
+
# Parse an <tt>EMP_STAT_CD</tt> from a String.
|
173
|
+
# @param [String] str the String to be parsed.
|
174
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
175
|
+
# @return [String] the parsed <tt>EMP_STAT_CD</tt>.
|
176
|
+
# @raise [TextParseError] if the <tt>EMP_STAT_CD</tt> is not valid.
|
177
|
+
# @see parse_string
|
178
|
+
def self.parse_emp_stat_cd(str, opt={ name: 'EMP_STAT_CD', valid_values: /^(A|D|L|N|P|R|S|T)$/i })
|
179
|
+
# `EMP_STAT_CD` varchar(40) COLLATE utf8_bin DEFAULT NULL,
|
180
|
+
opt[:name] = "EMP_STAT_CD" if opt[:name].nil?
|
181
|
+
opt[:valid_values] = /^(A|D|L|N|P|R|S|T)$/i if opt[:valid_values].nil?
|
182
|
+
return KualiCo::ETL::parse_flag str, opt
|
183
|
+
end
|
184
|
+
|
185
|
+
# Parse an <tt>EMP_TYP_CD</tt> from a String.
|
186
|
+
# @param [String] str the String to be parsed.
|
187
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
188
|
+
# @return [String] the parsed <tt>EMP_TYP_CD</tt>.
|
189
|
+
# @raise [TextParseError] if the <tt>EMP_TYP_CD</tt> is not valid.
|
190
|
+
# @see parse_string
|
191
|
+
def self.parse_emp_typ_cd(str, opt={ name: 'EMP_TYP_CD', valid_values: /^(N|O|P)$/i })
|
192
|
+
# `EMP_TYP_CD` varchar(40) COLLATE utf8_bin DEFAULT NULL,
|
193
|
+
opt[:name] = "EMP_TYP_CD" if opt[:name].nil?
|
194
|
+
opt[:valid_values] = /^(N|O|P)$/i if opt[:valid_values].nil?
|
195
|
+
return KualiCo::ETL::parse_flag str, opt
|
196
|
+
end
|
197
|
+
|
198
|
+
# Parse an <tt>ADDR_TYP_CD</tt> from a String.
|
199
|
+
# @param [String] str the String to be parsed.
|
200
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
201
|
+
# @return [String] the parsed <tt>ADDR_TYP_CD</tt>.
|
202
|
+
# @raise [TextParseError] if the <tt>ADDR_TYP_CD</tt> is not valid.
|
203
|
+
# @see parse_string
|
204
|
+
def self.parse_address_type_code(str, opt={ name: 'ADDR_TYP_CD', length: 3, valid_values: /^(HM|OTH|WRK)$/i })
|
205
|
+
opt[:name] = "ADDR_TYP_CD" if opt[:name].nil?
|
206
|
+
opt[:length] = 3 if opt[:length].nil?
|
207
|
+
opt[:valid_values] = /^(HM|OTH|WRK)$/i if opt[:valid_values].nil?
|
208
|
+
return KualiCo::ETL::parse_flag str, opt
|
209
|
+
end
|
210
|
+
|
211
|
+
# Parse a <tt>NM_TYP_CD</tt> from a String.
|
212
|
+
# @param [String] str the String to be parsed.
|
213
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
214
|
+
# @return [String] the parsed <tt>NM_TYP_CD</tt>.
|
215
|
+
# @raise [TextParseError] if the <tt>NM_TYP_CD</tt> is not valid.
|
216
|
+
# @see parse_string
|
217
|
+
def self.parse_name_code(str, opt={ name: 'NM_TYP_CD', length: 4, valid_values: /^(OTH|PRFR|PRM)$/i })
|
218
|
+
opt[:name] = "NM_TYP_CD" if opt[:name].nil?
|
219
|
+
opt[:length] = 4 if opt[:length].nil?
|
220
|
+
opt[:valid_values] = /^(OTH|PRFR|PRM)$/i if opt[:valid_values].nil?
|
221
|
+
return KualiCo::ETL::parse_flag str, opt
|
222
|
+
end
|
223
|
+
|
224
|
+
# Parse a <tt>PREFIX_NM</tt> from a String.
|
225
|
+
# @param [String] str the String to be parsed.
|
226
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
227
|
+
# @return [String] the parsed <tt>PREFIX_NM</tt>.
|
228
|
+
# @raise [TextParseError] if the <tt>PREFIX_NM</tt> is not valid.
|
229
|
+
# @see parse_string
|
230
|
+
def self.parse_prefix(str, opt={ name: 'PREFIX_NM', length: 3, valid_values: /^(Ms|Mrs|Mr|Dr)?$/ })
|
231
|
+
opt[:name] = "PREFIX_NM" if opt[:name].nil?
|
232
|
+
opt[:length] = 3 if opt[:length].nil?
|
233
|
+
opt[:valid_values] = /^(Ms|Mrs|Mr|Dr)?$/ if opt[:valid_values].nil?
|
234
|
+
opt[:upcase] = false if opt[:upcase].nil?
|
235
|
+
return KualiCo::ETL::parse_flag str, opt
|
236
|
+
end
|
237
|
+
|
238
|
+
# Parse a <tt>SUFFIX_NM</tt> from a String.
|
239
|
+
# @param [String] str the String to be parsed.
|
240
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
241
|
+
# @return [String] the parsed <tt>SUFFIX_NM</tt>.
|
242
|
+
# @raise [TextParseError] if the <tt>SUFFIX_NM</tt> is not valid.
|
243
|
+
# @see parse_string
|
244
|
+
def self.parse_suffix(str, opt={ name: 'SUFFIX_NM', length: 3, valid_values: /^(Jr|Sr|Mr|Md)?$/ })
|
245
|
+
opt[:name] = "SUFFIX_NM" if opt[:name].nil?
|
246
|
+
opt[:length] = 3 if opt[:length].nil?
|
247
|
+
opt[:valid_values] = /^(Jr|Sr|Mr|Md)?$/ if opt[:valid_values].nil?
|
248
|
+
opt[:upcase] = false if opt[:upcase].nil?
|
249
|
+
return KualiCo::ETL::parse_flag str, opt
|
250
|
+
end
|
251
|
+
|
252
|
+
# Parse a <tt>PHONE_TYP_CD</tt> from a String.
|
253
|
+
# @param [String] str the String to be parsed.
|
254
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
255
|
+
# @return [String] the parsed <tt>PHONE_TYP_CD</tt>.
|
256
|
+
# @raise [TextParseError] if the <tt>PHONE_TYP_CD</tt> is not valid.
|
257
|
+
# @see parse_string
|
258
|
+
def self.parse_phone_type(str, opt={ name: 'PHONE_TYP_CD', length: 3, valid_values: /^(FAX|HM|MBL|OTH|WRK)$/i })
|
259
|
+
opt[:name] = "PHONE_TYP_CD" if opt[:name].nil?
|
260
|
+
opt[:length] = 3 if opt[:length].nil?
|
261
|
+
opt[:valid_values] = /^(FAX|HM|MBL|OTH|WRK)$/i if opt[:valid_values].nil?
|
262
|
+
return KualiCo::ETL::parse_flag str, opt
|
263
|
+
end
|
264
|
+
|
265
|
+
# Parse a <tt>PHONE_NBR</tt> from a String.
|
266
|
+
# @param [String] str the String to be parsed.
|
267
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
268
|
+
# @return [String] the parsed <tt>PHONE_NBR</tt>.
|
269
|
+
# @raise [TextParseError] if the <tt>PHONE_NBR</tt> is not valid.
|
270
|
+
# @see parse_string
|
271
|
+
def self.parse_phone_number(str, opt={ name: 'PHONE_NBR', length: 12, valid_values: /^(\d{3}-\d{3}-\d{4})?$/ })
|
272
|
+
opt[:name] = "PHONE_NBR" if opt[:name].nil?
|
273
|
+
opt[:length] = 12 if opt[:length].nil?
|
274
|
+
opt[:valid_values] = /^(\d{3}-\d{3}-\d{4})?$/ if opt[:valid_values].nil?
|
275
|
+
return KualiCo::ETL::parse_string str, opt
|
276
|
+
end
|
277
|
+
|
278
|
+
# Parse an <tt>EMAIL_TYP_CD</tt> from a String.
|
279
|
+
# @param [String] str the String to be parsed.
|
280
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
281
|
+
# @return [String] the parsed <tt>EMAIL_TYP_CD</tt>.
|
282
|
+
# @raise [TextParseError] if the <tt>EMAIL_TYP_CD</tt> is not valid.
|
283
|
+
# @see parse_string
|
284
|
+
def self.parse_email_type(str, opt={ name: 'EMAIL_TYP_CD', length: 3, valid_values: /^(HM|OTH|WRK)$/i })
|
285
|
+
opt[:name] = "EMAIL_TYP_CD" if opt[:name].nil?
|
286
|
+
opt[:length] = 3 if opt[:length].nil?
|
287
|
+
opt[:valid_values] = /^(HM|OTH|WRK)$/i if opt[:valid_values].nil?
|
288
|
+
return KualiCo::ETL::parse_flag str, opt
|
289
|
+
end
|
290
|
+
|
291
|
+
# Parse a <tt>YEAR</tt> from a String.
|
292
|
+
# @param [String] str the String to be parsed.
|
293
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
294
|
+
# @return [String] the parsed <tt>YEAR</tt>.
|
295
|
+
# @raise [TextParseError] if the <tt>YEAR</tt> is not valid.
|
296
|
+
# @see parse_string
|
297
|
+
def self.parse_year(str, opt={ name: 'YEAR', length: 4, valid_values: /^(\d{4})?$/ })
|
298
|
+
opt[:length] = 4 if opt[:length].nil?
|
299
|
+
opt[:valid_values] = /^(\d{4})?$/ if opt[:valid_values].nil?
|
300
|
+
return KualiCo::ETL::parse_string str, opt
|
301
|
+
end
|
302
|
+
|
303
|
+
# Parse a <tt>CITIZENSHIP_TYPE_CODE</tt> from a String.
|
304
|
+
# @param [String] str the String to be parsed.
|
305
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
306
|
+
# @return [String] the parsed <tt>CITIZENSHIP_TYPE_CODE</tt>.
|
307
|
+
# @raise [TextParseError] if the <tt>CITIZENSHIP_TYPE_CODE</tt> is not valid.
|
308
|
+
# @see parse_string
|
309
|
+
def self.parse_citizenship_type(str, opt={ name: 'CITIZENSHIP_TYPE_CODE', valid_values: /^([1-5])$/ })
|
310
|
+
opt[:name] = "CITIZENSHIP_TYPE_CODE" if opt[:name].nil?
|
311
|
+
opt[:valid_values] = /^([1-5])$/ if opt[:valid_values].nil?
|
312
|
+
return KualiCo::ETL::parse_flag str, opt
|
313
|
+
end
|
314
|
+
|
315
|
+
# Parse a <tt>DEGREE</tt> from a String.
|
316
|
+
# @param [String] str the String to be parsed.
|
317
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
318
|
+
# @return [String] the parsed <tt>DEGREE</tt>.
|
319
|
+
# @raise [TextParseError] if the <tt>DEGREE</tt> is not valid.
|
320
|
+
# @see parse_string
|
321
|
+
def self.parse_degree(str, opt={ name: 'DEGREE', length: 5 })
|
322
|
+
opt[:name] = "DEGREE" if opt[:name].nil?
|
323
|
+
opt[:length] = 5 if opt[:length].nil?
|
324
|
+
opt[:valid_values] = /^(AS|BA|BComm|BEd|BS|DA|DC|DD|DDS|DEng|DFA|DH|DHA|DMin|DPA|DSN|DVM|DVS|HS|JD|LLD|LLM|MA|MAEd|MArch|MBA|MD|MDS|MDiv|MEE|MEd|MEng|MFA|MIS|MLS|MPA|MPE|MPH|MPd|MPhil|MS|MSEd|MST|MSW|MTh|PhD|PharD|ScD|ThD|UKNW)?$/ if opt[:valid_values].nil?
|
325
|
+
opt[:upcase] = false if opt[:upcase].nil?
|
326
|
+
return KualiCo::ETL::parse_flag str, opt
|
327
|
+
end
|
328
|
+
|
329
|
+
# Parse an <tt>ACTV_IND</tt> from a String.
|
330
|
+
# @note Designed specifically for <tt>ACTV_IND</tt>, but could be used on *any* fields that matches <tt>(Y|N)</tt>.
|
331
|
+
# @param [String] str the String to be parsed.
|
332
|
+
# @param [Hash] opt options Hash will be passed through to {KualiCo::ETL.parse_string}.
|
333
|
+
# @return [String] the parsed <tt>ACTV_IND</tt>.
|
334
|
+
# @raise [TextParseError] if the <tt>ACTV_IND</tt> is not valid.
|
335
|
+
# @see parse_string
|
336
|
+
def self.parse_actv_ind(str, opt={ name: 'ACTV_IND', default: 'Y', valid_values: /^(Y|N)$/i })
|
337
|
+
# `ACTV_IND` varchar(1) COLLATE utf8_bin DEFAULT 'Y',
|
338
|
+
opt[:name] = "ACTV_IND" if opt[:name].nil?
|
339
|
+
opt[:default] = "Y" if opt[:default].nil?
|
340
|
+
opt[:valid_values] = /^(Y|N)$/i if opt[:valid_values].nil?
|
341
|
+
return KualiCo::ETL::parse_flag str, opt
|
342
|
+
end
|
343
|
+
|
344
|
+
# Parses the <tt>ACTV_IND</tt> by column :name and mutates the SQL statement accordingly.
|
345
|
+
# @note Designed specifically for <tt>ACTV_IND</tt>, but could be used on *any* fields that matches <tt>(Y|N)</tt>.
|
346
|
+
# @param row [CSV::Row] the CSV Row being parsed
|
347
|
+
# @param insert_str [String] the left side of the insert statement (i.e. columns)
|
348
|
+
# @param values_str [String] the right side of the insert statement (i.e. values)
|
349
|
+
# @param opt [Hash] options Hash will be passed through to {parse_actv_ind}.
|
350
|
+
# @return [void]
|
351
|
+
# @see parse_actv_ind
|
352
|
+
# @see mutate_sql_stmt!
|
353
|
+
def self.parse_actv_ind!(row, insert_str, values_str, opt={ name: 'ACTV_IND' })
|
354
|
+
# `ACTV_IND` varchar(1) COLLATE utf8_bin DEFAULT 'Y',
|
355
|
+
opt[:name] = "ACTV_IND" if opt[:name].nil?
|
356
|
+
actv_ind = parse_actv_ind row[ KualiCo::ETL::to_symbol( opt[:name] ) ]
|
357
|
+
KualiCo::ETL::mutate_sql_stmt! insert_str, opt[:name], values_str, actv_ind
|
358
|
+
end
|
359
|
+
|
360
|
+
# Performs an XML XSD schema validation using the published schema.
|
361
|
+
# @note Any schema validation errors are output to STDOUT via puts.
|
362
|
+
# @param xml_filename [String] A path to the XML file to be validated.
|
363
|
+
# @return [Boolean] true if no validation errors are found; otherwise false.
|
364
|
+
def self.validate_hr_xml(xml_filename)
|
365
|
+
ret_val = false
|
366
|
+
# validate the resulting XML file against the official XSD schema
|
367
|
+
uri = URI 'https://raw.githubusercontent.com/KualiCo/ce-tech-docs/master/hrmanifest.xsd'
|
368
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
369
|
+
Tempfile.open "hrmanifest.xsd" do |schema|
|
370
|
+
request = Net::HTTP::Get.new uri.request_uri
|
371
|
+
http.request request do |response|
|
372
|
+
response.read_body do |segment|
|
373
|
+
schema.write(segment)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
schema.rewind
|
377
|
+
xsd = Nokogiri::XML::Schema schema
|
378
|
+
doc = Nokogiri::XML File.read xml_filename
|
379
|
+
xml_errors = xsd.validate doc
|
380
|
+
if xml_errors.empty?
|
381
|
+
puts "Congratulations! The XML file passes XSD schema validation! w00t!\n\n"
|
382
|
+
ret_val = true
|
383
|
+
else
|
384
|
+
puts "Sorry, the XML file does NOT pass XSD schema validation!:"
|
385
|
+
xml_errors.each do |error|
|
386
|
+
puts error.message
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end # schema
|
390
|
+
end
|
391
|
+
return ret_val
|
392
|
+
end
|
393
|
+
|
394
|
+
end
|