ncs_mdes_warehouse 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +10 -0
- data/lib/ncs_navigator/warehouse/transform_status.rb +29 -3
- data/lib/ncs_navigator/warehouse/transformers/enum_transformer.rb +14 -5
- data/lib/ncs_navigator/warehouse/version.rb +1 -1
- data/ncs_mdes_warehouse.gemspec +2 -1
- data/spec/ncs_navigator/warehouse/transform_status_spec.rb +41 -0
- data/spec/ncs_navigator/warehouse/transformers/enum_transformer_spec.rb +37 -7
- metadata +10 -4
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
NCS Navigator MDES Warehouse History
|
2
2
|
====================================
|
3
3
|
|
4
|
+
0.6.1
|
5
|
+
-----
|
6
|
+
|
7
|
+
- Change validation error reporting: Each validation error in
|
8
|
+
EnumTransformer now produces a separate TransformError. (Previously
|
9
|
+
they were concatenated into a single error.) (#2155)
|
10
|
+
|
11
|
+
- Provide a SubprocessTransformer-compatible JSON serialization on
|
12
|
+
TransformError. (#2199)
|
13
|
+
|
4
14
|
0.6.0
|
5
15
|
-----
|
6
16
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'ncs_navigator/warehouse'
|
2
2
|
require 'ncs_navigator/warehouse/data_mapper'
|
3
|
+
require 'json'
|
3
4
|
|
4
5
|
module NcsNavigator::Warehouse
|
5
6
|
##
|
@@ -38,12 +39,13 @@ module NcsNavigator::Warehouse
|
|
38
39
|
self.transform_errors << TransformError.new(:message => message)
|
39
40
|
end
|
40
41
|
|
41
|
-
def unsuccessful_record(record, message)
|
42
|
+
def unsuccessful_record(record, message, error_attributes={})
|
42
43
|
self.transform_errors <<
|
43
|
-
TransformError.new(
|
44
|
+
TransformError.new({
|
44
45
|
:model_class => record.class.name,
|
45
46
|
:record_id => (record.key.first if record && record.key),
|
46
|
-
:message => message
|
47
|
+
:message => message
|
48
|
+
}.merge(error_attributes))
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
@@ -57,6 +59,8 @@ module NcsNavigator::Warehouse
|
|
57
59
|
property :message, Text, :required => true
|
58
60
|
property :model_class, String, :length => 255
|
59
61
|
property :record_id, String, :length => 255
|
62
|
+
property :attribute_name, String, :length => 255
|
63
|
+
property :attribute_value, Text
|
60
64
|
|
61
65
|
belongs_to :transform_status, TransformStatus, :required => true
|
62
66
|
|
@@ -68,6 +72,28 @@ module NcsNavigator::Warehouse
|
|
68
72
|
].compact.join("\n")
|
69
73
|
)
|
70
74
|
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# Provides fpr a JSON serialization that is compatible with
|
78
|
+
# {SubprocessTransformer}.
|
79
|
+
#
|
80
|
+
# @return [Hash] a key-value object containing just the
|
81
|
+
# serializable components of this instance
|
82
|
+
def as_json
|
83
|
+
model.properties.
|
84
|
+
reject { |p| [:id, :transform_status_id].include?(p.name) }.
|
85
|
+
inject({}) { |json, prop|
|
86
|
+
value = self.send(prop.name)
|
87
|
+
json[prop.name.to_s] = value if value
|
88
|
+
json
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# @return [String] single-line JSON serialization of {#as_json}.
|
94
|
+
def to_json
|
95
|
+
as_json.to_json
|
96
|
+
end
|
71
97
|
end
|
72
98
|
|
73
99
|
TransformError.finalize
|
@@ -98,9 +98,11 @@ module NcsNavigator::Warehouse::Transformers
|
|
98
98
|
|
99
99
|
def save_model_instance(record, status)
|
100
100
|
if !has_valid_psu?(record)
|
101
|
-
msg = "Invalid PSU ID
|
101
|
+
msg = "Invalid PSU ID. The list of valid PSU IDs for this Study Center is #{@configuration.navigator.psus.collect(&:id).inspect}."
|
102
102
|
log.error "#{record_ident record}: #{msg}"
|
103
|
-
status.unsuccessful_record(record, msg
|
103
|
+
status.unsuccessful_record(record, msg,
|
104
|
+
:attribute_name => 'psu_id',
|
105
|
+
:attribute_value => record.psu_id.inspect)
|
104
106
|
elsif record.valid?
|
105
107
|
log.debug("Saving valid record #{record_ident record}.")
|
106
108
|
begin
|
@@ -115,9 +117,16 @@ module NcsNavigator::Warehouse::Transformers
|
|
115
117
|
status.unsuccessful_record(record, msg)
|
116
118
|
end
|
117
119
|
else
|
118
|
-
|
119
|
-
|
120
|
-
|
120
|
+
log.error "Invalid record. #{record_messages(record).join(' ')}"
|
121
|
+
record.errors.keys.each do |prop|
|
122
|
+
record.errors[prop].each do |e|
|
123
|
+
status.unsuccessful_record(
|
124
|
+
record, "Invalid: #{e}.",
|
125
|
+
:attribute_name => prop,
|
126
|
+
:attribute_value => record.send(prop).inspect
|
127
|
+
)
|
128
|
+
end
|
129
|
+
end
|
121
130
|
end
|
122
131
|
status.record_count += 1
|
123
132
|
end
|
data/ncs_mdes_warehouse.gemspec
CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency 'ncs_mdes', '~> 0.6', '>= 0.6.1'
|
19
19
|
s.add_dependency 'ncs_navigator_configuration', '~> 0.2'
|
20
20
|
|
21
|
-
|
21
|
+
# Post-3.2.4 breaks DataMapper due to https://github.com/rails/rails/pull/6857
|
22
|
+
s.add_dependency 'activesupport', '~> 3.0', '< 3.2.4'
|
22
23
|
s.add_dependency 'i18n', '~> 0.4' # required by activesupport
|
23
24
|
|
24
25
|
s.add_dependency 'thor', '~> 0.14.6'
|
@@ -62,5 +62,46 @@ module NcsNavigator::Warehouse
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
|
+
|
66
|
+
describe '#to_json' do
|
67
|
+
let(:error) {
|
68
|
+
TransformError.new(
|
69
|
+
:message => "It's\n complicated",
|
70
|
+
:model_class => SampleRecordishThing.to_s,
|
71
|
+
:record_id => '45-T',
|
72
|
+
:attribute_name => 'Fred',
|
73
|
+
:attribute_value => 'MacMurray'
|
74
|
+
)
|
75
|
+
}
|
76
|
+
let(:json) { error.to_json }
|
77
|
+
let(:parsed) { JSON.parse(json) }
|
78
|
+
|
79
|
+
it 'is a single line' do
|
80
|
+
json.should_not =~ /\n/
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'the JSON contents' do
|
84
|
+
%w(message model_class record_id attribute_name attribute_value).each do |prop|
|
85
|
+
it "includes the #{prop.gsub('_', ' ')}" do
|
86
|
+
parsed[prop].should == error.send(prop)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "does not include #{prop.gsub('_', ' ')} when it isn't set" do
|
90
|
+
error.send("#{prop}=", nil)
|
91
|
+
parsed.should_not have_key(prop)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'never contains the transform status ID' do
|
96
|
+
error.transform_status_id = 5
|
97
|
+
parsed.should_not have_key('transform_status_id')
|
98
|
+
end
|
99
|
+
|
100
|
+
it "never contains the error's own ID" do
|
101
|
+
error.id = 7
|
102
|
+
parsed.should_not have_key('id')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
65
106
|
end
|
66
107
|
end
|
@@ -8,7 +8,7 @@ module NcsNavigator::Warehouse::Transformers
|
|
8
8
|
include ::DataMapper::Resource
|
9
9
|
|
10
10
|
property :psu_id, String
|
11
|
-
property :recruit_type, String
|
11
|
+
property :recruit_type, String, :format => /^\d$/
|
12
12
|
property :id, Integer, :key => true
|
13
13
|
property :name, String, :required => true
|
14
14
|
end
|
@@ -46,15 +46,37 @@ module NcsNavigator::Warehouse::Transformers
|
|
46
46
|
records[0].should_receive(:save).and_return(true)
|
47
47
|
records[1].should_receive(:save).and_return(true)
|
48
48
|
records[2].name = nil
|
49
|
+
records[2].recruit_type = 'H'
|
49
50
|
|
50
51
|
subject.transform(transform_status)
|
51
52
|
end
|
52
53
|
|
53
|
-
it 'records
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
it 'records each invalidity separately' do
|
55
|
+
transform_status.transform_errors.size.should == 2
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'the error for an invalidity' do
|
59
|
+
let(:err) { transform_status.transform_errors.sort_by { |te| te.message }.last }
|
60
|
+
|
61
|
+
it "knows the record's class" do
|
62
|
+
err.model_class.should == Sample.to_s
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'knows the record ID' do
|
66
|
+
err.record_id.should == '3'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'has the invalidity message' do
|
70
|
+
err.message.should == 'Invalid: Recruit type has an invalid format.'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'knows the invalid attribute' do
|
74
|
+
err.attribute_name.should == 'recruit_type'
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'knows the invalid value' do
|
78
|
+
err.attribute_value.should == '"H"'
|
79
|
+
end
|
58
80
|
end
|
59
81
|
|
60
82
|
it 'saves the other instances' do
|
@@ -101,7 +123,15 @@ module NcsNavigator::Warehouse::Transformers
|
|
101
123
|
|
102
124
|
it 'has a message' do
|
103
125
|
error.message.should ==
|
104
|
-
'Invalid PSU ID
|
126
|
+
'Invalid PSU ID. The list of valid PSU IDs for this Study Center is ["20000030", "20000042"].'
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'has the PSU attribute' do
|
130
|
+
error.attribute_name.should == 'psu_id'
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'has the invalid value' do
|
134
|
+
error.attribute_value.should == '"20000041"'
|
105
135
|
end
|
106
136
|
end
|
107
137
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ncs_mdes_warehouse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ncs_mdes
|
@@ -57,6 +57,9 @@ dependencies:
|
|
57
57
|
- - ~>
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '3.0'
|
60
|
+
- - <
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.2.4
|
60
63
|
type: :runtime
|
61
64
|
prerelease: false
|
62
65
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -65,6 +68,9 @@ dependencies:
|
|
65
68
|
- - ~>
|
66
69
|
- !ruby/object:Gem::Version
|
67
70
|
version: '3.0'
|
71
|
+
- - <
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 3.2.4
|
68
74
|
- !ruby/object:Gem::Dependency
|
69
75
|
name: i18n
|
70
76
|
requirement: !ruby/object:Gem::Requirement
|
@@ -1391,7 +1397,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
1391
1397
|
version: '0'
|
1392
1398
|
segments:
|
1393
1399
|
- 0
|
1394
|
-
hash:
|
1400
|
+
hash: 766009229452089340
|
1395
1401
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
1396
1402
|
none: false
|
1397
1403
|
requirements:
|
@@ -1400,7 +1406,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1400
1406
|
version: '0'
|
1401
1407
|
segments:
|
1402
1408
|
- 0
|
1403
|
-
hash:
|
1409
|
+
hash: 766009229452089340
|
1404
1410
|
requirements: []
|
1405
1411
|
rubyforge_project:
|
1406
1412
|
rubygems_version: 1.8.24
|