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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'lib/adiwg/mdtranslator/readers/fgdc/modules/module_contact.rb', line 43
def self.unpack(xContact, hResponseObj)
intMetadataClass = InternalMetadata.new
contactType = nil
personName = ''
orgName = ''
personId = nil
orgId = nil
xContactInfo = xContact.xpath('./cntinfo')
unless xContactInfo.empty?
xPerson = xContactInfo.xpath('./cntperp')
unless xPerson.empty?
contactType = 'person'
personName = xPerson.xpath('./cntper').text
orgName = xPerson.xpath('./cntorg').text
end
xOrg = xContactInfo.xpath('./cntorgp')
unless xOrg.empty?
contactType = 'organization'
personName = xOrg.xpath('./cntper').text
orgName = xOrg.xpath('./cntorg').text
end
if contactType.nil?
hResponseObj[:readerExecutionMessages] << 'ERROR: FGDC reader: contact is neither person or organization'
return nil
end
if contactType == 'person' && personName == ''
hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: contact person name is missing'
end
if contactType == 'organization' && orgName == ''
hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: contact organization name is missing'
end
unless contactType.nil?
personId = Fgdc.add_contact(personName, false) unless personName.empty?
orgId = Fgdc.add_contact(orgName, true) unless orgName.empty?
hContact = Fgdc.get_contact_by_id(personId) if contactType == 'person'
hContact = Fgdc.get_contact_by_id(orgId) if contactType == 'organization'
if contactType == 'person'
unless orgId.nil?
unless hContact.include?(orgId)
hContact[:memberOfOrgs] << orgId
end
end
end
position = xContactInfo.xpath('./cntpos').text
if contactType == 'person'
hContact[:positionName] = position
end
axAddress = xContactInfo.xpath('./cntaddr')
unless axAddress.empty?
axAddress.each do |xAddress|
hAddress = intMetadataClass.newAddress
addType = xAddress.xpath('./addrtype').text
hAddress[:addressTypes] << addType unless addType.empty?
if addType.empty?
hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: contact address type is missing'
end
axAddLines = xAddress.xpath('./address')
unless axAddLines.empty?
axAddLines.each do |xLine|
addLine = xLine.text
hAddress[:deliveryPoints] << addLine unless addLine.empty?
end
end
city = xAddress.xpath('./city').text
hAddress[:city] = city unless city.empty?
if city.empty?
hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: contact address city is missing'
end
state = xAddress.xpath('./state').text
hAddress[:adminArea] = state unless state.empty?
if state.empty?
hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: contact address state is missing'
end
postal = xAddress.xpath('./postal').text
hAddress[:postalCode] = postal unless postal.empty?
if postal.empty?
hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: contact address zip code is missing'
end
country = xAddress.xpath('./country').text
hAddress[:country] = country unless country.empty?
saveAddress = true
hContact[:addresses].each do |hOld|
isSame = true
isSame = false unless hAddress[:deliveryPoints].length == hOld[:deliveryPoints].length
if hAddress[:deliveryPoints].length == hOld[:deliveryPoints].length
(1..hAddress[:deliveryPoints].length).each do |x|
isSame = false unless hAddress[:deliveryPoints][x] == hOld[:deliveryPoints][x]
end
end
isSame = false unless hAddress[:city] == hOld[:city]
isSame = false unless hAddress[:adminArea] == hOld[:adminArea]
isSame = false unless hAddress[:postalCode] == hOld[:postalCode]
isSame = false unless hAddress[:country] == hOld[:country]
if isSame
saveAddress = false
break
end
end
hContact[:addresses] << hAddress if saveAddress
end
end
if axAddress.empty?
hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: contact address is missing'
end
axVoice = xContactInfo.xpath('./cntvoice')
unless axVoice.empty?
axVoice.each do |xPhone|
phone = xPhone.text
unless phone.empty?
add_phone(hContact, phone, 'voice')
end
end
end
if axVoice.empty?
hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: contact voice phone is missing'
end
axTDD = xContactInfo.xpath('./cnttdd')
unless axTDD.empty?
axTDD.each do |xPhone|
phone = xPhone.text
unless phone.empty?
add_phone(hContact, phone, 'tty')
end
end
end
axFax = xContactInfo.xpath('./cntfax')
unless axFax.empty?
axFax.each do |xPhone|
phone = xPhone.text
unless phone.empty?
add_phone(hContact, phone, 'facsimile')
end
end
end
axEmail = xContactInfo.xpath('./cntemail')
unless axEmail.empty?
axEmail.each do |xEmail|
email = xEmail.text
unless email.empty?
unless hContact[:eMailList].include?(email)
hContact[:eMailList] << email
end
end
end
end
hours = xContactInfo.xpath('./hours').text
unless hours.empty?
unless hContact[:hoursOfService].include?(hours)
hContact[:hoursOfService] << hours
end
end
instruct = xContactInfo.xpath('./cntinst').text
hContact[:contactInstructions] = instruct unless instruct.empty?
Fgdc.set_contact(hContact)
hResponsibility = intMetadataClass.newResponsibility
hParty = intMetadataClass.newParty
hParty[:contactId] = hContact[:contactId]
aContact = Fgdc.find_contact_by_id(hContact[:contactId])
hParty[:contactIndex] = aContact[0]
hParty[:contactType] = aContact[1]
hResponsibility[:parties] << hParty
return hResponsibility
end
end
return nil
end
|