onebody-updateagent 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -10,7 +10,7 @@ Install [Ruby](http://ruby-lang.org) if you don't already have it.
10
10
 
11
11
  Run the following command ("sudo" may be required in some environments):
12
12
 
13
- gem install seven1m-onebody-updateagent -s http://gems.github.com
13
+ gem install onebody-updateagent -s http://gemcutter.org
14
14
 
15
15
  Configuration
16
16
  -------------
@@ -30,7 +30,7 @@ class UpdateAgent
30
30
  puts "You must utilize 'legacy_id' rather than 'id' so that"
31
31
  puts "identity and foreign keys are maintained from your"
32
32
  puts "existing membership management database."
33
- exit
33
+ exit(1)
34
34
  end
35
35
  end
36
36
 
@@ -71,9 +71,14 @@ class UpdateAgent
71
71
  end
72
72
  record_count += 1
73
73
  print "reading record #{record_count}\r"
74
- hash['deleted'] = false
75
- hash
74
+ if hash.any?
75
+ hash['deleted'] = false
76
+ hash
77
+ else
78
+ nil
79
+ end
76
80
  end
81
+ @data.compact!
77
82
  puts
78
83
  @attributes << 'deleted'
79
84
  @attributes.reject! { |a| IGNORE_ATTRIBUTES.include?(a) }
@@ -128,7 +133,9 @@ class UpdateAgent
128
133
  statuses.each do |status|
129
134
  record = data_by_id[status['legacy_id']]
130
135
  record['id'] = status['id']
131
- if status['status'] == 'error'
136
+ record['name'] = status['name']
137
+ record['status'] = status['status']
138
+ if status['error']
132
139
  puts "#{status['legacy_id']}: #{status['error']}"
133
140
  @errors << {:record => record, :error => status['error']}
134
141
  record['error_messages'] = status['error']
@@ -166,7 +173,7 @@ class UpdateAgent
166
173
  end
167
174
 
168
175
  def start_sync
169
- @sync = Sync.create(:complete => false)
176
+ @sync = Sync.create(:complete => false, :started_at => Time.now)
170
177
  end
171
178
 
172
179
  def finish_sync(create_items=true, mark_complete=true)
@@ -182,6 +189,7 @@ class UpdateAgent
182
189
  end
183
190
  if mark_complete
184
191
  @sync.complete = true
192
+ @sync.finished_at = Time.now
185
193
  @sync.error_count = errors.length
186
194
  @sync.success_count = (@create + @update).length - errors.length
187
195
  @sync.save
@@ -192,15 +200,15 @@ class UpdateAgent
192
200
  h = {
193
201
  :syncable_type => self.resource.name,
194
202
  :syncable_id => record['id'],
195
- :name => name_for(record),
203
+ :name => record['name'],
196
204
  :legacy_id => record['legacy_id'],
197
205
  :operation => operation,
198
- :status => record['error_messages'] ? 'error' : 'success'
206
+ :status => record['status']
199
207
  }
200
208
  if record['error_messages']
201
- h[:error_messages] = record['error_messages'].split('; ')
209
+ h[:error_messages] = record['error_messages']
202
210
  end
203
- return h
211
+ return h
204
212
  end
205
213
 
206
214
  def data_by_id
@@ -10,16 +10,26 @@ class PeopleUpdater < UpdateAgent
10
10
  @data = converter.convert(@data.clone)
11
11
  @attributes = @data.first.keys
12
12
  end
13
+ check_for_missing_columns
13
14
  person_data = []
14
15
  family_data = {}
15
16
  @data.each_with_index do |row, index|
16
17
  person, family = split_change_hash(row)
17
18
  if existing_family = family_data[family['legacy_id']]
18
19
  person['family'] = existing_family
20
+ if person.has_key?('email')
21
+ person['email_changed'] = false
22
+ @attributes << 'email_changed'
23
+ end
19
24
  person_data << person
20
25
  else
21
26
  person['family'] = family
27
+ if person.has_key?('email')
28
+ person['email_changed'] = false
29
+ @attributes << 'email_changed'
30
+ end
22
31
  person_data << person
32
+ family['barcode_id_changed'] = false if family.has_key?('barcode_id')
23
33
  family_data[family['legacy_id']] = family
24
34
  end
25
35
  print "splitting family record #{index+1}\r"
@@ -30,6 +40,16 @@ class PeopleUpdater < UpdateAgent
30
40
  @family_agent = FamilyUpdater.new(family_data.values)
31
41
  end
32
42
 
43
+ @@required_columns = %w(legacy_id legacy_family_id)
44
+
45
+ def check_for_missing_columns
46
+ if row = @data.detect { |row| (@@required_columns - row.keys).any? }
47
+ puts "Error: one or more required columns are missing."
48
+ puts "Required but missing: #{(@@required_columns - row.keys).join(', ')}"
49
+ exit(1)
50
+ end
51
+ end
52
+
33
53
  def name_for(row)
34
54
  "#{row['first_name']} #{row['last_name']}" rescue ''
35
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onebody-updateagent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Morgan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-15 00:00:00 -06:00
12
+ date: 2009-11-16 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -63,8 +63,10 @@ files:
63
63
  - lib/updateagent/updaters/family_updater.rb
64
64
  - lib/updateagent/updaters/people_updater.rb
65
65
  - lib/updateagent/updaters/external_group_updater.rb
66
- has_rdoc: false
66
+ has_rdoc: true
67
67
  homepage: http://github.com/seven1m/onebody-updateagent
68
+ licenses: []
69
+
68
70
  post_install_message:
69
71
  rdoc_options: []
70
72
 
@@ -85,9 +87,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
87
  requirements: []
86
88
 
87
89
  rubyforge_project:
88
- rubygems_version: 1.3.1
90
+ rubygems_version: 1.3.5
89
91
  signing_key:
90
- specification_version: 2
92
+ specification_version: 3
91
93
  summary: Companion to OneBody that handles sync with external data source.
92
94
  test_files: []
93
95