Revision 94853726
Added by Andreas Müller over 5 years ago
app-import/src/main/java/eu/etaxonomy/cdm/app/greece/GreeceImageActivator.java | ||
---|---|---|
39 | 39 |
private static final Logger logger = Logger.getLogger(GreeceImageActivator.class); |
40 | 40 |
|
41 | 41 |
|
42 |
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
|
42 |
static final ICdmDataSource cdmDestination = CdmDestinations.localH2(); |
|
43 | 43 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test(); |
44 |
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_greece_checklist_production(); |
|
44 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_greece_checklist_production(); |
|
45 |
|
|
46 |
// private static final UUID sourceUuid = UUID.fromString("1964a2e5-9ec3-411e-a36a-44279230c4b9"); |
|
47 |
private static final UUID sourceUuid = UUID.fromString("3430d54b-1a51-4a0d-9d9f-38178f1e4de3"); |
|
45 | 48 |
|
46 |
// private static final UUID sourceUuid = UUID.fromString("418b5885-08fb-4f1e-ac94-8f5c84b1683d"); |
|
47 |
private static final UUID sourceUuid = UUID.fromString("c3d300f0-86ef-4c65-8727-c594035ed7a7"); |
|
48 | 49 |
// private static final String fileName = "20171107_sent_1332_images.xlsx"; |
49 |
private static final String fileName = "20171110_Turland_433_others_59.xlsx"; |
|
50 |
// private static final String fileName = "20171110_Turland_433_others_59.xlsx"; |
|
51 |
// private static final String fileName = "20180824_Metadata_Zarkos_images_July_2018_b.xlsx"; |
|
52 |
// private static final String fileName = "2018_Aug_images.xlsx"; |
|
53 |
private static final String fileName = "20180925_FOG_images.xlsx"; |
|
50 | 54 |
|
55 |
// NOTE!!: Darauf achten, dass die Header case sensitiv sind und keine Leerzeichen am Ende sein sollten, trim funktioniert seltsamerweise nicht immer |
|
51 | 56 |
|
52 | 57 |
//check - import |
53 | 58 |
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK; |
app-import/src/main/java/eu/etaxonomy/cdm/app/greece/GreeceWillingActivator.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 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 |
package eu.etaxonomy.cdm.app.greece; |
|
10 |
|
|
11 |
import java.net.URI; |
|
12 |
import java.util.UUID; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
|
|
16 |
import eu.etaxonomy.cdm.app.common.CdmDestinations; |
|
17 |
import eu.etaxonomy.cdm.database.DatabaseTypeEnum; |
|
18 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
19 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
20 |
import eu.etaxonomy.cdm.io.common.CdmDefaultImport; |
|
21 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK; |
|
22 |
import eu.etaxonomy.cdm.io.common.ImportResult; |
|
23 |
import eu.etaxonomy.cdm.io.greece.GreeceWillingImportConfigurator; |
|
24 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
25 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
26 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
27 |
|
|
28 |
/** |
|
29 |
* @author a.mueller |
|
30 |
* @since 21.08.2018 |
|
31 |
* |
|
32 |
*/ |
|
33 |
public class GreeceWillingActivator { |
|
34 |
@SuppressWarnings("unused") |
|
35 |
private static final Logger logger = Logger.getLogger(GreeceWillingActivator.class); |
|
36 |
|
|
37 |
|
|
38 |
static final ICdmDataSource cdmDestination = CdmDestinations.localH2(); |
|
39 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_greece_checklist_production(); |
|
40 |
|
|
41 |
private static final UUID sourceUuid = UUID.fromString("b96b8a10-e2a5-4a01-b2f2-435a59a7a269"); |
|
42 |
|
|
43 |
private static final String fileName = "WillingImport.xslx"; |
|
44 |
|
|
45 |
private void doImport(ICdmDataSource cdmDestination){ |
|
46 |
|
|
47 |
DbSchemaValidation schemaVal = cdmDestination.getDatabaseType() == DatabaseTypeEnum.H2 ? DbSchemaValidation.CREATE : DbSchemaValidation.VALIDATE; |
|
48 |
URI source = greekChecklist(); //just any |
|
49 |
//make Source |
|
50 |
GreeceWillingImportConfigurator config = GreeceWillingImportConfigurator.NewInstance(source, cdmDestination); |
|
51 |
config.setCheck(CHECK.IMPORT_WITHOUT_CHECK); |
|
52 |
config.setDbSchemaValidation(schemaVal); |
|
53 |
config.setSourceReference(getSourceReference()); |
|
54 |
config.setNomenclaturalCode(NomenclaturalCode.ICNAFP); |
|
55 |
|
|
56 |
CdmDefaultImport<GreeceWillingImportConfigurator> myImport = new CdmDefaultImport<>(); |
|
57 |
ImportResult result = myImport.invoke(config); |
|
58 |
System.out.println(result.createReport()); |
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
|
|
63 |
private URI greekChecklist(){ |
|
64 |
return URI.create("file:////BGBM-PESIHPC/Greece/" + fileName); |
|
65 |
} |
|
66 |
|
|
67 |
|
|
68 |
private Reference getSourceReference(){ |
|
69 |
Reference result = ReferenceFactory.newDatabase(); |
|
70 |
// xx; |
|
71 |
result.setTitle(fileName); |
|
72 |
result.setUuid(sourceUuid); |
|
73 |
|
|
74 |
return result; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* @param args |
|
79 |
*/ |
|
80 |
public static void main(String[] args) { |
|
81 |
GreeceWillingActivator me = new GreeceWillingActivator(); |
|
82 |
me.doImport(cdmDestination); |
|
83 |
System.exit(0); |
|
84 |
} |
|
85 |
|
|
86 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelAreaImport.java | ||
---|---|---|
68 | 68 |
" SELECT AreaId " |
69 | 69 |
+ " FROM " + getTableName(); |
70 | 70 |
if (state.getConfig().isEuroMed()){ |
71 |
result += " WHERE AreaID NOT IN (1, 21, 650, 653, 1718, 654) "; //#3986 |
|
71 |
result += " WHERE AreaID NOT IN (1, 21, 650, 653, 1718, 654, 646, 647) "; //#3986
|
|
72 | 72 |
} |
73 | 73 |
return result; |
74 | 74 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelOccurrenceImport.java | ||
---|---|---|
81 | 81 |
String emCode = config.isIncludesAreaEmCode()? ", ar.EMCode" : ""; |
82 | 82 |
String strQuery = //DISTINCT because otherwise emOccurrenceSource creates multiple records for a single distribution |
83 | 83 |
" SELECT DISTINCT pt.RIdentifier AS taxonId, occ.OccurrenceId, occ.Native, occ.Introduced, " + |
84 |
" occ.Cultivated, occ.WorldDistCompl, occ.Notes occNotes, " + |
|
84 |
" occ.Cultivated, occ.StatusUnknown, occ.WorldDistCompl, occ.Notes occNotes, " +
|
|
85 | 85 |
" sumcat.emOccurSumCatId, sumcat.Short, sumcat.Description, " + |
86 | 86 |
" sumcat.OutputCode, ar.AreaId, ar.TDWGCode " + emCode + |
87 | 87 |
" FROM emOccurrence occ " + |
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelTaxonRelationImport.java | ||
---|---|---|
34 | 34 |
import org.springframework.stereotype.Component; |
35 | 35 |
import org.springframework.transaction.TransactionStatus; |
36 | 36 |
|
37 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
37 | 38 |
import eu.etaxonomy.cdm.common.ResultWrapper; |
38 | 39 |
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer; |
39 | 40 |
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelTaxonRelationImportValidator; |
... | ... | |
43 | 44 |
import eu.etaxonomy.cdm.model.common.AnnotatableEntity; |
44 | 45 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
45 | 46 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
47 |
import eu.etaxonomy.cdm.model.name.NameRelationshipType; |
|
48 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus; |
|
49 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType; |
|
50 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
|
46 | 51 |
import eu.etaxonomy.cdm.model.reference.Reference; |
52 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
47 | 53 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
48 | 54 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
49 | 55 |
import eu.etaxonomy.cdm.model.taxon.SynonymType; |
... | ... | |
53 | 59 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
54 | 60 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
55 | 61 |
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException; |
62 |
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl; |
|
63 |
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser; |
|
56 | 64 |
|
57 | 65 |
/** |
58 | 66 |
* @author a.mueller |
... | ... | |
65 | 73 |
private static final Logger logger = Logger.getLogger(BerlinModelTaxonRelationImport.class); |
66 | 74 |
|
67 | 75 |
public static final String TREE_NAMESPACE = "PTRefFk"; |
76 |
private static final Integer AUCT_REF_ID = 5959; |
|
68 | 77 |
|
69 | 78 |
private static int modCount = 30000; |
70 | 79 |
private static final String pluralString = "taxon relations"; |
... | ... | |
253 | 262 |
int relPTaxonId = rs.getInt("RelPTaxonId"); |
254 | 263 |
Integer taxon1Id = nullSafeInt(rs, "taxon1Id"); |
255 | 264 |
Integer taxon2Id = nullSafeInt(rs, "taxon2Id"); |
265 |
Integer ptRefFk1 = nullSafeInt(rs, "PTRefFk1"); |
|
266 |
|
|
256 | 267 |
int relQualifierFk = -1; |
257 | 268 |
try { |
258 | 269 |
Integer relRefFk = nullSafeInt(rs,"relRefFk"); |
... | ... | |
289 | 300 |
if (relQualifierFk == TAX_REL_IS_INCLUDED_IN){ |
290 | 301 |
taxonRelationship = makeTaxonomicallyIncluded(state, classificationMap, treeRefFk, fromTaxon, toTaxon, citation, microcitation); |
291 | 302 |
}else if (relQualifierFk == TAX_REL_IS_MISAPPLIED_NAME_OF){ |
292 |
taxonRelationship = toTaxon.addMisappliedName(fromTaxon, citation, microcitation); |
|
303 |
boolean isProParte = "p.p.".equals(notes); |
|
304 |
if (isProParte){ |
|
305 |
notes = null; |
|
306 |
} |
|
307 |
boolean isDoubtful = "?".equals(notes); |
|
308 |
if (isDoubtful){ |
|
309 |
notes = null; |
|
310 |
} |
|
311 |
|
|
312 |
if (notes!= null && notes.startsWith("{non ") && notes.endsWith("}")){ |
|
313 |
notes = notes.substring(1, notes.length() - 1); |
|
314 |
} |
|
315 |
//handle auct. author |
|
316 |
if (fromTaxon.getSec() == null || fromTaxon.getSec().getTitleCache().startsWith("auct.")){ |
|
317 |
String existingSecTitle = fromTaxon.getSec() == null ? null : fromTaxon.getSec().getTitleCache().trim(); |
|
318 |
String existingAppendedPhrase = fromTaxon.getAppendedPhrase(); |
|
319 |
if (fromTaxon.getSec() == null && isBlank(existingAppendedPhrase)){ |
|
320 |
existingAppendedPhrase = "auct."; |
|
321 |
} |
|
322 |
fromTaxon.setSec(null); |
|
323 |
if (isNotBlank(existingAppendedPhrase) && isNotBlank(notes)){ |
|
324 |
logger.warn("Misapplied name has >1 MA relation with a note, RelId: " + relPTaxonId); |
|
325 |
} |
|
326 |
|
|
327 |
String newAppendedPhrase = CdmUtils.concat(", ", existingSecTitle, notes); |
|
328 |
fromTaxon.setAppendedPhrase(CdmUtils.concat("; ", existingAppendedPhrase, newAppendedPhrase)); |
|
329 |
if (isBlank(fromTaxon.getAppendedPhrase())){ |
|
330 |
logger.warn("Appended phrase is empty. This is probably not correct. RelID: " + relPTaxonId); |
|
331 |
}else if ("auct.".equals(fromTaxon.getAppendedPhrase())){ |
|
332 |
fromTaxon.setAppendedPhrase(null); |
|
333 |
} |
|
334 |
notes = null; |
|
335 |
}else if (notes != null && notes.startsWith("non ")){ |
|
336 |
fromTaxon.setAppendedPhrase(CdmUtils.concat(", ", fromTaxon.getAppendedPhrase(), notes)); |
|
337 |
notes = null; |
|
338 |
} |
|
339 |
|
|
340 |
if (isProParte){ |
|
341 |
taxonRelationship = toTaxon.addProParteMisappliedName(fromTaxon, citation, microcitation); |
|
342 |
}else{ |
|
343 |
taxonRelationship = toTaxon.addMisappliedName(fromTaxon, citation, microcitation); |
|
344 |
} |
|
345 |
if (isDoubtful){ |
|
346 |
((TaxonRelationship)taxonRelationship).setDoubtful(true); |
|
347 |
} |
|
293 | 348 |
}else if (relQualifierFk == TAX_REL_IS_PROPARTE_SYN_OF || |
294 | 349 |
//TODO homo/hetero |
295 | 350 |
relQualifierFk == TAX_REL_IS_PROPARTE_HOMOTYPIC_SYNONYM_OF || |
... | ... | |
326 | 381 |
success = false; |
327 | 382 |
logger.warn("Synonym relationship type not yet implemented: " + relQualifierFk); |
328 | 383 |
} |
384 |
// |
|
385 |
notes = handleSynonymNotes(state, toTaxon, synonym, notes, relPTaxonId); |
|
329 | 386 |
}else if (isConceptRelationship){ |
330 | 387 |
ResultWrapper<Boolean> isInverse = ResultWrapper.NewInstance(false); |
331 | 388 |
ResultWrapper<Boolean> isDoubtful = ResultWrapper.NewInstance(false); |
... | ... | |
358 | 415 |
success = false; |
359 | 416 |
} |
360 | 417 |
|
361 |
if (taxonRelationship != null){ |
|
418 |
if (taxonRelationship != null && isNotBlank(notes)){
|
|
362 | 419 |
doNotes(taxonRelationship, notes); |
363 |
}else if (isNotBlank(notes)){ |
|
364 |
logger.warn("Notes for synonym relationship or unknown taxon relationship not handled. RelID: " + relPTaxonId + ". Note: " + notes); |
|
420 |
} |
|
421 |
if (isNotBlank(notes)){ |
|
422 |
logger.warn("Notes in RelPTaxon should all be handled explicitly and should not exist as notes anymore. RelID: " + relPTaxonId + ". Note: " + notes); |
|
365 | 423 |
} |
366 | 424 |
taxaToSave.add(taxon2); |
367 | 425 |
|
... | ... | |
396 | 454 |
} |
397 | 455 |
|
398 | 456 |
|
399 |
private void handleAllRelatedTaxa(BerlinModelImportState state, Taxon taxon, Map<Integer, Classification> classificationMap, Integer secRefFk) { |
|
457 |
/** |
|
458 |
* @param toTaxon |
|
459 |
* @param synonym |
|
460 |
* @param notes |
|
461 |
* @return |
|
462 |
*/ |
|
463 |
private String handleSynonymNotes(BerlinModelImportState state, Taxon toTaxon, Synonym synonym, String notes, int relId) { |
|
464 |
if (state.getConfig().isEuroMed() && isNotBlank(notes)){ |
|
465 |
notes = notes.trim(); |
|
466 |
if (notes.startsWith("[non ") && notes.endsWith("]")){ |
|
467 |
notes = notes.substring(5, notes.length()-1).trim(); |
|
468 |
String[] splits = notes.split(", nec "); |
|
469 |
for (String split : splits){ |
|
470 |
String nameStr = split.replace("<i>", "").replace("</i>", ""); |
|
471 |
NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance(); |
|
472 |
TaxonName name; |
|
473 |
NomenclaturalStatusType status = null; |
|
474 |
if (nameStr.endsWith(", nom. rej.") || nameStr.endsWith(", nom. cons.")||nameStr.endsWith(", nom. illeg.")){ |
|
475 |
String statusStr = nameStr.endsWith(", nom. rej.")? ", nom. rej.": |
|
476 |
nameStr.endsWith(", nom. cons.")? ", nom. cons.": |
|
477 |
", nom. illeg."; |
|
478 |
nameStr = nameStr.replace(statusStr, ""); |
|
479 |
statusStr = statusStr.replace(", ", ""); |
|
480 |
try { |
|
481 |
status = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusStr, null); |
|
482 |
} catch (UnknownCdmTypeException e) { |
|
483 |
logger.warn("NomStatusType not recognized: "+ statusStr + ", RelId: " + relId); |
|
484 |
} |
|
485 |
} |
|
486 |
|
|
487 |
if (nameStr.contains(",") || nameStr.contains(" in ") ){ |
|
488 |
name = parser.parseReferencedName(nameStr, state.getConfig().getNomenclaturalCode(), null); |
|
489 |
}else if (nameStr.matches(".*\\s\\d{4}")){ |
|
490 |
String nameStr2 = nameStr.substring(0, nameStr.length() - 5).trim(); |
|
491 |
String yearStr = nameStr.substring(nameStr.length()-4); |
|
492 |
name = (TaxonName)parser.parseFullName(nameStr2, state.getConfig().getNomenclaturalCode(), null); |
|
493 |
Reference nomRef = name.getNomenclaturalReference(); |
|
494 |
if (nomRef == null){ |
|
495 |
nomRef = ReferenceFactory.newGeneric(); |
|
496 |
name.setNomenclaturalReference(nomRef); |
|
497 |
} |
|
498 |
nomRef.setDatePublished(TimePeriodParser.parseStringVerbatim(yearStr)); |
|
499 |
}else if (nameStr.endsWith(" 1831-1832")){ |
|
500 |
String nameStr2 = nameStr.substring(0, nameStr.length() - 10).trim(); |
|
501 |
name = (TaxonName)parser.parseFullName(nameStr2, state.getConfig().getNomenclaturalCode(), null); |
|
502 |
Reference nomRef = name.getNomenclaturalReference(); |
|
503 |
if (nomRef == null){ |
|
504 |
nomRef = ReferenceFactory.newGeneric(); |
|
505 |
name.setNomenclaturalReference(nomRef); |
|
506 |
} |
|
507 |
nomRef.setDatePublished(TimePeriodParser.parseStringVerbatim("1831-1832")); |
|
508 |
}else{ |
|
509 |
name = parser.parseReferencedName(nameStr, state.getConfig().getNomenclaturalCode(), null); |
|
510 |
} |
|
511 |
if (name.isProtectedTitleCache() || name.isProtectedNameCache() |
|
512 |
|| name.getNomenclaturalReference() != null && (name.getNomenclaturalReference().isProtectedAbbrevTitleCache()|| name.getNomenclaturalReference().isProtectedTitleCache() )){ |
|
513 |
logger.warn("Blocking name for synonym relation could not be parsed: " + nameStr + ", RelId: "+ relId); |
|
514 |
} |
|
515 |
if (status != null){ |
|
516 |
name.addStatus(NomenclaturalStatus.NewInstance(status)); |
|
517 |
} |
|
518 |
synonym.getName().addRelationshipFromName(name, NameRelationshipType.BLOCKING_NAME_FOR(), null, null, null); |
|
519 |
|
|
520 |
getNameService().saveOrUpdate(name); |
|
521 |
} |
|
522 |
return null; |
|
523 |
}else{ |
|
524 |
return notes; |
|
525 |
} |
|
526 |
}else{ |
|
527 |
return notes; |
|
528 |
} |
|
529 |
} |
|
530 |
|
|
531 |
private void handleAllRelatedTaxa(BerlinModelImportState state, Taxon taxon, |
|
532 |
Map<Integer, Classification> classificationMap, Integer secRefFk) { |
|
400 | 533 |
if (taxon.getTaxonNodes().size() > 0){ |
401 | 534 |
return; |
402 | 535 |
}else{ |
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/validation/BerlinModelCommonNamesImportValidator.java | ||
---|---|---|
164 | 164 |
boolean result = true; |
165 | 165 |
Source source = config.getSource(); |
166 | 166 |
String strQueryArticlesWithoutJournal = "SELECT Count(*) as n " + |
167 |
" FROM emCommonName " + |
|
168 |
" WHERE (emCommonName.LanguageRefFk NOT IN " +
|
|
167 |
" FROM emCommonName cn INNER JOIN PTaxon pt ON pt.PTNameFk = cn.PTNameFk AND pt.PTRefFk = cn.PTRefFk " +
|
|
168 |
" WHERE (cn.LanguageRefFk NOT IN " +
|
|
169 | 169 |
"(SELECT ReferenceId FROM emLanguageReference)) AND " + |
170 |
"(emCommonName.LanguageRefFk is NOT NULL)"; |
|
170 |
"(cn.LanguageRefFk is NOT NULL) AND " |
|
171 |
+ " cn.LanguageRefFk <> cn.RefFk " |
|
172 |
+ " AND pt.statusFk NOT IN (6) "; |
|
171 | 173 |
ResultSet rs = source.getResultSet(strQueryArticlesWithoutJournal); |
172 | 174 |
rs.next(); |
173 | 175 |
int count = rs.getInt("n"); |
174 | 176 |
if (count > 0){ |
175 |
System.out.println("========================================================"); |
|
176 |
System.out.println("There are " + count + " common names that have a languageRefFk which can not be found in the emLanguageReference table."); |
|
177 |
System.out.println("========================================================"); |
|
177 |
System.out.println("============================================================================");
|
|
178 |
System.out.println("There are " + count + " common names that have a languageRefFk which can not be found in the emLanguageReference table AND are not equal to RefFk.");
|
|
179 |
System.out.println("============================================================================");
|
|
178 | 180 |
} |
179 | 181 |
if (count > 0){ |
180 | 182 |
System.out.println(" "); |
app-import/src/main/java/eu/etaxonomy/cdm/io/greece/GreeceWillingImport.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 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 |
package eu.etaxonomy.cdm.io.greece; |
|
10 |
|
|
11 |
import java.net.MalformedURLException; |
|
12 |
import java.net.URI; |
|
13 |
import java.text.ParseException; |
|
14 |
import java.util.List; |
|
15 |
import java.util.Map; |
|
16 |
import java.util.UUID; |
|
17 |
|
|
18 |
import org.apache.log4j.Logger; |
|
19 |
|
|
20 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; |
|
21 |
import eu.etaxonomy.cdm.api.service.config.MatchingTaxonConfigurator; |
|
22 |
import eu.etaxonomy.cdm.io.common.utils.ImportDeduplicationHelper; |
|
23 |
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImport; |
|
24 |
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState; |
|
25 |
import eu.etaxonomy.cdm.model.agent.Team; |
|
26 |
import eu.etaxonomy.cdm.model.common.Language; |
|
27 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
|
28 |
import eu.etaxonomy.cdm.model.description.IndividualsAssociation; |
|
29 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
30 |
import eu.etaxonomy.cdm.model.location.Country; |
|
31 |
import eu.etaxonomy.cdm.model.media.Media; |
|
32 |
import eu.etaxonomy.cdm.model.occurrence.Collection; |
|
33 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
34 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
35 |
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser; |
|
36 |
|
|
37 |
/** |
|
38 |
* @author a.mueller |
|
39 |
* @since 21.08.2018 |
|
40 |
* |
|
41 |
*/ |
|
42 |
public class GreeceWillingImport |
|
43 |
extends SimpleExcelTaxonImport<GreeceWillingImportConfigurator>{ |
|
44 |
|
|
45 |
private static final long serialVersionUID = 8258914747643501550L; |
|
46 |
|
|
47 |
private static final Logger logger = Logger.getLogger(GreeceWillingImport.class); |
|
48 |
|
|
49 |
private ImportDeduplicationHelper<SimpleExcelTaxonImportState> dedupHelper; |
|
50 |
|
|
51 |
|
|
52 |
/** |
|
53 |
* {@inheritDoc} |
|
54 |
*/ |
|
55 |
@Override |
|
56 |
protected void firstPass(SimpleExcelTaxonImportState<GreeceWillingImportConfigurator> state) { |
|
57 |
try { |
|
58 |
Map<String, String> record = state.getOriginalRecord(); |
|
59 |
String scientificName = record.get("ScientificName"); |
|
60 |
String stableIdentifier = record.get("ObjectURI"); |
|
61 |
String title = record.get("Title"); |
|
62 |
String titleDescription = record.get("TitleDescription"); |
|
63 |
|
|
64 |
String collector = record.get("Collector"); |
|
65 |
String collectorNumber = record.get("CollectorNumber"); |
|
66 |
|
|
67 |
String collectionDate = record.get("CollectionDate"); |
|
68 |
// String CollDateISO = record.get("CollDateISO"); |
|
69 |
String catalogNumber = record.get("CatalogNumber"); |
|
70 |
String locality = record.get("Locality"); |
|
71 |
String image = record.get("Image"); |
|
72 |
|
|
73 |
String latitude = record.get("Latitude"); |
|
74 |
String longitude = record.get("Longitude"); |
|
75 |
|
|
76 |
String rdfId = record.get("rdfID"); |
|
77 |
|
|
78 |
TimePeriod date = TimePeriodParser.parseEnglishDate(collectionDate, null); |
|
79 |
|
|
80 |
validate(state, "BaseOfRecords", "Specimen"); |
|
81 |
validate(state, "InstitutionCode", "BGBM"); |
|
82 |
validate(state, "CollectionCode", "B"); |
|
83 |
validate(state, "HigherGeography", "Greece"); |
|
84 |
validate(state, "Country", "Greece"); |
|
85 |
validate(state, "CountryCode", "GR"); |
|
86 |
|
|
87 |
|
|
88 |
// HerbariumID |
|
89 |
// CollDateISO |
|
90 |
|
|
91 |
|
|
92 |
Taxon taxon = getTaxonByName(state, scientificName); |
|
93 |
DerivedUnitFacade facade = DerivedUnitFacade.NewPreservedSpecimenInstance(); |
|
94 |
|
|
95 |
facade.setPreferredStableUri(URI.create(stableIdentifier)); |
|
96 |
facade.setFieldNumber(collectorNumber); |
|
97 |
facade.setBarcode(catalogNumber); |
|
98 |
facade.setCountry(Country.GREECEHELLENICREPUBLIC()); |
|
99 |
|
|
100 |
facade.setLocality(locality); |
|
101 |
try { |
|
102 |
facade.setExactLocationByParsing(longitude, latitude, null, null); |
|
103 |
} catch (ParseException e) { |
|
104 |
e.printStackTrace(); |
|
105 |
} |
|
106 |
facade.setCollector(getCollector(state, collector)); |
|
107 |
facade.getGatheringEvent(true).setTimeperiod(date); |
|
108 |
|
|
109 |
facade.setCollection(getCollection(state)); |
|
110 |
|
|
111 |
Media media = getMedia(state,title, titleDescription, image); |
|
112 |
facade.addFieldObjectMedia(media); |
|
113 |
|
|
114 |
Reference sourceReference = state.getSourceReference(); |
|
115 |
String sourceId = rdfId; |
|
116 |
String namespace = "rdfID"; |
|
117 |
this.addOriginalSource(facade.innerFieldUnit(), sourceId, namespace, sourceReference); |
|
118 |
this.addOriginalSource(facade.innerDerivedUnit(), sourceId, namespace, sourceReference); |
|
119 |
this.addOriginalSource(media, sourceId, namespace, sourceReference); |
|
120 |
|
|
121 |
TaxonDescription description = getTaxonDescription(taxon, sourceReference, false, CREATE); |
|
122 |
IndividualsAssociation specimen = IndividualsAssociation.NewInstance(facade.innerDerivedUnit()); |
|
123 |
description.addElement(specimen); |
|
124 |
|
|
125 |
// getDedupHelper(state).replaceAuthorNamesAndNomRef(state, name); |
|
126 |
|
|
127 |
} catch (MalformedURLException e) { |
|
128 |
logger.warn("An error occurred during import"); |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
} |
|
135 |
|
|
136 |
private Collection bgbm; |
|
137 |
/** |
|
138 |
* @param state |
|
139 |
* @return |
|
140 |
*/ |
|
141 |
private Collection getCollection(SimpleExcelTaxonImportState<GreeceWillingImportConfigurator> state) { |
|
142 |
if (bgbm == null){ |
|
143 |
List<Collection> results = getCollectionService().searchByCode("B"); |
|
144 |
if (results.size()> 1){ |
|
145 |
throw new RuntimeException("More then 1 collection found for 'B'"); |
|
146 |
}else if (results.isEmpty()){ |
|
147 |
throw new RuntimeException("No collection found for 'B'"); |
|
148 |
} |
|
149 |
bgbm = results.get(0); |
|
150 |
} |
|
151 |
return bgbm; |
|
152 |
} |
|
153 |
|
|
154 |
/** |
|
155 |
* @param state |
|
156 |
* @param string |
|
157 |
* @param string2 |
|
158 |
*/ |
|
159 |
private void validate(SimpleExcelTaxonImportState<GreeceWillingImportConfigurator> state, String attr, |
|
160 |
String expectedValue) { |
|
161 |
Map<String, String> record = state.getOriginalRecord(); |
|
162 |
String attrValue = record.get(attr); |
|
163 |
if (!expectedValue.equalsIgnoreCase(attrValue)){ |
|
164 |
throw new RuntimeException("Attribute " + attr + " has not expected value " + expectedValue + " but "+ attrValue); |
|
165 |
} |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* @param state |
|
170 |
* @param title |
|
171 |
* @param titleDescription |
|
172 |
* @param image |
|
173 |
* @return |
|
174 |
* @throws MalformedURLException |
|
175 |
*/ |
|
176 |
private Media getMedia(SimpleExcelTaxonImportState<GreeceWillingImportConfigurator> state, String title, |
|
177 |
String titleDescription, String image) throws MalformedURLException { |
|
178 |
|
|
179 |
//TODO |
|
180 |
String thumbnail = image; |
|
181 |
Media media = getImageMedia(image, thumbnail, true); |
|
182 |
|
|
183 |
if (isNotBlank(title)){ |
|
184 |
media.putTitle(Language.ENGLISH(), title); |
|
185 |
} |
|
186 |
if (isNotBlank(titleDescription)){ |
|
187 |
media.putDescription(Language.ENGLISH(), titleDescription); |
|
188 |
} |
|
189 |
|
|
190 |
|
|
191 |
//TODO thumbnails etc. |
|
192 |
|
|
193 |
// ImageInfo info = ImageInfo.NewInstanceWithMetaData(URI.create(image), 60); |
|
194 |
// Media media = Media.NewInstance(uri, info.getLength(), info.getMimeType(), info.getSuffix()); |
|
195 |
return media; |
|
196 |
} |
|
197 |
|
|
198 |
|
|
199 |
Team willingCollector; |
|
200 |
/** |
|
201 |
* @param state |
|
202 |
* @param collector |
|
203 |
* @return |
|
204 |
*/ |
|
205 |
private Team getCollector(SimpleExcelTaxonImportState<GreeceWillingImportConfigurator> state, |
|
206 |
String collector) { |
|
207 |
if (!"Willing,R. & Willing,E.".equals(collector)){ |
|
208 |
throw new RuntimeException("Unexpected collector: " + collector); |
|
209 |
} |
|
210 |
if (willingCollector == null){ |
|
211 |
UUID willingTeamUuid = UUID.fromString("ab3594a5-304f-4f19-bc8b-4a38c8abfad7"); |
|
212 |
willingCollector = (Team)getAgentService().find(willingTeamUuid); |
|
213 |
} |
|
214 |
return willingCollector; |
|
215 |
} |
|
216 |
|
|
217 |
/** |
|
218 |
* @param state |
|
219 |
* @param scientificName |
|
220 |
* @return |
|
221 |
*/ |
|
222 |
private Taxon getTaxonByName(SimpleExcelTaxonImportState<GreeceWillingImportConfigurator> state, |
|
223 |
String scientificName) { |
|
224 |
MatchingTaxonConfigurator config = MatchingTaxonConfigurator.NewInstance(); |
|
225 |
config.setTaxonNameTitle(scientificName); |
|
226 |
config.setIncludeSynonyms(false); |
|
227 |
Taxon result = getTaxonService().findBestMatchingTaxon(config); |
|
228 |
return result; |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* @param state |
|
233 |
* @return |
|
234 |
*/ |
|
235 |
private ImportDeduplicationHelper<SimpleExcelTaxonImportState> getDedupHelper(SimpleExcelTaxonImportState<GreeceWillingImportConfigurator> state) { |
|
236 |
if (this.dedupHelper == null){ |
|
237 |
dedupHelper = ImportDeduplicationHelper.NewInstance(this, state); |
|
238 |
} |
|
239 |
return this.dedupHelper; |
|
240 |
} |
|
241 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/greece/GreeceWillingImportConfigurator.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 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 |
package eu.etaxonomy.cdm.io.greece; |
|
10 |
|
|
11 |
import java.net.URI; |
|
12 |
|
|
13 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
14 |
import eu.etaxonomy.cdm.io.common.ImportStateBase; |
|
15 |
import eu.etaxonomy.cdm.io.excel.common.ExcelImportConfiguratorBase; |
|
16 |
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState; |
|
17 |
|
|
18 |
/** |
|
19 |
* @author a.mueller |
|
20 |
* @since 21.08.2018 |
|
21 |
* |
|
22 |
*/ |
|
23 |
public class GreeceWillingImportConfigurator |
|
24 |
extends ExcelImportConfiguratorBase{ |
|
25 |
|
|
26 |
private static final long serialVersionUID = 5599561699561750055L; |
|
27 |
|
|
28 |
public static GreeceWillingImportConfigurator NewInstance(URI source, ICdmDataSource destination) { |
|
29 |
return new GreeceWillingImportConfigurator(source, destination); |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* @param uri |
|
34 |
* @param destination |
|
35 |
*/ |
|
36 |
protected GreeceWillingImportConfigurator(URI uri, ICdmDataSource destination) { |
|
37 |
super(uri, destination); |
|
38 |
} |
|
39 |
|
|
40 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
|
41 |
@Override |
|
42 |
public ImportStateBase getNewState() { |
|
43 |
return new SimpleExcelTaxonImportState<>(this); |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* {@inheritDoc} |
|
48 |
*/ |
|
49 |
@SuppressWarnings("unchecked") |
|
50 |
@Override |
|
51 |
protected void makeIoClassList() { |
|
52 |
ioClassList = new Class[]{ |
|
53 |
GreeceWillingImport.class, |
|
54 |
}; |
|
55 |
} |
|
56 |
|
|
57 |
} |
Also available in: Unified diff
ref #3986 remove It(I) and IT(S) from imported areas