@@ -115,6 +115,7 @@ class EmlImportService {
115
115
def extractContactsFromEml (eml , dataResource ){
116
116
117
117
def contacts = []
118
+ def primaryContacts = []
118
119
119
120
emlFields. each { name , accessor ->
120
121
def val = accessor(eml)
@@ -126,7 +127,7 @@ class EmlImportService {
126
127
// add contacts...
127
128
if (eml. dataset. creator){
128
129
eml. dataset. creator. each {
129
- def contact = addContact (it)
130
+ def contact = addOrUpdateContact (it)
130
131
if (contact){
131
132
contacts << contact
132
133
}
@@ -137,7 +138,7 @@ class EmlImportService {
137
138
&& eml. dataset. metadataProvider. electronicMailAddress != eml. dataset. creator. electronicMailAddress){
138
139
139
140
eml. dataset. metadataProvider. each {
140
- def contact = addContact (it)
141
+ def contact = addOrUpdateContact (it)
141
142
if (contact){
142
143
contacts << contact
143
144
}
@@ -147,26 +148,27 @@ class EmlImportService {
147
148
// Add additional contacts
148
149
if (eml. dataset. contact){
149
150
eml. dataset. contact. each {
150
- def contact = addContact (it)
151
+ def contact = addOrUpdateContact (it)
151
152
if (contact){
152
153
contacts << contact
154
+ primaryContacts << contact
153
155
}
154
156
}
155
157
}
156
158
157
159
if (eml. dataset. associatedParty){
158
160
eml. dataset. associatedParty. each {
159
- def contact = addContact (it)
161
+ def contact = addOrUpdateContact (it)
160
162
if (contact){
161
163
contacts << contact
162
164
}
163
165
}
164
166
}
165
167
166
- contacts
168
+ [ contacts : contacts, primaryContacts : primaryContacts]
167
169
}
168
170
169
- private def addContact (emlElement ) {
171
+ private def addOrUpdateContact (emlElement ) {
170
172
def contact = null
171
173
if (emlElement. electronicMailAddress && ! emlElement. electronicMailAddress. isEmpty()) {
172
174
String email = emlElement. electronicMailAddress. text(). trim()
@@ -185,23 +187,26 @@ class EmlImportService {
185
187
186
188
if (! contact && (hasEmail || hasName)) {
187
189
contact = new Contact ()
188
- contact. firstName = emlElement. individualName. givenName
189
- contact. lastName = emlElement. individualName. surName
190
- // some email has leading/trailing spaces causing the email constrain regexp to fail, lets trim
191
- contact. email = emlElement. electronicMailAddress. text(). trim()
192
- contact. setUserLastModified(collectoryAuthService. username())
193
- Contact . withTransaction {
194
- if (contact. validate()) {
195
- contact. save(flush : true , failOnError : true )
196
- return contact
197
- } else {
198
- contact. errors. each {
199
- log. error(" Problem creating contact: " + it)
200
- }
201
- return null
190
+ }
191
+
192
+ // Update the contact details
193
+ contact. firstName = emlElement. individualName. givenName
194
+ contact. lastName = emlElement. individualName. surName
195
+ // some email has leading/trailing spaces causing the email constrain regexp to fail, lets trim
196
+ contact. email = emlElement. electronicMailAddress. text(). trim()
197
+ contact. setUserLastModified(collectoryAuthService. username())
198
+ Contact . withTransaction {
199
+ if (contact. validate()) {
200
+ contact. save(flush : true , failOnError : true )
201
+ return contact
202
+ } else {
203
+ contact. errors. each {
204
+ log. error(" Problem creating contact: " + it)
202
205
}
206
+ return null
203
207
}
204
208
}
209
+
205
210
contact
206
211
}
207
212
}
0 commit comments