1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.io.berlinModel.in;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.sql.SQLException;
|
14
|
import java.sql.Timestamp;
|
15
|
import java.util.Map;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.joda.time.DateTime;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
21
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
22
|
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
|
23
|
import eu.etaxonomy.cdm.io.common.DbImportBase;
|
24
|
import eu.etaxonomy.cdm.io.common.ICdmIO;
|
25
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
|
26
|
import eu.etaxonomy.cdm.io.common.IPartitionedIO;
|
27
|
import eu.etaxonomy.cdm.io.common.TdwgAreaProvider;
|
28
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
29
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
30
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
31
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
33
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
34
|
import eu.etaxonomy.cdm.model.common.Language;
|
35
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
36
|
import eu.etaxonomy.cdm.model.common.SourcedEntityBase;
|
37
|
import eu.etaxonomy.cdm.model.common.User;
|
38
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
39
|
import eu.etaxonomy.cdm.model.location.Country;
|
40
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
41
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
42
|
import eu.etaxonomy.cdm.model.reference.ISourceable;
|
43
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
44
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
45
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
46
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
47
|
import eu.etaxonomy.cdm.model.term.TermType;
|
48
|
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
49
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
50
|
|
51
|
/**
|
52
|
* @author a.mueller
|
53
|
* @since 20.03.2008
|
54
|
*/
|
55
|
public abstract class BerlinModelImportBase
|
56
|
extends DbImportBase<BerlinModelImportState, BerlinModelImportConfigurator>
|
57
|
implements ICdmIO<BerlinModelImportState>, IPartitionedIO<BerlinModelImportState> {
|
58
|
private static final long serialVersionUID = -4982506434258587864L;
|
59
|
private static final Logger logger = Logger.getLogger(BerlinModelImportBase.class);
|
60
|
|
61
|
public BerlinModelImportBase(String tableName, String pluralString ) {
|
62
|
super(tableName, pluralString);
|
63
|
}
|
64
|
|
65
|
|
66
|
/**
|
67
|
* @return
|
68
|
*/
|
69
|
@Override
|
70
|
protected String getIdQuery(BerlinModelImportState state){
|
71
|
String result = " SELECT " + getTableName() + "id FROM " + getTableName();
|
72
|
return result;
|
73
|
}
|
74
|
|
75
|
|
76
|
protected boolean doIdCreatedUpdatedNotes(BerlinModelImportState state, DescriptionElementBase descriptionElement, ResultSet rs, String id, String namespace) throws SQLException{
|
77
|
boolean success = true;
|
78
|
//id
|
79
|
success &= doId(state, descriptionElement, id, namespace);
|
80
|
//createdUpdateNotes
|
81
|
success &= doCreatedUpdatedNotes(state, descriptionElement, rs);
|
82
|
return success;
|
83
|
}
|
84
|
|
85
|
protected boolean doIdCreatedUpdatedNotes(BerlinModelImportState state, IdentifiableEntity identifiableEntity, ResultSet rs, long id, String namespace, boolean excludeUpdated, boolean excludeNotes)
|
86
|
throws SQLException{
|
87
|
boolean success = true;
|
88
|
//id
|
89
|
success &= doId(state, identifiableEntity, id, namespace);
|
90
|
//createdUpdateNotes
|
91
|
success &= doCreatedUpdatedNotes(state, identifiableEntity, rs, excludeUpdated, excludeNotes);
|
92
|
return success;
|
93
|
}
|
94
|
|
95
|
|
96
|
protected boolean doIdCreatedUpdatedNotes(BerlinModelImportState state, IdentifiableEntity identifiableEntity, ResultSet rs, long id, String namespace)
|
97
|
throws SQLException{
|
98
|
boolean excludeUpdated = false;
|
99
|
return doIdCreatedUpdatedNotes(state, identifiableEntity, rs, id, namespace, excludeUpdated, false);
|
100
|
}
|
101
|
|
102
|
protected boolean doCreatedUpdatedNotes(BerlinModelImportState state, AnnotatableEntity annotatableEntity, ResultSet rs)
|
103
|
throws SQLException{
|
104
|
boolean excludeUpdated = false;
|
105
|
return doCreatedUpdatedNotes(state, annotatableEntity, rs, excludeUpdated, false);
|
106
|
}
|
107
|
|
108
|
protected boolean doCreatedUpdatedNotes(BerlinModelImportState state, AnnotatableEntity annotatableEntity,
|
109
|
ResultSet rs, boolean excludeUpdated, boolean excludeNotes)
|
110
|
throws SQLException{
|
111
|
|
112
|
BerlinModelImportConfigurator config = state.getConfig();
|
113
|
Object createdWhen = rs.getObject("Created_When");
|
114
|
String createdWho = rs.getString("Created_Who");
|
115
|
createdWho = normalizeUsername(state, createdWho);
|
116
|
Object updatedWhen = null;
|
117
|
String updatedWho = null;
|
118
|
if (excludeUpdated == false){
|
119
|
try {
|
120
|
updatedWhen = rs.getObject("Updated_When");
|
121
|
updatedWho = rs.getString("Updated_who");
|
122
|
updatedWho = normalizeUsername(state, updatedWho);
|
123
|
} catch (SQLException e) {
|
124
|
//Table "Name" has no updated when/who
|
125
|
}
|
126
|
}
|
127
|
|
128
|
boolean success = true;
|
129
|
|
130
|
//Created When, Who, Updated When Who
|
131
|
if (config.getEditor() == null || config.getEditor().equals(EDITOR.NO_EDITORS)){
|
132
|
//do nothing
|
133
|
}else if (config.getEditor().equals(EDITOR.EDITOR_AS_ANNOTATION)){
|
134
|
String createdAnnotationString = "Berlin Model record was created By: " + String.valueOf(createdWho) + " (" + String.valueOf(createdWhen) + ") ";
|
135
|
if (updatedWhen != null && updatedWho != null){
|
136
|
createdAnnotationString += " and updated By: " + String.valueOf(updatedWho) + " (" + String.valueOf(updatedWhen) + ")";
|
137
|
}
|
138
|
Annotation annotation = Annotation.NewInstance(createdAnnotationString, Language.DEFAULT());
|
139
|
//TODO make transaction compatible, same as common sec reference
|
140
|
annotation.setCommentator(config.getCommentator());
|
141
|
annotation.setAnnotationType(AnnotationType.TECHNICAL());
|
142
|
annotatableEntity.addAnnotation(annotation);
|
143
|
}else if (config.getEditor().equals(EDITOR.EDITOR_AS_EDITOR)){
|
144
|
User creator;
|
145
|
boolean xmlSourceAdded= addXmlSource(state, annotatableEntity, createdWho, false);
|
146
|
if (xmlSourceAdded){
|
147
|
creator = getXmlImporter(state);
|
148
|
}else{
|
149
|
creator = getUser(state, createdWho);
|
150
|
}
|
151
|
annotatableEntity.setCreatedBy(creator);
|
152
|
|
153
|
User updator;
|
154
|
xmlSourceAdded = addXmlSource(state, annotatableEntity, updatedWho, xmlSourceAdded);
|
155
|
if (xmlSourceAdded){
|
156
|
updator = getXmlImporter(state);
|
157
|
}else{
|
158
|
updator = getUser(state, updatedWho);
|
159
|
}
|
160
|
annotatableEntity.setUpdatedBy(updator);
|
161
|
|
162
|
DateTime created = getDateTime(createdWhen);
|
163
|
DateTime updated = getDateTime(updatedWhen);
|
164
|
annotatableEntity.setCreated(created);
|
165
|
annotatableEntity.setUpdated(updated);
|
166
|
}else {
|
167
|
logger.warn("Editor type not yet implemented: " + config.getEditor());
|
168
|
}
|
169
|
|
170
|
|
171
|
//notes
|
172
|
if (! excludeNotes){
|
173
|
String notes = rs.getString("notes");
|
174
|
doNotes(annotatableEntity, notes);
|
175
|
}
|
176
|
return success;
|
177
|
}
|
178
|
|
179
|
/**
|
180
|
* @param state
|
181
|
* @return
|
182
|
*/
|
183
|
private User getXmlImporter(BerlinModelImportState state) {
|
184
|
return getUser(state, "import to BM");
|
185
|
}
|
186
|
|
187
|
|
188
|
/**
|
189
|
* @param state
|
190
|
* @param annotatableEntity
|
191
|
* @param xmlSourceAdded
|
192
|
* @return
|
193
|
*/
|
194
|
private boolean addXmlSource(BerlinModelImportState state, AnnotatableEntity annotatableEntity, String username, boolean existsAlready) {
|
195
|
if (!state.getConfig().isEuroMed() || !isXmlImport(username)){
|
196
|
return false;
|
197
|
}
|
198
|
if (isXmlImport(username) && existsAlready){
|
199
|
return true;
|
200
|
}
|
201
|
Reference ref = getXmlRef(state, username);
|
202
|
if (annotatableEntity.isInstanceOf(SourcedEntityBase.class)){
|
203
|
SourcedEntityBase<?> sourcedEntity = CdmBase.deproxy(annotatableEntity, SourcedEntityBase.class);
|
204
|
sourcedEntity.addImportSource(null, null, ref, null);
|
205
|
}else if (annotatableEntity.isInstanceOf(DescriptionElementBase.class)){
|
206
|
DescriptionElementBase descriptionElement = CdmBase.deproxy(annotatableEntity, DescriptionElementBase.class);
|
207
|
descriptionElement.addImportSource(null, null, ref, null);
|
208
|
}else{
|
209
|
return false;
|
210
|
}
|
211
|
return true;
|
212
|
}
|
213
|
|
214
|
|
215
|
/**
|
216
|
* @param state
|
217
|
* @param username
|
218
|
* @return
|
219
|
*/
|
220
|
private Reference getXmlRef(BerlinModelImportState state, String username) {
|
221
|
String namespace = "IMPORT USER";
|
222
|
Reference ref = state.getRelatedObject(namespace, username, Reference.class);
|
223
|
if (ref == null){
|
224
|
if (state.getXmlImportRefUuid(username)!= null){
|
225
|
ref = getReferenceService().find(state.getXmlImportRefUuid(username));
|
226
|
}
|
227
|
if (ref == null){
|
228
|
Pager<Reference> pager = getReferenceService().findByTitle(Reference.class, username, MatchMode.EXACT, null, null, null, null, null);
|
229
|
if (pager.getCount()>0){
|
230
|
ref = pager.getRecords().get(0);
|
231
|
if (pager.getCount()>1){
|
232
|
logger.warn("More then 1 reference found for " + username);
|
233
|
}
|
234
|
}
|
235
|
}
|
236
|
if (ref == null){
|
237
|
ref = ReferenceFactory.newDatabase();
|
238
|
ref.setTitleCache(username, true);
|
239
|
ref.setTitle(username);
|
240
|
getReferenceService().save(ref);
|
241
|
}
|
242
|
state.addRelatedObject(namespace, username, ref);
|
243
|
state.putXmlImportRefUuid(username, ref.getUuid());
|
244
|
|
245
|
}
|
246
|
return ref;
|
247
|
}
|
248
|
|
249
|
|
250
|
/**
|
251
|
* @param username
|
252
|
* @return
|
253
|
*/
|
254
|
private boolean isXmlImport(String username) {
|
255
|
if (username == null){
|
256
|
return false;
|
257
|
}
|
258
|
return username.matches(".*\\.xml")
|
259
|
|| username.equals("J.Li: import from pandora")
|
260
|
|| username.equals("J.Li imported from pandora")
|
261
|
||username.equals("Import from Kew Checklist 2010")
|
262
|
||username.equals("Import from ILDIS 2010");
|
263
|
}
|
264
|
|
265
|
|
266
|
private DateTime getDateTime(Object timeString){
|
267
|
if (timeString == null){
|
268
|
return null;
|
269
|
}
|
270
|
DateTime dateTime = null;
|
271
|
if (timeString instanceof Timestamp){
|
272
|
Timestamp timestamp = (Timestamp)timeString;
|
273
|
dateTime = new DateTime(timestamp);
|
274
|
}else{
|
275
|
logger.warn("time ("+timeString+") is not a timestamp. Datetime set to current date. ");
|
276
|
dateTime = new DateTime();
|
277
|
}
|
278
|
return dateTime;
|
279
|
}
|
280
|
|
281
|
/**
|
282
|
* @param state
|
283
|
* @param newTaxonId
|
284
|
* @param taxonMap
|
285
|
* @param factId
|
286
|
* @return
|
287
|
*/
|
288
|
protected Taxon getTaxon(BerlinModelImportState state, int taxonId, Map<String, TaxonBase> taxonMap, int factId) {
|
289
|
TaxonBase<?> taxonBase = taxonMap.get(String.valueOf(taxonId));
|
290
|
|
291
|
//TODO for testing
|
292
|
// if (taxonBase == null && ! state.getConfig().isDoTaxa()){
|
293
|
// taxonBase = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
|
294
|
// }
|
295
|
|
296
|
Taxon taxon;
|
297
|
if ( taxonBase instanceof Taxon ) {
|
298
|
taxon = (Taxon) taxonBase;
|
299
|
} else if (taxonBase != null) {
|
300
|
logger.warn("TaxonBase (" + taxonId + ") for Fact(Specimen) with factId " + factId + " was not of type Taxon but: " + taxonBase.getClass().getSimpleName());
|
301
|
return null;
|
302
|
} else {
|
303
|
logger.warn("TaxonBase (" + taxonId + ") for Fact(Specimen) with factId " + factId + " is null.");
|
304
|
return null;
|
305
|
}
|
306
|
return taxon;
|
307
|
}
|
308
|
|
309
|
|
310
|
/**
|
311
|
* Searches first in the detail maps then in the ref maps for a reference.
|
312
|
* Returns the reference as soon as it finds it in one of the map, according
|
313
|
* to the order of the map.
|
314
|
* If nomRefDetailFk is <code>null</code> no search on detail maps is performed.
|
315
|
* If one of the maps is <code>null</code> no search on the according map is
|
316
|
* performed. <BR>
|
317
|
* You may define the order of search by the order you pass the maps but
|
318
|
* make sure to always pass the detail maps first.
|
319
|
* @param firstDetailMap
|
320
|
* @param secondDetailMap
|
321
|
* @param firstRefMap
|
322
|
* @param secondRefMap
|
323
|
* @param nomRefDetailFk
|
324
|
* @param nomRefFk
|
325
|
* @return
|
326
|
*/
|
327
|
protected Reference getReferenceFromMaps(
|
328
|
Map<String, Reference> detailMap,
|
329
|
Map<String, Reference> refMap,
|
330
|
String nomRefDetailFk,
|
331
|
String nomRefFk) {
|
332
|
Reference ref = null;
|
333
|
if (detailMap != null){
|
334
|
ref = detailMap.get(nomRefDetailFk);
|
335
|
}
|
336
|
if (ref == null){
|
337
|
ref = refMap.get(nomRefFk);
|
338
|
}
|
339
|
return ref;
|
340
|
}
|
341
|
|
342
|
|
343
|
/**
|
344
|
* Searches for a reference in the first detail map. If it does not exist it
|
345
|
* searches in the second detail map. Returns null if it does not exist in any map.
|
346
|
* A map may be <code>null</code> to avoid search on this map.
|
347
|
* @param secondDetailMap
|
348
|
* @param firstDetailMap
|
349
|
* @param nomRefDetailFk
|
350
|
* @return
|
351
|
*/
|
352
|
private Reference getReferenceDetailFromMaps(Map<String, Reference> firstDetailMap, Map<String, Reference> secondDetailMap, String nomRefDetailFk) {
|
353
|
Reference result = null;
|
354
|
if (nomRefDetailFk != null){
|
355
|
//get ref
|
356
|
if (firstDetailMap != null){
|
357
|
result = firstDetailMap.get(nomRefDetailFk);
|
358
|
}
|
359
|
if (result == null && secondDetailMap != null){
|
360
|
result = secondDetailMap.get(nomRefDetailFk);
|
361
|
}
|
362
|
}
|
363
|
return result;
|
364
|
}
|
365
|
|
366
|
protected NamedArea getOtherAreas(BerlinModelImportState state, String emCodeString, String tdwgCodeString) {
|
367
|
String em = CdmUtils.Nz(emCodeString).trim();
|
368
|
String tdwg = CdmUtils.Nz(tdwgCodeString).trim();
|
369
|
//Cichorieae + E+M
|
370
|
if ("EM".equals(em)){
|
371
|
return getNamedArea(state, BerlinModelTransformer.euroMedUuid, "Euro+Med", "Euro+Med area", "EM", null, null);
|
372
|
}else if("Rf".equals(em)){
|
373
|
return Country.RUSSIANFEDERATION();
|
374
|
|
375
|
}else if("KRY-OO;UKR-UK".equals(tdwg)){
|
376
|
return Country.UKRAINE();
|
377
|
|
378
|
}else if("TCS-AZ;TCS-NA".equals(tdwg)){
|
379
|
return Country.AZERBAIJANREPUBLICOF();
|
380
|
}else if("TCS-AB;TCS-AD;TCS-GR".equals(tdwg)){
|
381
|
return Country.GEORGIA();
|
382
|
|
383
|
}else if("Cc".equals(em)){
|
384
|
return getNamedArea(state, BerlinModelTransformer.uuidCaucasia, "Caucasia (Ab + Ar + Gg + Rf(CS))", "Euro+Med area 'Caucasia (Ab + Ar + Gg + Rf(CS))'", "Cc", null, null);
|
385
|
}
|
386
|
|
387
|
//E+M
|
388
|
else if("EUR".equals(em)){
|
389
|
return TdwgAreaProvider.getAreaByTdwgAbbreviation("1");
|
390
|
}else if("14".equals(em)){
|
391
|
return TdwgAreaProvider.getAreaByTdwgAbbreviation("14");
|
392
|
}else if("21".equals(em)){
|
393
|
return TdwgAreaProvider.getAreaByTdwgAbbreviation("21"); // Macaronesia
|
394
|
}else if("33".equals(em)){
|
395
|
return TdwgAreaProvider.getAreaByTdwgAbbreviation("33");
|
396
|
|
397
|
}else if("SM".equals(em)){
|
398
|
return getNamedArea(state, BerlinModelTransformer.uuidSerbiaMontenegro, "Serbia & Montenegro", "Euro+Med area 'Serbia & Montenegro'", "SM", NamedAreaType.ADMINISTRATION_AREA(), null);
|
399
|
}else if("Sr".equals(em)){
|
400
|
return getNamedArea(state, BerlinModelTransformer.uuidSerbia, "Serbia", "Euro+Med area 'Serbia' (including Kosovo and Vojvodina)", "Sr", NamedAreaType.ADMINISTRATION_AREA(), null);
|
401
|
|
402
|
|
403
|
//see #2769
|
404
|
}else if("Rs".equals(em)){
|
405
|
return getNamedArea(state, BerlinModelTransformer.uuidUssr, "Former USSR", "Euro+Med area 'Former USSR'", "Rs", NamedAreaType.ADMINISTRATION_AREA(), null);
|
406
|
}else if("Rs(N)".equals(em)){
|
407
|
return getNamedArea(state, BerlinModelTransformer.uuidRussiaNorthern, "Russia Northern", "Euro+Med area 'Russia Northern'", "Rs(N)", null, null);
|
408
|
}else if("Rs(B)".equals(em)){
|
409
|
return getNamedArea(state, BerlinModelTransformer.uuidRussiaBaltic, "Russia Baltic", "Euro+Med area 'Russia Baltic'", "Rs(B)", null, null);
|
410
|
}else if("Rs(C)".equals(em)){
|
411
|
return getNamedArea(state, BerlinModelTransformer.uuidRussiaCentral, "Russia Central", "Euro+Med area 'Russia Central'", "Rs(C)", null, null);
|
412
|
}else if("Rs(W)".equals(em)){
|
413
|
return getNamedArea(state, BerlinModelTransformer.uuidRussiaSouthWest, "Russia Southwest", "Euro+Med area 'Russia Southwest'", "Rs(W)", null, null);
|
414
|
}else if("Rs(E)".equals(em)){
|
415
|
return getNamedArea(state, BerlinModelTransformer.uuidRussiaSouthEast, "Russia Southeast", "Euro+Med area 'Russia Southeast'", "Rs(E)", null, null);
|
416
|
|
417
|
//see #2770
|
418
|
}else if("AE".equals(em)){
|
419
|
return getNamedArea(state, BerlinModelTransformer.uuidEastAegeanIslands, "East Aegean Islands", "Euro+Med area 'East Aegean Islands'", "AE", null, null);
|
420
|
}else if("AE(T)".equals(em)){
|
421
|
return getNamedArea(state, BerlinModelTransformer.uuidTurkishEastAegeanIslands, "Turkish East Aegean Islands", "Euro+Med area 'Turkish East Aegean Islands'", "AE(T)", null, null);
|
422
|
}else if("Tu".equals(em)){
|
423
|
return getNamedArea(state, BerlinModelTransformer.uuidTurkey, "Turkey", "Euro+Med area 'Turkey' (without AE(T))", "Tu", null, null);
|
424
|
|
425
|
//TODO Azores, Canary Is.
|
426
|
}else if("Md(D)".equals(em)){
|
427
|
return getNamedArea(state, BerlinModelTransformer.uuidDesertas, "Desertas", "Euro+Med area 'Desertas'", "Md(D)", null, null);
|
428
|
}else if("Md(M)".equals(em)){
|
429
|
return getNamedArea(state, BerlinModelTransformer.uuidMadeira, "Madeira", "Euro+Med area 'Madeira'", "Md(M)", null, null);
|
430
|
}else if("Md(P)".equals(em)){
|
431
|
return getNamedArea(state, BerlinModelTransformer.uuidPortoSanto, "Porto Santo", "Euro+Med area 'Porto Santo'", "Md(P)", null, null);
|
432
|
//Azores
|
433
|
}else if("Az(L)".equals(em)){
|
434
|
return getNamedArea(state, BerlinModelTransformer.uuidFlores, "Flores", "Euro+Med area 'Flores'", "Az(L)", null, null);
|
435
|
}else if("Az(C)".equals(em)){
|
436
|
return getNamedArea(state, BerlinModelTransformer.uuidCorvo, "Corvo", "Euro+Med area 'Corvo'", "Az(C)", null, null);
|
437
|
}else if("Az(F)".equals(em)){
|
438
|
return getNamedArea(state, BerlinModelTransformer.uuidFaial, "Faial", "Euro+Med area 'Faial'", "Az(F)", null, null);
|
439
|
}else if("Az(G)".equals(em)){
|
440
|
return getNamedArea(state, BerlinModelTransformer.uuidGraciosa, "Graciosa", "Euro+Med area 'Graciosa'", "Az(G)", null, null);
|
441
|
}else if("Az(J)".equals(em)){
|
442
|
return getNamedArea(state, BerlinModelTransformer.uuidSaoJorge, "S\u00E3o Jorge", "Euro+Med area 'S\u00E3o Jorge'", "Az(J)", null, null);
|
443
|
}else if("Az(M)".equals(em)){
|
444
|
return getNamedArea(state, BerlinModelTransformer.uuidSaoMiguel, "S\u00E3o Miguel", "Euro+Med area 'S\u00E3o Miguel'", "Az(M)", null, null);
|
445
|
}else if("Az(P)".equals(em)){
|
446
|
return getNamedArea(state, BerlinModelTransformer.uuidPico, "Pico", "Euro+Med area 'Pico'", "Az(P)", null, null);
|
447
|
}else if("Az(S)".equals(em)){
|
448
|
return getNamedArea(state, BerlinModelTransformer.uuidSantaMaria, "Santa Maria", "Euro+Med area 'Santa Maria'", "Az(S)", null, null);
|
449
|
}else if("Az(T)".equals(em)){
|
450
|
return getNamedArea(state, BerlinModelTransformer.uuidTerceira, "Terceira", "Euro+Med area 'Terceira'", "Az(T)", null, null);
|
451
|
//Canary Islands
|
452
|
}else if("Ca(C)".equals(em)){
|
453
|
return getNamedArea(state, BerlinModelTransformer.uuidGranCanaria, "Gran Canaria", "Euro+Med area 'Gran Canaria'", "Ca(C)", null, null);
|
454
|
}else if("Ca(F)".equals(em)){
|
455
|
return getNamedArea(state, BerlinModelTransformer.uuidFuerteventura, "Fuerteventura with Lobos", "Euro+Med area 'Fuerteventura with Lobos'", "Ca(F)", null, null);
|
456
|
}else if("Ca(G)".equals(em)){
|
457
|
return getNamedArea(state, BerlinModelTransformer.uuidGomera, "Gomera", "Euro+Med area 'Gomera'", "Ca(G)", null, null);
|
458
|
}else if("Ca(H)".equals(em)){
|
459
|
return getNamedArea(state, BerlinModelTransformer.uuidHierro, "Hierro", "Euro+Med area 'Hierro'", "Ca(H)", null, null);
|
460
|
}else if("Ca(L)".equals(em)){
|
461
|
return getNamedArea(state, BerlinModelTransformer.uuidLanzaroteWithGraciosa, "Lanzarote with Graciosa", "Euro+Med area 'Lanzarote with Graciosa'", "Ca(L)", null, null);
|
462
|
}else if("Ca(P)".equals(em)){
|
463
|
return getNamedArea(state, BerlinModelTransformer.uuidLaPalma, "La Palma", "Euro+Med area 'La Palma'", "Ca(P)", null, null);
|
464
|
}else if("Ca(T)".equals(em)){
|
465
|
return getNamedArea(state, BerlinModelTransformer.uuidTenerife, "Tenerife", "Euro+Med area 'Tenerife'", "Ca(T)", null, null);
|
466
|
//Baleares
|
467
|
}else if("Bl(I)".equals(em)){
|
468
|
return getNamedArea(state, BerlinModelTransformer.uuidIbizaWithFormentera, "Ibiza with Formentera", "Euro+Med area 'Ibiza with Formentera'", "Bl(I)", null, null);
|
469
|
}else if("Bl(M)".equals(em)){
|
470
|
return getNamedArea(state, BerlinModelTransformer.uuidTerceira, "Mallorca", "Euro+Med area 'Mallorca'", "Bl(M)", null, null);
|
471
|
}else if("Bl(N)".equals(em)){
|
472
|
return getNamedArea(state, BerlinModelTransformer.uuidTerceira, "Menorca", "Euro+Med area 'Menorca'", "Bl(N)", null, null);
|
473
|
}
|
474
|
|
475
|
logger.warn("Area(em: '" + em + "', tdwg: '" + tdwg +"') could not be found");
|
476
|
|
477
|
return null;
|
478
|
}
|
479
|
|
480
|
/**
|
481
|
* @return
|
482
|
*/
|
483
|
protected TermVocabulary<MarkerType> getEuroMedMarkerTypeVoc() {
|
484
|
TermVocabulary<MarkerType> markerTypeVoc = getVocabulary(TermType.MarkerType, BerlinModelTransformer.uuidVocEMMarkerType,
|
485
|
"Euro+Med marker type vocabulary", "E+M marker types", null, null, false, MarkerType.COMPLETE());
|
486
|
return markerTypeVoc;
|
487
|
}
|
488
|
|
489
|
|
490
|
/**
|
491
|
* @param sourceReference
|
492
|
* @return
|
493
|
*/
|
494
|
protected Reference getSourceReference(Reference sourceReference) {
|
495
|
Reference persistentSourceReference = getReferenceService().find(sourceReference.getUuid()); //just to be sure
|
496
|
if (persistentSourceReference != null){
|
497
|
sourceReference = persistentSourceReference;
|
498
|
}
|
499
|
return sourceReference;
|
500
|
}
|
501
|
|
502
|
protected static <T extends IdentifiableSource> boolean importSourceExists(ISourceable<T> sourceable, String idInSource,
|
503
|
String namespace, Reference ref) {
|
504
|
for (T source : sourceable.getSources()){
|
505
|
if (CdmUtils.nullSafeEqual(namespace, source.getIdNamespace()) &&
|
506
|
CdmUtils.nullSafeEqual(idInSource, source.getIdInSource()) &&
|
507
|
CdmUtils.nullSafeEqual(ref, source.getCitation())){
|
508
|
return true;
|
509
|
}
|
510
|
}
|
511
|
return false;
|
512
|
}
|
513
|
|
514
|
/**
|
515
|
* @param state
|
516
|
* @param username
|
517
|
* @return
|
518
|
*/
|
519
|
protected String normalizeUsername(BerlinModelImportState state, String username) {
|
520
|
if (username == null){
|
521
|
return null;
|
522
|
}else{
|
523
|
username = username.trim();
|
524
|
if (state.getConfig().isEuroMed()){
|
525
|
if (username.matches("[A-Za-z]+[7-9][0-9]")){
|
526
|
username = username.substring(0, username.length()-2);
|
527
|
}else if(username.matches("(mariam[1-4]|palermo|palma|paltar)")){
|
528
|
username = "mariam";
|
529
|
}
|
530
|
if(username.matches("kapet")){
|
531
|
username = "kpet";
|
532
|
}
|
533
|
}
|
534
|
return username;
|
535
|
}
|
536
|
}
|
537
|
|
538
|
}
|