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